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

26 lines
876 B
TypeScript
Raw Normal View History

2025-08-26 18:55:59 +00:00
import { ExpressController, authGuard, forbidQueryFieldGuard, tenantGuard } from "@erp/core/api";
import { GetCustomerInvoiceUseCase } from "../../../application";
export class GetCustomerInvoiceController extends ExpressController {
2025-09-03 18:04:09 +00:00
public constructor(private readonly useCase: GetCustomerInvoiceUseCase) {
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-09-03 18:04:09 +00:00
const { invoice_id } = this.req.params;
2025-09-03 18:04:09 +00:00
const result = await this.useCase.execute({ invoice_id, companyId });
return result.match(
(data) => this.ok(data),
2025-08-26 18:55:59 +00:00
(err) => this.handleError(err)
);
}
}