Uecko_ERP/modules/customers/src/api/infrastructure/express/controllers/delete-customer.controller.ts
2026-01-13 19:41:14 +01:00

39 lines
1.1 KiB
TypeScript

import {
ExpressController,
forbidQueryFieldGuard,
requireAuthenticatedGuard,
requireCompanyContextGuard,
} from "@erp/core/api";
import type { DeleteCustomerUseCase } from "../../../application";
import { customersApiErrorMapper } from "../customer-api-error-mapper";
export class DeleteCustomerController extends ExpressController {
public constructor(private readonly useCase: DeleteCustomerUseCase) {
super();
this.errorMapper = customersApiErrorMapper;
// 🔐 Reutiliza guards de auth/tenant y prohíbe 'companyId' en query
this.registerGuards(
requireAuthenticatedGuard(),
requireCompanyContextGuard(),
forbidQueryFieldGuard("companyId")
);
}
async executeImpl(): Promise<any> {
const companyId = this.getTenantId();
if (!companyId) {
return this.forbiddenError("Tenant ID not found");
}
const { customer_id } = this.req.params;
const result = await this.useCase.execute({ customer_id, companyId });
return result.match(
(data) => this.ok(data),
(err) => this.handleError(err)
);
}
}