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

39 lines
1.1 KiB
TypeScript
Raw Normal View History

2026-01-13 18:41:14 +00:00
import {
ExpressController,
forbidQueryFieldGuard,
requireAuthenticatedGuard,
requireCompanyContextGuard,
} from "@erp/core/api";
import type { 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
2026-01-13 18:41:14 +00:00
this.registerGuards(
requireAuthenticatedGuard(),
requireCompanyContextGuard(),
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
}
}