29 lines
1.1 KiB
TypeScript
29 lines
1.1 KiB
TypeScript
|
|
import type { TeleworkAuthorizationDTO } from "../../common/telework-authorizations";
|
||
|
|
import type { TeleworkAuthorization } from "../domain/telework-authorization.aggregate";
|
||
|
|
|
||
|
|
import type { TeleworkAuthorizationContext } from "./telework-authorization.repository";
|
||
|
|
import { teleworkAuthorizationState } from "./telework-authorization-policy";
|
||
|
|
|
||
|
|
export function buildTeleworkAuthorizationResponse(
|
||
|
|
item: TeleworkAuthorization,
|
||
|
|
context: TeleworkAuthorizationContext
|
||
|
|
): TeleworkAuthorizationDTO {
|
||
|
|
const { status, effective, needsReview } = teleworkAuthorizationState(item, context);
|
||
|
|
return {
|
||
|
|
id: item.id.toPrimitive(),
|
||
|
|
companyId: item.companyId.toPrimitive(),
|
||
|
|
values: item.values.toPrimitive(),
|
||
|
|
status,
|
||
|
|
effective,
|
||
|
|
needsReview,
|
||
|
|
history: item.history.map((revision) => ({
|
||
|
|
id: revision.id.toPrimitive(),
|
||
|
|
values: revision.values.toPrimitive(),
|
||
|
|
actorId: revision.actorId.toPrimitive(),
|
||
|
|
actorName:
|
||
|
|
context.actors.get(revision.actorId.toPrimitive()) ?? revision.actorId.toPrimitive(),
|
||
|
|
recordedAt: revision.recordedAt,
|
||
|
|
})),
|
||
|
|
};
|
||
|
|
}
|