2026-01-13 18:41:14 +00:00
|
|
|
import {
|
|
|
|
|
ExpressController,
|
|
|
|
|
forbidQueryFieldGuard,
|
|
|
|
|
requireAuthenticatedGuard,
|
|
|
|
|
requireCompanyContextGuard,
|
|
|
|
|
} from "@erp/core/api";
|
|
|
|
|
|
|
|
|
|
import type { DeleteCustomerUseCase } from "../../../application";
|
2025-11-06 16:17:00 +00:00
|
|
|
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();
|
2025-11-06 16:17:00 +00:00
|
|
|
this.errorMapper = customersApiErrorMapper;
|
|
|
|
|
|
2025-08-14 14:58:13 +00:00
|
|
|
// 🔐 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
|
|
|
}
|
|
|
|
|
}
|