Files
100kmph_web/web/lib/workshop.ts
T
2026-09-28 23:15:47 +05:30

48 lines
1.2 KiB
TypeScript

export const NO_BIKE = "No bike found for this number.";
export const NOT_IN_WORKSHOP = "This bike is not in the workshop.";
export const STAGE_LABELS: Record<string, string> = {
received: "Received",
diagnostic: "Diagnostic",
in_repair: "In Repair",
quality_check: "Quality Check",
ready: "Ready",
billed: "Billed",
};
export function stageLabel(stage: string): string {
return STAGE_LABELS[stage] ?? stage;
}
export type JobPick = {
id: string;
stage: string;
createdAt: string;
};
/** Newest non-deleted job that is not billed. Caller already dropped deleted rows. */
export function pickWorkshopJob(jobs: JobPick[]): JobPick | null {
const open = jobs.filter((job) => job.stage !== "billed");
open.sort((a, b) => {
const byTime = b.createdAt.localeCompare(a.createdAt);
if (byTime !== 0) return byTime;
return b.id.localeCompare(a.id);
});
return open[0] ?? null;
}
export type BikeStatus = {
registration: string;
make: string;
model: string;
inWorkshop: boolean;
stageLabel: string | null;
stageAt: string | null;
};
export type StatusResult = {
message: string | null;
error: string | null;
bikes: BikeStatus[];
};