2025-08-21 08:14:12 +00:00
|
|
|
import {
|
|
|
|
|
ExpressController,
|
|
|
|
|
authGuard,
|
|
|
|
|
errorMapper,
|
|
|
|
|
forbidQueryFieldGuard,
|
|
|
|
|
tenantGuard,
|
|
|
|
|
} from "@erp/core/api";
|
|
|
|
|
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();
|
2025-08-14 14:58:13 +00:00
|
|
|
// 🔐 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-08-21 08:14:12 +00:00
|
|
|
const tenantId = this.getTenantId()!; // garantizado por tenantGuard
|
2025-08-11 17:49:52 +00:00
|
|
|
const { id } = this.req.params;
|
|
|
|
|
|
2025-08-21 08:14:12 +00:00
|
|
|
const result = await this.useCase.execute({ id, tenantId });
|
2025-08-11 17:49:52 +00:00
|
|
|
|
2025-08-21 08:14:12 +00:00
|
|
|
return result.match(
|
|
|
|
|
(data) => this.ok(data),
|
|
|
|
|
(error) => this.handleApiError(errorMapper.toApiError(error))
|
|
|
|
|
);
|
2025-08-11 17:49:52 +00:00
|
|
|
}
|
|
|
|
|
}
|