metis-desk/modules/resources/src/api/application/resource-response.builder.ts
David fe6ec361b7 feat(companies): vincular identidades locales a activos y añadir cuenta de acceso a FolderMapping
- Asociar entornos locales con activos y conservar su trazabilidad.
- Registrar la cuenta de acceso del mapeo con historial de cambios.
- Calcular cobertura documental específica sin alterar la cobertura general.
- Añadir migraciones, validaciones, endpoints protegidos, pruebas y documentación.
2026-10-21 11:25:23 +02:00

31 lines
1.2 KiB
TypeScript

import type { DirectoryDomainDTO } from "../../common/directory-domains";
import type { ResourceDTO } from "../../common/inventory";
import type { NetworkShareDTO } from "../../common/network-shares";
import type { Resource } from "../domain/resource.aggregate";
export function buildResourceResponse(
resource: Resource,
actors: ReadonlyMap<string, string>,
directory?: DirectoryDomainDTO,
networkShare?: NetworkShareDTO
): ResourceDTO {
return {
...(directory ? { directory } : {}),
...(networkShare ? { networkShare } : {}),
id: resource.id.toPrimitive(),
companyId: resource.companyId.toPrimitive(),
specification: resource.specification.toPrimitive(),
values: resource.values.toPrimitive(),
history: resource.history.map((revision) => ({
id: revision.id.toPrimitive(),
values: revision.values.toPrimitive(),
...(revision.specification.equals(resource.specification)
? {}
: { specification: revision.specification.toPrimitive() }),
actorId: revision.actorId.toPrimitive(),
actorName: actors.get(revision.actorId.toPrimitive()) ?? revision.actorId.toPrimitive(),
recordedAt: revision.recordedAt,
})),
};
}