Uecko_ERP/modules/customers/src/api/infrastructure/express/controllers/delete-customer.controller.ts

26 lines
870 B
TypeScript
Raw Normal View History

2025-08-26 18:55:59 +00:00
import { ExpressController, authGuard, forbidQueryFieldGuard, tenantGuard } from "@erp/core/api";
2025-08-21 08:14:12 +00:00
import { DeleteCustomerUseCase } from "../../../application";
2025-08-11 17:49:52 +00:00
export class DeleteCustomerController extends ExpressController {
2025-08-21 08:14:12 +00:00
public constructor(private readonly useCase: DeleteCustomerUseCase) {
2025-08-11 17:49:52 +00:00
super();
// 🔐 Reutiliza guards de auth/tenant y prohíbe 'companyId' en query
this.useGuards(authGuard(), tenantGuard(), forbidQueryFieldGuard("companyId"));
2025-08-11 17:49:52 +00:00
}
async executeImpl(): Promise<any> {
2025-09-14 10:04:57 +00:00
const companyId = this.getTenantId();
if (!companyId) {
return this.forbiddenError("Tenant ID not found");
}
2025-09-02 08:57:41 +00:00
const { customer_id } = this.req.params;
2025-08-11 17:49:52 +00:00
2025-09-02 08:57:41 +00:00
const result = await this.useCase.execute({ customer_id, companyId });
2025-08-11 17:49:52 +00:00
2025-08-21 08:14:12 +00:00
return result.match(
(data) => this.ok(data),
2025-08-26 18:55:59 +00:00
(err) => this.handleError(err)
2025-08-21 08:14:12 +00:00
);
2025-08-11 17:49:52 +00:00
}
}