Facturas de cliente
This commit is contained in:
parent
dba421e9c5
commit
6c472c21aa
@ -1,3 +1,4 @@
|
|||||||
export * from "./domain-validation-error";
|
export * from "./domain-validation-error";
|
||||||
export * from "./error-mapper";
|
export * from "./error-mapper";
|
||||||
|
export * from "./validation-api-error";
|
||||||
export * from "./validation-error-collection";
|
export * from "./validation-error-collection";
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
// src/common/middlewares/validate-dto.ts
|
// src/common/middlewares/validate-dto.ts
|
||||||
import { ValidationApiError } from "@erp/core/api";
|
import { ExpressController, ValidationApiError } from "@erp/core/api";
|
||||||
import { RequestHandler } from "express";
|
import { RequestHandler } from "express";
|
||||||
import { ZodSchema } from "zod/v4";
|
import { ZodSchema } from "zod/v4";
|
||||||
|
|
||||||
@ -40,17 +40,22 @@ export const validateRequest = <T extends "body" | "query" | "params">(
|
|||||||
options: ValidateRequestWithSchemaOptions = { sanitize: true }
|
options: ValidateRequestWithSchemaOptions = { sanitize: true }
|
||||||
): RequestHandler => {
|
): RequestHandler => {
|
||||||
return async (req, res, next) => {
|
return async (req, res, next) => {
|
||||||
console.debug(`Validating request ${source} with schema:`, schema);
|
console.debug(`Validating request ${source} with schema.`);
|
||||||
const result = schema.safeParse(req[source]);
|
const result = schema.safeParse(req[source]);
|
||||||
|
|
||||||
if (!result.success) {
|
if (!result.success) {
|
||||||
// Construye errores detallados
|
// Construye errores detallados
|
||||||
const validationErrors = result.error.errors.map((err) => ({
|
const validationErrors = result.error.issues.map((err) => ({
|
||||||
field: err.path.join("."),
|
field: err.path.join("."),
|
||||||
message: err.message,
|
message: err.message,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
return new ValidationApiError("Validation failed", validationErrors);
|
console.debug(validationErrors);
|
||||||
|
|
||||||
|
return ExpressController.errorResponse(
|
||||||
|
new ValidationApiError("Validation failed", validationErrors),
|
||||||
|
res
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Si pasa la validación, opcionalmente reescribe req.body
|
// Si pasa la validación, opcionalmente reescribe req.body
|
||||||
|
|||||||
@ -1,10 +1,9 @@
|
|||||||
import { ExpressController, errorMapper } from "@erp/core/api";
|
import { ExpressController, errorMapper } from "@erp/core/api";
|
||||||
import { CreateCustomerInvoiceCommandDTO } from "../../../common/dto";
|
import { CreateCustomerInvoiceCommandDTO } from "../../../common/dto";
|
||||||
|
import { CreateCustomerInvoiceUseCase } from "../../application";
|
||||||
|
|
||||||
export class CreateCustomerInvoiceController extends ExpressController {
|
export class CreateCustomerInvoiceController extends ExpressController {
|
||||||
public constructor(
|
public constructor(private readonly createCustomerInvoice: CreateCustomerInvoiceUseCase) {
|
||||||
private readonly createCustomerInvoice: any // Replace with actual type
|
|
||||||
) {
|
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -25,6 +24,7 @@ export class CreateCustomerInvoiceController extends ExpressController {
|
|||||||
const result = await this.createCustomerInvoice.execute(dto);
|
const result = await this.createCustomerInvoice.execute(dto);
|
||||||
|
|
||||||
if (result.isFailure) {
|
if (result.isFailure) {
|
||||||
|
console.log(result.error);
|
||||||
const apiError = errorMapper.toApiError(result.error);
|
const apiError = errorMapper.toApiError(result.error);
|
||||||
return this.handleApiError(apiError);
|
return this.handleApiError(apiError);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -45,5 +45,4 @@ export interface ICustomerInvoiceRepository {
|
|||||||
* @returns Result<void, Error>
|
* @returns Result<void, Error>
|
||||||
*/
|
*/
|
||||||
deleteById(id: UniqueID, transaction: any): Promise<Result<void, Error>>;
|
deleteById(id: UniqueID, transaction: any): Promise<Result<void, Error>>;
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@ -5,7 +5,10 @@ import {
|
|||||||
CreateCustomerInvoiceCommandSchema,
|
CreateCustomerInvoiceCommandSchema,
|
||||||
ListCustomerInvoicesQuerySchema,
|
ListCustomerInvoicesQuerySchema,
|
||||||
} from "../../../common/dto";
|
} from "../../../common/dto";
|
||||||
import { buildListCustomerInvoicesController } from "../../controllers";
|
import {
|
||||||
|
buildCreateCustomerInvoicesController,
|
||||||
|
buildListCustomerInvoicesController,
|
||||||
|
} from "../../controllers";
|
||||||
|
|
||||||
export const customerInvoicesRouter = (params: ModuleParams) => {
|
export const customerInvoicesRouter = (params: ModuleParams) => {
|
||||||
const { app, database, baseRoutePath, logger } = params as {
|
const { app, database, baseRoutePath, logger } = params as {
|
||||||
@ -43,7 +46,7 @@ export const customerInvoicesRouter = (params: ModuleParams) => {
|
|||||||
//checkUser,
|
//checkUser,
|
||||||
validateRequest(CreateCustomerInvoiceCommandSchema),
|
validateRequest(CreateCustomerInvoiceCommandSchema),
|
||||||
(req: Request, res: Response, next: NextFunction) => {
|
(req: Request, res: Response, next: NextFunction) => {
|
||||||
buildCreateCustomerInvoiceController(database).execute(req, res, next);
|
buildCreateCustomerInvoicesController(database).execute(req, res, next);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import * as z from "zod/v4";
|
import * as z from "zod/v4";
|
||||||
|
|
||||||
export const ICreateCustomerInvoiceRequestSchema = z.object({
|
export const ICreateCustomerInvoiceRequestSchema = z.object({
|
||||||
id: z.string().uuid(),
|
id: z.uuid(),
|
||||||
customerInvoice_number: z.string().min(1),
|
customerInvoice_number: z.string().min(1),
|
||||||
customerInvoice_series: z.string().min(1),
|
customerInvoice_series: z.string().min(1),
|
||||||
issue_date: z.string().refine((date) => {
|
issue_date: z.string().refine((date) => {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user