71 lines
2.2 KiB
TypeScript
71 lines
2.2 KiB
TypeScript
import type { ProcessReferenceInput } from "../domain/process-values";
|
|
|
|
export type ProcessReviewSources = {
|
|
assets: readonly { id: string; name: string; personId: string | null; available: boolean }[];
|
|
profiles: readonly { id: string; personId: string; name: string; active: boolean }[];
|
|
configurations: readonly {
|
|
id: string;
|
|
personId: string;
|
|
kind: ProcessReferenceInput["kind"];
|
|
label: string;
|
|
state: string;
|
|
sourceKind?: ProcessReferenceInput["sourceKind"];
|
|
}[];
|
|
relationships: readonly {
|
|
id: string;
|
|
personId: string;
|
|
kind: ProcessReferenceInput["kind"];
|
|
label: string;
|
|
endDate: string | null;
|
|
configuration: string | null;
|
|
}[];
|
|
authorizations: readonly { id: string; personId: string; active: boolean }[];
|
|
};
|
|
|
|
export function buildProcessReview(
|
|
personId: string,
|
|
sources: ProcessReviewSources,
|
|
today: string
|
|
): ProcessReferenceInput[] {
|
|
const closed = (state: string | null) => state === "removed" || state === "never_configured";
|
|
|
|
const result: ProcessReferenceInput[] = sources.assets
|
|
.filter((a) => a.personId === personId && a.available)
|
|
.map((a) => ({ kind: "asset", id: a.id, label: a.name }));
|
|
|
|
for (const p of sources.profiles) {
|
|
if (p.personId === personId && p.active) {
|
|
result.push({ kind: "profile", id: p.id, label: p.name });
|
|
}
|
|
}
|
|
for (const c of sources.configurations) {
|
|
if (c.personId === personId && !closed(c.state)) {
|
|
result.push({
|
|
kind: c.kind,
|
|
id: c.id,
|
|
label: c.label,
|
|
...(c.sourceKind ? { sourceKind: c.sourceKind } : {}),
|
|
});
|
|
}
|
|
}
|
|
const relevantRelationships = sources.relationships
|
|
.filter((r) => r.personId === personId)
|
|
.filter(
|
|
(r) =>
|
|
!r.endDate || r.endDate >= today || Boolean(r.configuration && !closed(r.configuration))
|
|
);
|
|
|
|
result.push(...relevantRelationships.map((r) => ({ kind: r.kind, id: r.id, label: r.label })));
|
|
for (const a of sources.authorizations) {
|
|
if (a.personId === personId && a.active) {
|
|
result.push({ kind: "telework", id: a.id, label: personId });
|
|
}
|
|
}
|
|
|
|
return [
|
|
...new Map(
|
|
result.map((ref) => [`${ref.kind}:${ref.id}`, { ...ref, label: ref.label.slice(0, 500) }])
|
|
).values(),
|
|
];
|
|
}
|