98 lines
3.1 KiB
TypeScript
98 lines
3.1 KiB
TypeScript
import type { VMState } from "../index.js";
|
|
|
|
/**
|
|
* HR sick-leave view-models (AK-P17b). Pure functions. The AU certificate is
|
|
* sensitive: the VM NEVER carries the certificate File id or ciphertext — only a
|
|
* `hasCertificate` flag and a `revealHref` (a permission-checked + audited POST
|
|
* action decrypts it on demand). No React, no Prisma, no app imports.
|
|
*/
|
|
|
|
export type HrSickLeaveStatus = "reported" | "closed" | "cancelled";
|
|
|
|
export interface HrSickLeaveRow {
|
|
readonly id: string;
|
|
readonly status: HrSickLeaveStatus;
|
|
readonly statusLabelKey: string;
|
|
readonly startDateIso: string;
|
|
readonly expectedReturnDateIso: string | null;
|
|
readonly returnDateIso: string | null;
|
|
readonly note: string | null;
|
|
/** True when an (encrypted) certificate is attached; never the id itself. */
|
|
readonly hasCertificate: boolean;
|
|
/** POST action that decrypts + opens the certificate (gated + audited). */
|
|
readonly revealHref: string;
|
|
readonly canClose: boolean;
|
|
readonly canCancel: boolean;
|
|
}
|
|
|
|
export interface HrSickLeaveOwnData {
|
|
readonly rows: readonly HrSickLeaveRow[];
|
|
readonly canReport: boolean;
|
|
readonly emptyHeadlineKey: string;
|
|
readonly emptyBodyKey: string;
|
|
}
|
|
|
|
export type HrSickLeaveOwnVM = VMState<HrSickLeaveOwnData>;
|
|
|
|
export interface HrSickLeaveOfficeRow extends HrSickLeaveRow {
|
|
readonly employeeLabel: string;
|
|
}
|
|
|
|
export interface HrSickLeaveOfficeData {
|
|
readonly rows: readonly HrSickLeaveOfficeRow[];
|
|
readonly emptyHeadlineKey: string;
|
|
readonly emptyBodyKey: string;
|
|
}
|
|
|
|
export type HrSickLeaveOfficeVM = VMState<HrSickLeaveOfficeData>;
|
|
|
|
export interface HrSickLeaveInputRow {
|
|
readonly id: string;
|
|
readonly status: HrSickLeaveStatus;
|
|
readonly startDateIso: string;
|
|
readonly expectedReturnDateIso: string | null;
|
|
readonly returnDateIso: string | null;
|
|
readonly note: string | null;
|
|
readonly hasCertificate: boolean;
|
|
readonly revealHref: string;
|
|
}
|
|
|
|
function toRow(row: HrSickLeaveInputRow): HrSickLeaveRow {
|
|
return {
|
|
id: row.id,
|
|
status: row.status,
|
|
statusLabelKey: `hr.sick.status.${row.status}`,
|
|
startDateIso: row.startDateIso,
|
|
expectedReturnDateIso: row.expectedReturnDateIso,
|
|
returnDateIso: row.returnDateIso,
|
|
note: row.note,
|
|
hasCertificate: row.hasCertificate,
|
|
revealHref: row.revealHref,
|
|
canClose: row.status === "reported",
|
|
canCancel: row.status !== "cancelled",
|
|
};
|
|
}
|
|
|
|
export function buildHrSickOwnVM(input: { rows: readonly HrSickLeaveInputRow[]; canReport: boolean }): HrSickLeaveOwnVM {
|
|
return {
|
|
status: "ready",
|
|
data: {
|
|
rows: input.rows.map(toRow),
|
|
canReport: input.canReport,
|
|
emptyHeadlineKey: "hr.sick.own.empty.headline",
|
|
emptyBodyKey: "hr.sick.own.empty.body",
|
|
},
|
|
};
|
|
}
|
|
|
|
export function buildHrSickOfficeVM(input: { rows: ReadonlyArray<HrSickLeaveInputRow & { employeeLabel: string }> }): HrSickLeaveOfficeVM {
|
|
return {
|
|
status: "ready",
|
|
data: {
|
|
rows: input.rows.map((row) => ({ ...toRow(row), employeeLabel: row.employeeLabel })),
|
|
emptyHeadlineKey: "hr.sick.office.empty.headline",
|
|
emptyBodyKey: "hr.sick.office.empty.body",
|
|
},
|
|
};
|
|
}
|