21 lines
762 B
TypeScript
21 lines
762 B
TypeScript
|
|
import type { ResourceDTO } from "../../common/inventory";
|
||
|
|
import type { Resource } from "../domain/resource.aggregate";
|
||
|
|
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(),
|
||
|
|
actorId: revision.actorId.toPrimitive(),
|
||
|
|
actorName: actors.get(revision.actorId.toPrimitive()) ?? revision.actorId.toPrimitive(),
|
||
|
|
recordedAt: revision.recordedAt,
|
||
|
|
})),
|
||
|
|
};
|
||
|
|
}
|