import { err, ok, type ReadonlyDB } from "@tailor-platform/erp-kit/core"; import type { DB } from "../generated/kysely-tailordb"; import { CalculatedBlockNotFoundError } from "../lib/errors.generated"; export interface GetCalculatedBlockInput { id: string; } /** * Function: getCalculatedBlock * Description: Retrieves a single CalculatedTimeBlock by its id. Used when a * caller already has a specific calculated block id — for example when * following sourceReportedBlockIds/calculationTagKeys traceability links back * from a payroll or Article-36 agreement read, or when drilling into one block from a list * result. */ export async function run(db: ReadonlyDB, input: GetCalculatedBlockInput) { const calculatedTimeBlock = await db .selectFrom("CalculatedTimeBlock") .selectAll() .where("id", "=", input.id) .executeTakeFirst(); if (!calculatedTimeBlock) { return err(new CalculatedBlockNotFoundError(input.id)); } return ok({ calculatedTimeBlock }); }