- Added `useAssetPickerController` for managing asset selection logic. - Created `AssetSelectProps` type for defining asset selection properties. - Implemented `AssetPickerDialog` for displaying the asset selection interface. - Developed `AssetPickerList` for rendering the list of selectable assets. - Introduced `AssetSelect` component for integrating the asset picker into forms. - Created `AssetList` component for shared asset listing functionality. - Added tests for workstation creation logic to ensure proper validation. - Implemented workstation asset fields and association fields for managing workstation assets. - Developed workstation lifecycle dialog for managing work profile states. - Added form progress component for visualizing multi-step forms.
54 lines
1.7 KiB
TypeScript
54 lines
1.7 KiB
TypeScript
import type { UniqueID } from "@repo/rdx-ddd";
|
|
import type { Transaction } from "sequelize";
|
|
|
|
import type { Asset } from "../../domain/asset.aggregate";
|
|
|
|
import { WorkstationAssetModel } from "./workstation.model";
|
|
import { WorkstationPersistenceMapper } from "./workstation-persistence.mapper";
|
|
import { readWorkstations } from "./workstation-relational";
|
|
|
|
export async function loadWorkstations(
|
|
companyId: UniqueID,
|
|
transaction: Transaction,
|
|
assets: readonly Asset[],
|
|
sites: readonly { id: string }[],
|
|
people: readonly { id: string }[]
|
|
) {
|
|
const database = WorkstationAssetModel.sequelize;
|
|
|
|
if (!database) {
|
|
throw new Error("Persistencia de puestos sin inicializar.");
|
|
}
|
|
const { rows, revisions } = await readWorkstations(
|
|
database,
|
|
companyId.toPrimitive(),
|
|
transaction
|
|
);
|
|
const references = await WorkstationAssetModel.findAll({
|
|
where: { companyId: companyId.toPrimitive() },
|
|
transaction,
|
|
});
|
|
|
|
return rows.map((row) => {
|
|
const item = new WorkstationPersistenceMapper().toDomain(
|
|
row,
|
|
revisions.filter((revision) => revision.workstationId === row.id),
|
|
references.filter((reference) => reference.workstationId === row.id)
|
|
);
|
|
|
|
for (const revision of item.history) {
|
|
const values = revision.values.toPrimitive();
|
|
|
|
if (
|
|
(values.siteId && !sites.some((site) => site.id === values.siteId)) ||
|
|
(values.personId && !people.some((person) => person.id === values.personId)) ||
|
|
values.assetIds.some((id) => !assets.some((asset) => asset.id.toPrimitive() === id))
|
|
) {
|
|
throw new Error("Puesto de trabajo fuera de su compañía.");
|
|
}
|
|
}
|
|
|
|
return item;
|
|
});
|
|
}
|