28 lines
1.0 KiB
TypeScript
28 lines
1.0 KiB
TypeScript
|
|
import type { SoftwareInstallationDTO } from "../../common/software-installations";
|
||
|
|
import type { SoftwareInstallation } from "../domain/software-installation.aggregate";
|
||
|
|
|
||
|
|
import type { SoftwareContext } from "./software-installation.repository";
|
||
|
|
import { softwareAvailable } from "./software-installation-policy";
|
||
|
|
|
||
|
|
export function buildSoftwareResponse(
|
||
|
|
item: SoftwareInstallation,
|
||
|
|
context: SoftwareContext
|
||
|
|
): SoftwareInstallationDTO {
|
||
|
|
return {
|
||
|
|
id: item.id.toPrimitive(),
|
||
|
|
companyId: item.companyId.toPrimitive(),
|
||
|
|
values: item.values.toPrimitive(),
|
||
|
|
needsReview:
|
||
|
|
!item.values.closed &&
|
||
|
|
(!softwareAvailable(item.values, context) || item.values.state === "removal_pending"),
|
||
|
|
history: item.history.map((revision) => ({
|
||
|
|
id: revision.id.toPrimitive(),
|
||
|
|
actorId: revision.actorId.toPrimitive(),
|
||
|
|
actorName:
|
||
|
|
context.actors.get(revision.actorId.toPrimitive()) ?? revision.actorId.toPrimitive(),
|
||
|
|
recordedAt: revision.recordedAt,
|
||
|
|
values: revision.values.toPrimitive(),
|
||
|
|
})),
|
||
|
|
};
|
||
|
|
}
|