Uecko_ERP/modules/customer-invoices/src/api/infrastructure/express/controllers/get-customer-invoice.controller.ts
2025-09-14 12:04:57 +02:00

26 lines
876 B
TypeScript

import { ExpressController, authGuard, forbidQueryFieldGuard, tenantGuard } from "@erp/core/api";
import { GetCustomerInvoiceUseCase } from "../../../application";
export class GetCustomerInvoiceController extends ExpressController {
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() {
const companyId = this.getTenantId();
if (!companyId) {
return this.forbiddenError("Tenant ID not found");
}
const { invoice_id } = this.req.params;
const result = await this.useCase.execute({ invoice_id, companyId });
return result.match(
(data) => this.ok(data),
(err) => this.handleError(err)
);
}
}