46 lines
1.7 KiB
TypeScript
46 lines
1.7 KiB
TypeScript
|
|
import { UniqueID } from "@repo/rdx-ddd";
|
||
|
|
import { Result } from "@repo/rdx-utils";
|
||
|
|
|
||
|
|
import {
|
||
|
|
NetworkSharePublicationCommandSchema,
|
||
|
|
NetworkSharePublicationQuerySchema,
|
||
|
|
} from "../../common/network-share-publications";
|
||
|
|
import { AssetCatalogError } from "../domain/asset-definition";
|
||
|
|
|
||
|
|
import type { INetworkSharePublicationRepository } from "./network-share-publication.repository";
|
||
|
|
import { planNetworkSharePublication } from "./network-share-publication-plan";
|
||
|
|
|
||
|
|
export class NetworkSharePublicationUseCases {
|
||
|
|
constructor(private readonly repository: INetworkSharePublicationRepository) {}
|
||
|
|
|
||
|
|
execute(companyId: string, input: unknown, actorId: string) {
|
||
|
|
const company = UniqueID.create(companyId);
|
||
|
|
const actor = UniqueID.create(actorId);
|
||
|
|
const command = NetworkSharePublicationCommandSchema.safeParse(input);
|
||
|
|
|
||
|
|
if (!(company.isSuccess && actor.isSuccess && command.success)) {
|
||
|
|
return Promise.resolve(Result.fail(new AssetCatalogError("INVALID_REQUEST")));
|
||
|
|
}
|
||
|
|
|
||
|
|
return this.repository.mutate(company.data, command.data, (context) =>
|
||
|
|
planNetworkSharePublication(context, command.data, {
|
||
|
|
companyId: company.data,
|
||
|
|
actorId: actor.data,
|
||
|
|
now: new Date().toISOString(),
|
||
|
|
})
|
||
|
|
);
|
||
|
|
}
|
||
|
|
|
||
|
|
list(companyId: string, input: unknown, actorId: string) {
|
||
|
|
const company = UniqueID.create(companyId);
|
||
|
|
const actor = UniqueID.create(actorId);
|
||
|
|
const query = NetworkSharePublicationQuerySchema.safeParse(input);
|
||
|
|
|
||
|
|
if (!(company.isSuccess && actor.isSuccess && query.success)) {
|
||
|
|
return Promise.resolve(Result.fail(new AssetCatalogError("INVALID_REQUEST")));
|
||
|
|
}
|
||
|
|
|
||
|
|
return this.repository.list(company.data, actor.data, query.data);
|
||
|
|
}
|
||
|
|
}
|