mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-18 22:00:31 +00:00
refactor: payment services to nestjs
This commit is contained in:
@@ -0,0 +1,86 @@
|
||||
import {
|
||||
Controller,
|
||||
Get,
|
||||
Post,
|
||||
Delete,
|
||||
Param,
|
||||
Body,
|
||||
Req,
|
||||
Res,
|
||||
Next,
|
||||
UsePipes,
|
||||
ValidationPipe,
|
||||
HttpStatus,
|
||||
} from '@nestjs/common';
|
||||
import { Request, Response, NextFunction } from 'express';
|
||||
import { ApiTags } from '@nestjs/swagger';
|
||||
import { PaymentServicesApplication } from './PaymentServicesApplication';
|
||||
|
||||
@ApiTags('PaymentServices')
|
||||
@Controller('payment-services')
|
||||
export class PaymentServicesController {
|
||||
constructor(
|
||||
private readonly paymentServicesApp: PaymentServicesApplication,
|
||||
) {}
|
||||
|
||||
@Get('/')
|
||||
async getPaymentServicesSpecificInvoice(@Res() res: Response) {
|
||||
const paymentServices =
|
||||
await this.paymentServicesApp.getPaymentServicesForInvoice();
|
||||
|
||||
return res.status(HttpStatus.OK).send({ paymentServices });
|
||||
}
|
||||
|
||||
@Get('/state')
|
||||
async getPaymentMethodsState(@Res() res: Response) {
|
||||
const paymentMethodsState =
|
||||
await this.paymentServicesApp.getPaymentMethodsState();
|
||||
|
||||
return res.status(HttpStatus.OK).send({ data: paymentMethodsState });
|
||||
}
|
||||
|
||||
@Get('/:paymentServiceId')
|
||||
async getPaymentService(
|
||||
@Param('paymentServiceId') paymentServiceId: number,
|
||||
@Req() req: Request,
|
||||
@Res() res: Response,
|
||||
@Next() next: NextFunction,
|
||||
) {
|
||||
const paymentService =
|
||||
await this.paymentServicesApp.getPaymentService(paymentServiceId);
|
||||
|
||||
return res.status(HttpStatus.OK).send({ data: paymentService });
|
||||
}
|
||||
|
||||
@Post('/:paymentMethodId')
|
||||
@UsePipes(new ValidationPipe({ whitelist: true }))
|
||||
async updatePaymentMethod(
|
||||
@Param('paymentMethodId') paymentMethodId: number,
|
||||
@Body() updatePaymentMethodDTO: any,
|
||||
@Req() req: Request,
|
||||
@Res() res: Response,
|
||||
@Next() next: NextFunction,
|
||||
) {
|
||||
await this.paymentServicesApp.editPaymentMethod(
|
||||
paymentMethodId,
|
||||
updatePaymentMethodDTO,
|
||||
);
|
||||
return res.status(HttpStatus.OK).send({
|
||||
id: paymentMethodId,
|
||||
message: 'The given payment method has been updated.',
|
||||
});
|
||||
}
|
||||
|
||||
@Delete('/:paymentMethodId')
|
||||
async deletePaymentMethod(
|
||||
@Param('paymentMethodId') paymentMethodId: number,
|
||||
@Res() res: Response,
|
||||
) {
|
||||
await this.paymentServicesApp.deletePaymentMethod(paymentMethodId);
|
||||
|
||||
return res.status(HttpStatus.NO_CONTENT).send({
|
||||
id: paymentMethodId,
|
||||
message: 'The payment method has been deleted.',
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user