2026-10-05 11:13:51 +00:00
|
|
|
import type { ResourceDTO } from "../../common/inventory";
|
|
|
|
|
import type { Resource } from "../domain/resource.aggregate";
|
2026-10-10 10:01:58 +00:00
|
|
|
|
2026-10-05 11:13:51 +00:00
|
|
|
export function buildResourceResponse(
|
|
|
|
|
resource: Resource,
|
|
|
|
|
actors: ReadonlyMap<string, string>
|
|
|
|
|
): ResourceDTO {
|
|
|
|
|
return {
|
|
|
|
|
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(),
|
2026-10-19 09:45:09 +00:00
|
|
|
...(revision.specification.equals(resource.specification)
|
|
|
|
|
? {}
|
|
|
|
|
: { specification: revision.specification.toPrimitive() }),
|
2026-10-05 11:13:51 +00:00
|
|
|
actorId: revision.actorId.toPrimitive(),
|
|
|
|
|
actorName: actors.get(revision.actorId.toPrimitive()) ?? revision.actorId.toPrimitive(),
|
|
|
|
|
recordedAt: revision.recordedAt,
|
|
|
|
|
})),
|
|
|
|
|
};
|
|
|
|
|
}
|