metis-desk/modules/companies/src/api/application/telework-authorization-response.builder.ts
David 2382e0ea20 feat: add telework authorization management functionality
- Implemented RESTful API routes for telework authorizations, including GET and POST methods for retrieving and saving authorizations.
- Created Sequelize repository for managing telework authorization data with methods for loading and saving authorizations.
- Developed migration scripts to set up necessary database tables for telework authorizations and revisions.
- Added persistence mapping for telework authorization entities to facilitate data transformation between domain and database layers.
- Introduced common schemas for validating telework authorization requests and responses using Zod.
- Built frontend components for managing telework authorizations, including forms for creating and editing authorizations, and summaries for displaying authorization details.
- Integrated internationalization support for English and Spanish languages in the telework module.
- Added unit tests to ensure functionality and correctness of telework authorization components and API interactions.
2026-10-06 18:10:35 +02:00

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,
})),
};
}