import { err, ok, type ReadonlyDB } from "@tailor-platform/erp-kit/core"; import type { DB } from "../generated/kysely-tailordb"; import { ShiftPlacementNotFoundError } from "../lib/errors.generated"; export interface GetShiftPlacementInput { shiftPlacementId: string; } /** * Function: getShiftPlacement * Description: Retrieves a single placement (ShiftPlacement) by id — the * lookup behind shift-schedule-detail views and variance calculation, which need to * resolve exactly which Assignment is staffing a slot. Returns the placement * regardless of the parent Shift's current status. */ export async function run(db: ReadonlyDB, input: GetShiftPlacementInput) { const shiftPlacement = await db .selectFrom("ShiftPlacement") .selectAll() .where("id", "=", input.shiftPlacementId) .executeTakeFirst(); if (!shiftPlacement) { return err(new ShiftPlacementNotFoundError(input.shiftPlacementId)); } return ok({ shiftPlacement }); }