Uecko_ERP/templates/new-module/src/api/infrastructure/express/controllers/get-{{kebabCase name}}.controller.ts.hbs
2025-09-27 21:28:50 +02:00

26 lines
924 B
Handlebars

import { ExpressController, authGuard, tenantGuard, forbidQueryFieldGuard } from "@erp/core/api";
import { Get{{pascalCase name}}UseCase } from "../../../application";
/**
* Controlador de lectura por id en el contexto del tenant
*/
export class Get{{pascalCase name}}Controller extends ExpressController {
public constructor(private readonly useCase: Get{{pascalCase name}}UseCase) {
super();
this.useGuards(authGuard(), tenantGuard(), forbidQueryFieldGuard("companyId"));
}
protected async executeImpl() {
const companyId = this.getTenantId();
if (!companyId) return this.forbiddenError("Tenant ID not found");
const { {{snakeCase name}}_id } = this.req.params as { {{snakeCase name}}_id: string };
const result = await this.useCase.execute({ {{snakeCase name}}_id, companyId });
return result.match(
(data) => this.ok(data),
(err) => this.handleError(err)
);
}
}