2025-08-26 18:55:59 +00:00
|
|
|
import { ExpressController, authGuard, forbidQueryFieldGuard, tenantGuard } from "@erp/core/api";
|
2025-08-14 14:58:13 +00:00
|
|
|
|
|
|
|
|
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) {
|
2025-08-14 14:58:13 +00:00
|
|
|
super();
|
|
|
|
|
// 🔐 Reutiliza guards de auth/tenant y prohíbe 'companyId' en query
|
|
|
|
|
this.useGuards(authGuard(), tenantGuard(), forbidQueryFieldGuard("companyId"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected async executeImpl() {
|
2025-09-14 10:04:57 +00:00
|
|
|
const companyId = this.getTenantId();
|
|
|
|
|
if (!companyId) {
|
|
|
|
|
return this.forbiddenError("Tenant ID not found");
|
|
|
|
|
}
|
2025-08-14 14:58:13 +00:00
|
|
|
const dto = this.req.body as CreateCustomerInvoiceRequestDTO;
|
|
|
|
|
|
2025-09-04 17:57:04 +00:00
|
|
|
const result = await this.useCase.execute({ dto, companyId });
|
2025-08-14 14:58:13 +00:00
|
|
|
|
|
|
|
|
return result.match(
|
|
|
|
|
(data) => this.created(data),
|
2025-08-26 18:55:59 +00:00
|
|
|
(err) => this.handleError(err)
|
2025-08-14 14:58:13 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|