import { err, ok, type CommandContext } from "@tailor-platform/erp-kit/core"; import type { Transaction } from "../generated/kysely-tailordb"; import { HolidayNotFoundError } from "../lib/errors.generated"; export interface DeleteCompanyHolidayInput { id: string; } /** * Function: deleteCompanyHoliday * Description: Removes a holiday fact that was entered in error. Since * CompanyHoliday is a plain dated fact, deletion is a direct removal of * the record rather than closing an effective-dated generation. */ export async function run(db: Transaction, input: DeleteCompanyHolidayInput, _ctx: CommandContext) { const companyHoliday = await db .selectFrom("CompanyHoliday") .selectAll() .where("id", "=", input.id) .forUpdate() .executeTakeFirst(); if (!companyHoliday) { return err(new HolidayNotFoundError(input.id)); } await db.deleteFrom("CompanyHoliday").where("id", "=", input.id).execute(); return ok({}); }