Compare commits

...

2 Commits

Author SHA1 Message Date
d55dee448b UtcDate.today() 2025-11-05 18:16:27 +01:00
4c891fb8c8 Mejora de las respuestas de error 2025-11-05 18:16:03 +01:00
3 changed files with 18 additions and 5 deletions

View File

@ -1,9 +1,9 @@
import { Result } from "@repo/rdx-utils";
import {
DomainValidationError,
ValidationErrorDetail,
isDomainValidationError,
isValidationErrorCollection,
ValidationErrorDetail,
} from "../errors";
/**
@ -43,7 +43,7 @@ export function extractOrPushError<T>(
error.details?.forEach((detail) => {
errors.push({
...detail,
path: detail.path ?? path,
path: path ?? detail.path,
});
});
} else if (isDomainValidationError(error)) {

View File

@ -9,8 +9,8 @@ export function translateZodValidationError<T>(
const errors: ValidationErrorDetail[] = [];
for (const issue of zodError.issues) {
errors.push({
message: issue.message,
path: issue.path.join("."),
message: `${message}: ${issue.message}`,
path: issue.path ? issue.path.join(".") : undefined,
value: errorValue ?? issue.input,
});
}

View File

@ -42,6 +42,19 @@ export class UtcDate extends ValueObject<UtcDateProps> {
return Result.ok(new UtcDate({ value: isoDateString }));
}
/**
* Creador estático: devuelve la fecha de HOY en UTC a medianoche (00:00:00Z).
* - Evita ambigüedades de zona horaria construyendo el ISO explícitamente.
*/
static today(): UtcDate {
const now = new Date();
const y = now.getUTCFullYear();
const m = String(now.getUTCMonth() + 1).padStart(2, "0");
const d = String(now.getUTCDate()).padStart(2, "0");
const iso = `${y}-${m}-${d}T00:00:00Z`;
return new UtcDate({ value: iso });
}
getProps(): string {
return this.props.value;
}
@ -57,7 +70,7 @@ export class UtcDate extends ValueObject<UtcDateProps> {
* Devuelve la fecha en formato UTC sin hora (YYYY-MM-DD).
*/
toDateString(): string {
return this.date.toISOString().split("T")[0];
return this.date.toISOString().split("T")[0] ?? "";
}
toString() {