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