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

29 lines
996 B
TypeScript
Raw Normal View History

import { authGuard, ExpressController, forbidQueryFieldGuard, tenantGuard } from "@erp/core/api";
2025-08-21 08:14:12 +00:00
import { DeleteCustomerUseCase } from "../../../application";
import { customersApiErrorMapper } from "../customer-api-error-mapper";
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();
this.errorMapper = customersApiErrorMapper;
// 🔐 Reutiliza guards de auth/tenant y prohíbe 'companyId' en query
2025-11-04 19:15:25 +00:00
this.registerGuards(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
}
}