26 lines
930 B
TypeScript
26 lines
930 B
TypeScript
import { ExpressController, authGuard, forbidQueryFieldGuard, tenantGuard } from "@erp/core/api";
|
|
import { SendInvoiceVerifactuUseCase } from "../../../application/use-cases/send";
|
|
|
|
export class SendInvoiceVerifactuController extends ExpressController {
|
|
public constructor(private readonly useCase: SendInvoiceVerifactuUseCase) {
|
|
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, filename }) => this.downloadPDF(data, filename),
|
|
(err) => this.handleError(err)
|
|
);
|
|
}
|
|
}
|