50 lines
1.9 KiB
TypeScript
50 lines
1.9 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 {
|
|
CreateInvoiceFromCashMovementParams,
|
|
FindInvoicesParams,
|
|
IInvoice,
|
|
} from "../../Models/Invoices/Invoices.Interface";
|
|
import { InvoicesService } from "./Invoices.Service";
|
|
|
|
@Route("invoices/create-from-cash-movement")
|
|
@Middlewares(authenticateMiddleware)
|
|
export class InvoicesCreateFromCashMovementController extends Controller {
|
|
@SuccessResponse(200, "Done")
|
|
@Response<ApiValidationError>(500, "Ha ocurrido un error")
|
|
@Post()
|
|
public async createFromCashMovement(
|
|
@Body() requestBody: CreateInvoiceFromCashMovementParams
|
|
): Promise<IInvoice | ApiValidationError> {
|
|
try {
|
|
const invoice = await new InvoicesService().createFromCashMovement(requestBody);
|
|
this.setStatus(200);
|
|
return invoice;
|
|
} catch (e) {
|
|
const errorOccurred: Error = e as Error;
|
|
this.setStatus(500);
|
|
return new ApiValidationError(500, errorOccurred.message);
|
|
}
|
|
}
|
|
}
|
|
|
|
@Route("invoices/find")
|
|
@Middlewares(authenticateMiddleware)
|
|
export class InvoicesFindController extends Controller {
|
|
@SuccessResponse(200, "Done")
|
|
@Response<ApiValidationError>(500, "Ha ocurrido un error")
|
|
@Post()
|
|
public async find(@Body() requestBody: FindInvoicesParams): Promise<IInvoice[] | ApiValidationError> {
|
|
try {
|
|
const invoices = await new InvoicesService().find(requestBody);
|
|
this.setStatus(200);
|
|
return invoices;
|
|
} catch (e) {
|
|
const errorOccurred: Error = e as Error;
|
|
this.setStatus(500);
|
|
return new ApiValidationError(500, errorOccurred.message);
|
|
}
|
|
}
|
|
}
|