- Implemented CatalogTemplateForm for creating and managing asset templates. - Added inventory management components including AssetInventoryPage and related forms. - Introduced internationalization support for asset and inventory components in English and Spanish. - Created tests for catalog and inventory functionalities to ensure proper rendering and behavior. - Established API interactions for inventory management and asset catalog retrieval. - Enhanced user experience with form dialogs for quick creation of sites and persons within company inventory.
56 lines
1.9 KiB
TypeScript
56 lines
1.9 KiB
TypeScript
import { UniqueID } from "@repo/rdx-ddd";
|
|
import { Maybe, Result } from "@repo/rdx-utils";
|
|
|
|
import type { AssetDefinitionSpec } from "../../common";
|
|
import { AssetCatalogError } from "../domain/asset-definition";
|
|
import { AssetDefinitionValues } from "../domain/value-objects/asset-definition-values";
|
|
|
|
import type { IAssetCatalogRepository } from "./asset-catalog.repository";
|
|
|
|
export function catalogScope(value: string) {
|
|
if (value === "global") {
|
|
return Result.ok(Maybe.none<UniqueID>());
|
|
}
|
|
const id = UniqueID.create(value);
|
|
return id.isSuccess
|
|
? Result.ok(Maybe.some(id.data))
|
|
: Result.fail(new AssetCatalogError("INVALID_REQUEST"));
|
|
}
|
|
export class AssetCatalogUseCases {
|
|
constructor(private readonly repository: IAssetCatalogRepository) {}
|
|
async get(scope: string) {
|
|
const parsed = catalogScope(scope);
|
|
return parsed.isSuccess ? this.repository.get(parsed.data) : parsed;
|
|
}
|
|
async save(scope: string, identity: string | undefined, input: AssetDefinitionSpec) {
|
|
const parent = catalogScope(scope);
|
|
const values = AssetDefinitionValues.create(input);
|
|
const id = identity ? UniqueID.create(identity) : Result.ok(undefined);
|
|
if (!parent.isSuccess) {
|
|
return parent;
|
|
}
|
|
if (!values.isSuccess) {
|
|
return values;
|
|
}
|
|
if (!id.isSuccess) {
|
|
return Result.fail(new AssetCatalogError("INVALID_REQUEST"));
|
|
}
|
|
return this.repository.update(parent.data, (catalog) =>
|
|
catalog.save(parent.data, id.data ? Maybe.some(id.data) : Maybe.none(), values.data)
|
|
);
|
|
}
|
|
async setActive(scope: string, identity: string, active: boolean | null) {
|
|
const parent = catalogScope(scope);
|
|
const id = UniqueID.create(identity);
|
|
if (!parent.isSuccess) {
|
|
return parent;
|
|
}
|
|
if (!id.isSuccess) {
|
|
return Result.fail(new AssetCatalogError("INVALID_REQUEST"));
|
|
}
|
|
return this.repository.update(parent.data, (catalog) =>
|
|
catalog.setActive(parent.data, id.data, active)
|
|
);
|
|
}
|
|
}
|