52 lines
2.1 KiB
TypeScript
52 lines
2.1 KiB
TypeScript
import { Body, Controller, Middlewares, Post, Response, Route, SuccessResponse } from "tsoa";
|
|
import { authenticateMiddleware } from "../../middleware/authentication";
|
|
import { ApiValidationError } from "../../Models/Server.Error.model";
|
|
import {
|
|
FindOrganizationFiscalProfilesParams,
|
|
IOrganizationFiscalProfile,
|
|
UpsertOrganizationFiscalProfileParams,
|
|
} from "../../Models/OrganizationFiscalProfiles/OrganizationFiscalProfiles.Interface";
|
|
import { OrganizationFiscalProfilesService } from "./OrganizationFiscalProfiles.Service";
|
|
|
|
@Route("organization-fiscal-profiles/upsert")
|
|
@Middlewares(authenticateMiddleware)
|
|
export class OrganizationFiscalProfilesUpsertController extends Controller {
|
|
@SuccessResponse(200, "Done")
|
|
@Response<ApiValidationError>(500, "Ha ocurrido un error")
|
|
@Post()
|
|
public async upsert(
|
|
@Body() requestBody: UpsertOrganizationFiscalProfileParams
|
|
): Promise<IOrganizationFiscalProfile | ApiValidationError> {
|
|
try {
|
|
const profile = await new OrganizationFiscalProfilesService().upsert(requestBody);
|
|
this.setStatus(200);
|
|
return profile;
|
|
} catch (e) {
|
|
const errorOccurred: Error = e as Error;
|
|
this.setStatus(500);
|
|
return new ApiValidationError(500, errorOccurred.message);
|
|
}
|
|
}
|
|
}
|
|
|
|
@Route("organization-fiscal-profiles/find")
|
|
@Middlewares(authenticateMiddleware)
|
|
export class OrganizationFiscalProfilesFindController extends Controller {
|
|
@SuccessResponse(200, "Done")
|
|
@Response<ApiValidationError>(500, "Ha ocurrido un error")
|
|
@Post()
|
|
public async find(
|
|
@Body() requestBody: FindOrganizationFiscalProfilesParams
|
|
): Promise<IOrganizationFiscalProfile[] | ApiValidationError> {
|
|
try {
|
|
const profiles = await new OrganizationFiscalProfilesService().find(requestBody);
|
|
this.setStatus(200);
|
|
return profiles;
|
|
} catch (e) {
|
|
const errorOccurred: Error = e as Error;
|
|
this.setStatus(500);
|
|
return new ApiValidationError(500, errorOccurred.message);
|
|
}
|
|
}
|
|
}
|