- Add SoftwareInstallationValues value object for encapsulating software installation data. - Create HTTP routes for managing software installations, including GET, POST, and DELETE operations. - Implement Sequelize repository for software installations, handling database interactions. - Add migration script for creating necessary database tables for software installations. - Create persistence mapper for transforming between domain models and database rows. - Define snapshot schema for software installations to ensure data consistency. - Introduce common schemas for software installations to validate API requests and responses. - Develop UI components for displaying and managing software installations, including history dialogs and forms. - Implement API client for interacting with software installation endpoints. - Write tests for software installations panel and form components to ensure functionality.
73 lines
2.4 KiB
TypeScript
73 lines
2.4 KiB
TypeScript
import { UniqueID } from "@repo/rdx-ddd";
|
|
import { Result } from "@repo/rdx-utils";
|
|
|
|
import { SoftwareInstallation } from "../domain/software-installation.aggregate";
|
|
import type { SoftwareInstallationInput } from "../domain/software-installation-values";
|
|
import { SoftwareInstallationError } from "../domain/software-installation-values";
|
|
|
|
import type { ISoftwareInstallationRepository } from "./software-installation.repository";
|
|
import { mapSoftwareInput } from "./software-installation-input.mapper";
|
|
|
|
export class SoftwareInstallationUseCases {
|
|
constructor(private readonly repository: ISoftwareInstallationRepository) {}
|
|
|
|
remove(companyId: string, id: string) {
|
|
const company = UniqueID.create(companyId);
|
|
const identity = UniqueID.create(id);
|
|
|
|
if (!(company.isSuccess && identity.isSuccess)) {
|
|
return Promise.resolve(Result.fail(new SoftwareInstallationError("INVALID_REQUEST")));
|
|
}
|
|
|
|
return this.repository.remove(company.data, identity.data);
|
|
}
|
|
|
|
get(companyId: string) {
|
|
const company = UniqueID.create(companyId);
|
|
|
|
return company.isSuccess
|
|
? this.repository.get(company.data)
|
|
: Promise.resolve(Result.fail(new SoftwareInstallationError("INVALID_REQUEST")));
|
|
}
|
|
|
|
save(
|
|
companyId: string,
|
|
id: string | undefined,
|
|
input: SoftwareInstallationInput,
|
|
actorId: string
|
|
) {
|
|
const company = UniqueID.create(companyId);
|
|
const actor = UniqueID.create(actorId);
|
|
const identity = id ? UniqueID.create(id) : undefined;
|
|
|
|
if (!(company.isSuccess && actor.isSuccess) || (identity && !identity.isSuccess)) {
|
|
return Promise.resolve(Result.fail(new SoftwareInstallationError("INVALID_REQUEST")));
|
|
}
|
|
|
|
return this.repository.save(company.data, (context) => {
|
|
const previous = identity?.isSuccess
|
|
? context.configurations.find((item) => item.id.equals(identity.data))
|
|
: undefined;
|
|
|
|
if (id && !previous) {
|
|
return Result.fail(new SoftwareInstallationError("SOFTWARE_CONFIGURATION_NOT_FOUND"));
|
|
}
|
|
const values = mapSoftwareInput(input, context, previous);
|
|
|
|
if (!values.isSuccess) {
|
|
return values;
|
|
}
|
|
const now = new Date().toISOString();
|
|
const candidate = previous
|
|
? previous.update(values.data, actor.data, now)
|
|
: SoftwareInstallation.create(company.data, values.data, actor.data, now);
|
|
|
|
if (!candidate.isSuccess) {
|
|
return candidate;
|
|
}
|
|
|
|
return candidate;
|
|
});
|
|
}
|
|
}
|