Uecko_ERP/modules/customer-invoices/src/api/infrastructure/express/controllers/create-customer-invoice.controller.ts

25 lines
927 B
TypeScript
Raw Normal View History

2025-08-26 18:55:59 +00:00
import { ExpressController, authGuard, forbidQueryFieldGuard, tenantGuard } from "@erp/core/api";
import { CreateCustomerInvoiceRequestDTO } from "../../../../common/dto";
import { CreateCustomerInvoiceUseCase } from "../../../application";
export class CreateCustomerInvoiceController extends ExpressController {
2025-09-04 17:57:04 +00:00
public constructor(private readonly useCase: CreateCustomerInvoiceUseCase) {
super();
// 🔐 Reutiliza guards de auth/tenant y prohíbe 'companyId' en query
this.useGuards(authGuard(), tenantGuard(), forbidQueryFieldGuard("companyId"));
}
protected async executeImpl() {
2025-09-04 17:57:04 +00:00
const companyId = this.getTenantId()!; // garantizado por tenantGuard
const dto = this.req.body as CreateCustomerInvoiceRequestDTO;
2025-09-04 17:57:04 +00:00
const result = await this.useCase.execute({ dto, companyId });
return result.match(
(data) => this.created(data),
2025-08-26 18:55:59 +00:00
(err) => this.handleError(err)
);
}
}