Files
CapaKraken/packages/application/src/use-cases/allocation/list-assignment-bookings.ts
T
Hartmut cd78f72f33 chore: full technical rename planarchy → capakraken
Complete rename of all technical identifiers across the codebase:

Package names (11 packages):
- @planarchy/* → @capakraken/* in all package.json, tsconfig, imports

Import statements: 277 files, 548 occurrences replaced

Database & Docker:
- PostgreSQL user/db: planarchy → capakraken
- Docker volumes: planarchy_pgdata → capakraken_pgdata
- Connection strings updated in docker-compose, .env, CI

CI/CD:
- GitHub Actions workflow: all filter commands updated
- Test database credentials updated

Infrastructure:
- Redis channel: planarchy:sse → capakraken:sse
- Logger service name: planarchy-api → capakraken-api
- Anonymization seed updated
- Start/stop/restart scripts updated

Test data:
- Seed emails: @planarchy.dev → @capakraken.dev
- E2E test credentials: all 11 spec files updated
- Email defaults: @planarchy.app → @capakraken.app
- localStorage keys: planarchy_* → capakraken_*

Documentation: 30+ .md files updated

Verification:
- pnpm install: workspace resolution works
- TypeScript: only pre-existing TS2589 (no new errors)
- Engine: 310/310 tests pass
- Staffing: 37/37 tests pass

Co-Authored-By: claude-flow <ruv@ruv.net>
2026-03-27 13:18:09 +01:00

105 lines
2.9 KiB
TypeScript

import type { Prisma, PrismaClient } from "@capakraken/db";
type AssignmentBookingsDbClient = Pick<PrismaClient, "assignment">;
export interface ListAssignmentBookingsInput {
startDate?: Date | undefined;
endDate?: Date | undefined;
resourceIds?: string[] | undefined;
projectIds?: string[] | undefined;
excludeAssignmentIds?: string[] | undefined;
}
export interface AssignmentBookingWithFallback {
id: string;
projectId: string;
resourceId: string | null;
startDate: Date;
endDate: Date;
hoursPerDay: number;
dailyCostCents: number;
status: string;
project: {
id: string;
name: string;
shortCode: string;
status: string;
orderType: string;
clientId: string | null;
dynamicFields: Prisma.JsonValue | null;
};
resource: {
id: string;
displayName: string;
chapter: string | null;
} | null;
}
export async function listAssignmentBookings(
db: AssignmentBookingsDbClient,
input: ListAssignmentBookingsInput,
): Promise<AssignmentBookingWithFallback[]> {
const hasDateBounds = input.startDate !== undefined && input.endDate !== undefined;
if (!hasDateBounds && (input.startDate !== undefined || input.endDate !== undefined)) {
throw new Error("startDate and endDate must be provided together");
}
const excludeAssignmentIds = input.excludeAssignmentIds?.filter(Boolean) ?? [];
const assignmentWhere = {
status: { not: "CANCELLED" as const },
...(hasDateBounds
? {
startDate: { lte: input.endDate! },
endDate: { gte: input.startDate! },
}
: {}),
...(input.resourceIds?.length ? { resourceId: { in: input.resourceIds } } : {}),
...(input.projectIds?.length ? { projectId: { in: input.projectIds } } : {}),
...(excludeAssignmentIds.length ? { id: { notIn: excludeAssignmentIds } } : {}),
} satisfies Prisma.AssignmentWhereInput;
const assignmentSelect = {
id: true,
projectId: true,
resourceId: true,
startDate: true,
endDate: true,
hoursPerDay: true,
dailyCostCents: true,
status: true,
project: {
select: {
id: true,
name: true,
shortCode: true,
status: true,
orderType: true,
clientId: true,
dynamicFields: true,
},
},
resource: {
select: { id: true, displayName: true, chapter: true },
},
} satisfies Prisma.AssignmentSelect;
const assignments = await db.assignment.findMany({
where: assignmentWhere,
select: assignmentSelect,
});
return assignments.map((assignment) => ({
id: assignment.id,
projectId: assignment.projectId,
resourceId: assignment.resourceId,
startDate: assignment.startDate,
endDate: assignment.endDate,
hoursPerDay: assignment.hoursPerDay,
dailyCostCents: assignment.dailyCostCents,
status: assignment.status,
project: assignment.project,
resource: assignment.resource,
}));
}