31 lines
843 B
TypeScript
31 lines
843 B
TypeScript
|
|
import { ExpressController, errorMapper } from "@erp/core/api";
|
||
|
|
import { DeleteCustomerUseCase } from "../../application";
|
||
|
|
|
||
|
|
export class DeleteCustomerController extends ExpressController {
|
||
|
|
public constructor(private readonly deleteCustomer: DeleteCustomerUseCase) {
|
||
|
|
super();
|
||
|
|
}
|
||
|
|
|
||
|
|
async executeImpl(): Promise<any> {
|
||
|
|
const { id } = this.req.params;
|
||
|
|
|
||
|
|
/*
|
||
|
|
const user = this.req.user; // asumimos middleware authenticateJWT inyecta user
|
||
|
|
|
||
|
|
if (!user || !user.companyId) {
|
||
|
|
this.unauthorized(res, "Unauthorized: user or company not found");
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
*/
|
||
|
|
|
||
|
|
const result = await this.deleteCustomer.execute({ id });
|
||
|
|
|
||
|
|
if (result.isFailure) {
|
||
|
|
const apiError = errorMapper.toApiError(result.error);
|
||
|
|
return this.handleApiError(apiError);
|
||
|
|
}
|
||
|
|
|
||
|
|
return this.ok(result.data);
|
||
|
|
}
|
||
|
|
}
|