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

26 lines
870 B
TypeScript

import { ExpressController, authGuard, forbidQueryFieldGuard, tenantGuard } from "@erp/core/api";
import { DeleteCustomerUseCase } from "../../../application";
export class DeleteCustomerController extends ExpressController {
public constructor(private readonly useCase: DeleteCustomerUseCase) {
super();
// 🔐 Reutiliza guards de auth/tenant y prohíbe 'companyId' en query
this.useGuards(authGuard(), tenantGuard(), forbidQueryFieldGuard("companyId"));
}
async executeImpl(): Promise<any> {
const companyId = this.getTenantId();
if (!companyId) {
return this.forbiddenError("Tenant ID not found");
}
const { customer_id } = this.req.params;
const result = await this.useCase.execute({ customer_id, companyId });
return result.match(
(data) => this.ok(data),
(err) => this.handleError(err)
);
}
}