metis-desk/modules/companies/src/api/domain/value-objects/process-template-values.ts
David dffb4b2794 feat: add process management features including feedback, help, and templates
- Implemented ProcessFeedback component for error handling in process forms.
- Created ProcessHelp component to provide contextual assistance for users.
- Added internationalization support for process-related strings in Spanish and English.
- Developed ProcessStartForm for initiating new processes with person and template selection.
- Introduced ProcessTemplateForm for creating and editing process templates.
- Built ProcessTemplatesPage to display and manage process templates.
- Enhanced ProcessesPage to list current processes and allow for creation and detail viewing.
- Added unit tests for various components to ensure functionality and correctness.
2026-10-07 09:34:18 +02:00

66 lines
2.1 KiB
TypeScript

import { Name } from "@repo/rdx-ddd";
import { Maybe, Result } from "@repo/rdx-utils";
import {
ProcessError,
type ProcessTemplateInput,
ProcessTemplateInputSchema,
} from "../process-values";
export class ProcessTemplateValues {
private constructor(
public readonly name: Name,
public readonly kind: ProcessTemplateInput["kind"],
public readonly active: boolean,
public readonly notes: Maybe<string>,
public readonly instructions: readonly Name[]
) {
Object.freeze(this);
}
static create(input: ProcessTemplateInput): Result<ProcessTemplateValues, ProcessError> {
const parsed = ProcessTemplateInputSchema.safeParse(input);
if (!parsed.success) {
return Result.fail(new ProcessError("INVALID_REQUEST"));
}
const name = Name.create(parsed.data.name, 160);
if (!name.isSuccess) {
return Result.fail(new ProcessError("INVALID_REQUEST"));
}
const instructions: Name[] = [];
for (const value of parsed.data.instructions) {
const item = Name.create(value, 160);
if (!item.isSuccess) {
return Result.fail(new ProcessError("INVALID_REQUEST"));
}
instructions.push(item.data);
}
return Result.ok(
new ProcessTemplateValues(
name.data,
parsed.data.kind,
parsed.data.active,
parsed.data.notes ? Maybe.some(parsed.data.notes) : Maybe.none(),
Object.freeze(instructions)
)
);
}
equals(other: ProcessTemplateValues) {
return (
this.name.equals(other.name) &&
this.kind === other.kind &&
this.active === other.active &&
this.notes.getOrUndefined() === other.notes.getOrUndefined() &&
this.instructions.length === other.instructions.length &&
this.instructions.every((item, index) => item.equals(other.instructions[index]))
);
}
toPrimitive(): ProcessTemplateInput {
return {
name: this.name.toPrimitive(),
kind: this.kind,
active: this.active,
notes: this.notes.getOrUndefined() ?? null,
instructions: this.instructions.map((n) => n.toPrimitive()),
};
}
}