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

31 lines
1.1 KiB
TypeScript
Raw Normal View History

import { authGuard, ExpressController, forbidQueryFieldGuard, tenantGuard } from "@erp/core/api";
2025-09-16 17:29:37 +00:00
import { UpdateCustomerByIdRequestDTO } from "../../../../common/dto";
2025-09-01 14:07:59 +00:00
import { UpdateCustomerUseCase } from "../../../application";
import { customersApiErrorMapper } from "../customer-api-error-mapper";
2025-09-01 14:07:59 +00:00
export class UpdateCustomerController extends ExpressController {
public constructor(private readonly useCase: UpdateCustomerUseCase) {
super();
this.errorMapper = customersApiErrorMapper;
2025-09-01 14:07:59 +00:00
// 🔐 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-09-01 14:07:59 +00:00
}
protected async executeImpl() {
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-09-16 17:29:37 +00:00
const dto = this.req.body as UpdateCustomerByIdRequestDTO;
2025-09-01 14:07:59 +00:00
2025-09-02 08:57:41 +00:00
const result = await this.useCase.execute({ customer_id, companyId, dto });
2025-09-01 14:07:59 +00:00
return result.match(
2025-09-02 11:06:25 +00:00
(data) => this.ok(data),
2025-09-01 14:07:59 +00:00
(err) => this.handleError(err)
);
}
}