Fallitos
This commit is contained in:
parent
a2b5c96cd7
commit
6cc728fb87
@ -5,7 +5,7 @@ export abstract class DomainEntity<T extends object> {
|
|||||||
public readonly id: UniqueID;
|
public readonly id: UniqueID;
|
||||||
|
|
||||||
protected constructor(props: T, id?: UniqueID) {
|
protected constructor(props: T, id?: UniqueID) {
|
||||||
this.id = id ? id : UniqueID.generateNewID().data;
|
this.id = id ? id : UniqueID.generateNewID();
|
||||||
this.props = props;
|
this.props = props;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -39,7 +39,12 @@ export function extractOrPushError<T>(
|
|||||||
|
|
||||||
if (isValidationErrorCollection(error)) {
|
if (isValidationErrorCollection(error)) {
|
||||||
// Agrega todos los detalles de error al array proporcionado
|
// Agrega todos los detalles de error al array proporcionado
|
||||||
errors.push(...error.details);
|
error.details.forEach((error) => {
|
||||||
|
errors.push({
|
||||||
|
...error,
|
||||||
|
path: error.path || path,
|
||||||
|
});
|
||||||
|
});
|
||||||
} else if (isDomainValidationError(error)) {
|
} else if (isDomainValidationError(error)) {
|
||||||
errors.push({ path, message: error.detail, value: error.cause?.toString() });
|
errors.push({ path, message: error.detail, value: error.cause?.toString() });
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
import { Result, generateUUIDv4 } from "@repo/rdx-utils";
|
import { Result, generateUUIDv4 } from "@repo/rdx-utils";
|
||||||
import * as z from "zod/v4";
|
import * as z from "zod/v4";
|
||||||
|
import { translateZodValidationError } from "../helpers";
|
||||||
import { ValueObject } from "./value-object";
|
import { ValueObject } from "./value-object";
|
||||||
|
|
||||||
export class UniqueID extends ValueObject<string> {
|
export class UniqueID extends ValueObject<string> {
|
||||||
@ -13,23 +14,23 @@ export class UniqueID extends ValueObject<string> {
|
|||||||
if (!generateOnEmpty) {
|
if (!generateOnEmpty) {
|
||||||
return Result.fail(new Error("ID cannot be undefined or null"));
|
return Result.fail(new Error("ID cannot be undefined or null"));
|
||||||
}
|
}
|
||||||
return UniqueID.generateNewID();
|
return Result.ok(UniqueID.generateNewID());
|
||||||
}
|
}
|
||||||
|
|
||||||
// biome-ignore lint/style/noNonNullAssertion: <explanation>
|
// biome-ignore lint/style/noNonNullAssertion: <explanation>
|
||||||
const result = UniqueID.validate(id!);
|
const valueIsValid = UniqueID.validate(id!);
|
||||||
|
|
||||||
return result.success
|
if (!valueIsValid.success) {
|
||||||
? Result.ok(new UniqueID(result.data))
|
return Result.fail(
|
||||||
: Result.fail(new Error(result.error.message));
|
translateZodValidationError("UniqueID creation failed", valueIsValid.error)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Result.ok(new UniqueID(valueIsValid.data));
|
||||||
}
|
}
|
||||||
|
|
||||||
static generate(): Result<UniqueID, never> {
|
static generateNewID(): UniqueID {
|
||||||
return UniqueID.generateNewID();
|
return new UniqueID(generateUUIDv4());
|
||||||
}
|
|
||||||
|
|
||||||
static generateNewID(): Result<UniqueID, never> {
|
|
||||||
return Result.ok(new UniqueID(generateUUIDv4()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getProps(): string {
|
getProps(): string {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user