test: implement resource template propagation tests for resource revisions feat: create prepareResourceTemplateUpdates function for handling resource template updates feat: add resource revision specifications for managing resource revisions in the database test: add tests for entity column visibility and local storage handling feat: implement entity column visibility storage for managing column preferences feat: create synchronizeTemplateStructure utility for managing template field and section synchronization
90 lines
2.6 KiB
TypeScript
90 lines
2.6 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.vo";
|
|
|
|
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,
|
|
actorId?: string
|
|
) {
|
|
const actor = actorId ? UniqueID.create(actorId) : undefined;
|
|
|
|
if (actor && !actor.isSuccess) {
|
|
return Result.fail(new AssetCatalogError("INVALID_REQUEST"));
|
|
}
|
|
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),
|
|
actor?.isSuccess ? actor.data : undefined
|
|
);
|
|
}
|
|
|
|
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)
|
|
);
|
|
}
|
|
|
|
async remove(scope: string, identity: string) {
|
|
const parent = catalogScope(scope);
|
|
const id = UniqueID.create(identity);
|
|
|
|
if (!(parent.isSuccess && id.isSuccess)) {
|
|
return Result.fail(new AssetCatalogError("INVALID_REQUEST"));
|
|
}
|
|
|
|
return this.repository.update(parent.data, (catalog) => catalog.remove(parent.data, id.data));
|
|
}
|
|
}
|