import { err, ok, type ReadonlyDB } from "@tailor-platform/erp-kit/core"; import type { DB } from "../generated/kysely-tailordb"; import { LeaveGrantNotFoundError } from "../lib/errors.generated"; export interface GetLeaveGrantInput { id: string; } /** * Function: getLeaveGrant * Retrieves a single LeaveGrant ledger record by id, regardless of whether * it is expired, partially consumed, or untouched. Returns the raw ledger * fields as stored; use getLeaveBalance for an aggregated balance. */ export async function run(db: ReadonlyDB, input: GetLeaveGrantInput) { const grant = await db .selectFrom("LeaveGrant") .selectAll() .where("id", "=", input.id) .executeTakeFirst(); if (!grant) { return err(new LeaveGrantNotFoundError(input.id)); } return ok({ grant }); }