59 lines
1.8 KiB
TypeScript
59 lines
1.8 KiB
TypeScript
import type { UniqueID } from "@repo/rdx-ddd";
|
|
import type { Result } from "@repo/rdx-utils";
|
|
|
|
import type { Ticket } from "../domain/ticket.aggregate";
|
|
import type { TicketError, TicketTargetInput } from "../domain/ticket-values";
|
|
|
|
export type TicketOption = Readonly<{ id: UniqueID; name: string; active: boolean }>;
|
|
|
|
export type TicketContext = Readonly<{
|
|
tickets: readonly Ticket[];
|
|
companies: readonly TicketOption[];
|
|
technicians: readonly TicketOption[];
|
|
people: readonly (TicketOption & { companyId: UniqueID })[];
|
|
actorNames: ReadonlyMap<string, string>;
|
|
}>;
|
|
|
|
export type TicketLookups = Readonly<{
|
|
people: readonly TicketOption[];
|
|
assets: readonly TicketOption[];
|
|
resources: readonly TicketOption[];
|
|
workstations: readonly TicketOption[];
|
|
}>;
|
|
|
|
export type TicketSaveContext = TicketContext & {
|
|
lookups: TicketLookups;
|
|
nextNumber: number;
|
|
requestTicket: Ticket | undefined;
|
|
};
|
|
|
|
export interface ITicketInventoryService {
|
|
list(company: UniqueID): Promise<readonly { id: UniqueID; name: string; available: boolean }[]>;
|
|
workstations(
|
|
company: UniqueID
|
|
): Promise<readonly { id: UniqueID; name: string; active: boolean }[]>;
|
|
}
|
|
|
|
export interface ITicketRepository {
|
|
list(company?: UniqueID): Promise<Result<TicketContext, TicketError>>;
|
|
lookups(company: UniqueID): Promise<Result<TicketLookups, TicketError>>;
|
|
save(
|
|
company: UniqueID,
|
|
requestKey: UniqueID,
|
|
action: (context: TicketSaveContext) => Result<Ticket, TicketError>
|
|
): Promise<Result<{ ticket: Ticket; context: TicketContext }, TicketError>>;
|
|
}
|
|
|
|
export function targetOptions(lookups: TicketLookups, kind: TicketTargetInput["kind"]) {
|
|
switch (kind) {
|
|
case "person":
|
|
return lookups.people;
|
|
case "asset":
|
|
return lookups.assets;
|
|
case "resource":
|
|
return lookups.resources;
|
|
case "workstation":
|
|
return lookups.workstations;
|
|
}
|
|
}
|