swagger for controllers
This commit is contained in:
parent
7966124df6
commit
66391a2ab2
6735
package-lock.json
generated
6735
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -1,5 +1,5 @@
|
||||
{
|
||||
"name": "abnandan-skeleton-be",
|
||||
"name": "remedify-payment-microservice",
|
||||
"version": "0.0.1",
|
||||
"description": "",
|
||||
"author": "",
|
||||
@ -23,11 +23,11 @@
|
||||
"test:e2e": "jest --config ./test/jest-e2e.json"
|
||||
},
|
||||
"dependencies": {
|
||||
"@nestjs-modules/mailer": "^1.10.3",
|
||||
"@nestjs/common": "^10.0.0",
|
||||
"@nestjs/config": "^3.1.1",
|
||||
"@nestjs/core": "^10.0.0",
|
||||
"@nestjs/platform-express": "^10.0.0",
|
||||
"@nestjs/swagger": "^8.1.1",
|
||||
"@nestjs/typeorm": "^10.0.1",
|
||||
"dotenv": "^16.3.1",
|
||||
"handlebars": "^4.7.8",
|
||||
|
||||
@ -30,8 +30,8 @@ import { RefundsModule } from './refund/refund.module';
|
||||
QuoteModule,
|
||||
RefundsModule,
|
||||
DataModule,
|
||||
MailModule,
|
||||
MasterConfigModule,
|
||||
// MailModule,
|
||||
// MasterConfigModule,
|
||||
ConfigModule,
|
||||
],
|
||||
controllers: [AppController, AppConfigController],
|
||||
|
||||
@ -3,19 +3,81 @@ import { Response } from 'express';
|
||||
import { InvoicesService } from './invoice.service';
|
||||
import { GenericResponse } from 'src/common/GenericResponse.model';
|
||||
import Invoice from './invoice.entity';
|
||||
import { ApiTags, ApiOperation, ApiResponse, ApiParam, ApiBody } from '@nestjs/swagger';
|
||||
|
||||
@ApiTags('invoices')
|
||||
@Controller('invoice')
|
||||
export class InvoicesController {
|
||||
constructor(private invoiceService: InvoicesService) { }
|
||||
constructor(private invoiceService: InvoicesService) {}
|
||||
|
||||
@Get("/all")
|
||||
@ApiOperation({ summary: 'Get all invoices' })
|
||||
@ApiResponse({
|
||||
status: 200,
|
||||
description: 'Successfully retrieved all invoices',
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 404,
|
||||
description: 'No invoices found',
|
||||
example: {
|
||||
"notification": {
|
||||
"exception": true,
|
||||
"exceptionSeverity": "HIGH",
|
||||
"exceptionMessage": "ERR.NOT_FOUND",
|
||||
"stackTrace": "No invoices found"
|
||||
},
|
||||
"data": null
|
||||
}
|
||||
})
|
||||
async getAll(@Res() res: Response) {
|
||||
const response = await this.invoiceService.findAll() || [];
|
||||
const httpResponse = new GenericResponse(null, response)
|
||||
res.send(httpResponse);
|
||||
const response = await this.invoiceService.findAll();
|
||||
if (!response) {
|
||||
const errorResponse = new GenericResponse({
|
||||
exception: true,
|
||||
exceptionSeverity: 'HIGH',
|
||||
exceptionMessage: 'ERR.NOT_FOUND',
|
||||
stackTrace: 'No invoices found'
|
||||
}, null);
|
||||
res.status(404).send(errorResponse);
|
||||
return;
|
||||
}
|
||||
const httpResponse = new GenericResponse(null, response);
|
||||
res.status(200).send(httpResponse);
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
@ApiOperation({ summary: 'Get invoice by ID' })
|
||||
@ApiParam({ name: 'id', type: Number, description: 'Invoice ID' })
|
||||
@ApiResponse({
|
||||
status: 400,
|
||||
description: 'ID parameter is missing',
|
||||
example: {
|
||||
"notification": {
|
||||
"exception": true,
|
||||
"exceptionSeverity": "HIGH",
|
||||
"exceptionMessage": "ERR.NO_ID_IN_REQ",
|
||||
"stackTrace": "Request"
|
||||
},
|
||||
"data": null
|
||||
}
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 404,
|
||||
description: 'Invoice not found',
|
||||
example: {
|
||||
"notification": {
|
||||
"exception": true,
|
||||
"exceptionSeverity": "HIGH",
|
||||
"exceptionMessage": "ERR.NOT_FOUND",
|
||||
"stackTrace": "Invoice not found"
|
||||
},
|
||||
"data": null
|
||||
}
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 200,
|
||||
description: 'Successfully retrieved invoice',
|
||||
})
|
||||
async findById(@Param('id') id: number, @Res() res: Response) {
|
||||
if (!id) {
|
||||
const response = new GenericResponse({
|
||||
@ -24,80 +86,232 @@ export class InvoicesController {
|
||||
exceptionMessage: 'ERR.NO_ID_IN_REQ',
|
||||
stackTrace: 'Request'
|
||||
}, null);
|
||||
res.send(response);
|
||||
res.status(400).send(response);
|
||||
return;
|
||||
}
|
||||
const response = await this.invoiceService.findByPk(id) || {};
|
||||
const httpResponse = new GenericResponse(null, response)
|
||||
res.send(httpResponse);
|
||||
const response = await this.invoiceService.findByPk(id);
|
||||
if (!response) {
|
||||
const errorResponse = new GenericResponse({
|
||||
exception: true,
|
||||
exceptionSeverity: 'HIGH',
|
||||
exceptionMessage: 'ERR.NOT_FOUND',
|
||||
stackTrace: `Invoice with ID ${id} not found`
|
||||
}, null);
|
||||
res.status(404).send(errorResponse);
|
||||
return;
|
||||
}
|
||||
const httpResponse = new GenericResponse(null, response);
|
||||
res.status(200).send(httpResponse);
|
||||
}
|
||||
|
||||
@Post('/filter')
|
||||
async filter(@Body() user: Invoice, @Res() res: Response) {
|
||||
if (!user) {
|
||||
@ApiOperation({ summary: 'Filter invoices based on criteria' })
|
||||
@ApiBody({ type: Invoice, description: 'Invoice filter criteria' })
|
||||
@ApiResponse({
|
||||
status: 404,
|
||||
description: 'No invoices matching criteria found',
|
||||
example: {
|
||||
"notification": {
|
||||
"exception": true,
|
||||
"exceptionSeverity": "HIGH",
|
||||
"exceptionMessage": "ERR.NOT_FOUND",
|
||||
"stackTrace": "No invoices found matching criteria"
|
||||
},
|
||||
"data": null
|
||||
}
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 200,
|
||||
description: 'Successfully filtered invoices',
|
||||
})
|
||||
async filter(@Body() invoice: Invoice, @Res() res: Response) {
|
||||
if (!invoice) {
|
||||
const response = new GenericResponse({
|
||||
exception: true,
|
||||
exceptionSeverity: 'HIGH',
|
||||
exceptionMessage: 'ERR.NO_REQ',
|
||||
stackTrace: 'Request'
|
||||
}, null);
|
||||
res.send(response);
|
||||
res.status(400).send(response);
|
||||
return;
|
||||
}
|
||||
const response = await this.invoiceService.filter(user) || [];
|
||||
const httpResponse = new GenericResponse(null, response)
|
||||
res.send(httpResponse);
|
||||
const response = await this.invoiceService.filter(invoice);
|
||||
if (!response) {
|
||||
const errorResponse = new GenericResponse({
|
||||
exception: true,
|
||||
exceptionSeverity: 'HIGH',
|
||||
exceptionMessage: 'ERR.NOT_FOUND',
|
||||
stackTrace: 'No invoices found matching criteria'
|
||||
}, null);
|
||||
res.status(404).send(errorResponse);
|
||||
return;
|
||||
}
|
||||
const httpResponse = new GenericResponse(null, response);
|
||||
res.status(200).send(httpResponse);
|
||||
}
|
||||
|
||||
@Post()
|
||||
async insert(@Body() user: Invoice, @Res() res: Response) {
|
||||
if (!user) {
|
||||
@ApiOperation({ summary: 'Insert a new invoice' })
|
||||
@ApiBody({ type: Invoice, description: 'Invoice data to insert' })
|
||||
@ApiResponse({
|
||||
status: 400,
|
||||
description: 'Failed to insert invoice',
|
||||
example: {
|
||||
"notification": {
|
||||
"exception": true,
|
||||
"exceptionSeverity": "HIGH",
|
||||
"exceptionMessage": "ERR.NOT_FOUND",
|
||||
"stackTrace": "Invoice not created"
|
||||
},
|
||||
"data": null
|
||||
}
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 201,
|
||||
description: 'Invoice successfully created',
|
||||
})
|
||||
async insert(@Body() invoice: Invoice, @Res() res: Response) {
|
||||
if (!invoice) {
|
||||
const response = new GenericResponse({
|
||||
exception: true,
|
||||
exceptionSeverity: 'HIGH',
|
||||
exceptionMessage: 'ERR.NO_REQ',
|
||||
stackTrace: 'Request'
|
||||
}, null);
|
||||
res.send(response);
|
||||
res.status(400).send(response);
|
||||
return;
|
||||
}
|
||||
delete user.id;
|
||||
const response = await this.invoiceService.upsert(user, true);
|
||||
const httpResponse = new GenericResponse(null, response)
|
||||
res.send(httpResponse);
|
||||
delete invoice.id;
|
||||
const response = await this.invoiceService.upsert(invoice, true);
|
||||
if (!response) {
|
||||
const errorResponse = new GenericResponse({
|
||||
exception: true,
|
||||
exceptionSeverity: 'HIGH',
|
||||
exceptionMessage: 'ERR.NOT_CREATED',
|
||||
stackTrace: 'Invoice not created'
|
||||
}, null);
|
||||
res.status(404).send(errorResponse);
|
||||
return;
|
||||
}
|
||||
const httpResponse = new GenericResponse(null, response);
|
||||
res.status(201).send(httpResponse);
|
||||
}
|
||||
|
||||
@Put()
|
||||
async update(@Body() user: Invoice, @Res() res: Response) {
|
||||
if (!user || !user.id) {
|
||||
@ApiOperation({ summary: 'Update an existing invoice' })
|
||||
@ApiBody({ type: Invoice, description: 'Invoice data to update' })
|
||||
@ApiResponse({
|
||||
status: 400,
|
||||
description: 'Failed to update invoice',
|
||||
example: {
|
||||
"notification": {
|
||||
"exception": true,
|
||||
"exceptionSeverity": "HIGH",
|
||||
"exceptionMessage": "ERR.NOT_FOUND",
|
||||
"stackTrace": "Invoice not updated"
|
||||
},
|
||||
"data": null
|
||||
}
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 404,
|
||||
description: 'Invoice not found',
|
||||
example: {
|
||||
"notification": {
|
||||
"exception": true,
|
||||
"exceptionSeverity": "HIGH",
|
||||
"exceptionMessage": "ERR.NOT_FOUND",
|
||||
"stackTrace": "Invoice not found"
|
||||
},
|
||||
"data": null
|
||||
}
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 200,
|
||||
description: 'Invoice successfully updated',
|
||||
})
|
||||
async update(@Body() invoice: Invoice, @Res() res: Response) {
|
||||
if (!invoice || !invoice.id) {
|
||||
const response = new GenericResponse({
|
||||
exception: true,
|
||||
exceptionSeverity: 'HIGH',
|
||||
exceptionMessage: 'ERR.NO_REQ',
|
||||
stackTrace: 'Request'
|
||||
}, null);
|
||||
res.send(response);
|
||||
res.status(400).send(response);
|
||||
return;
|
||||
}
|
||||
const response = await this.invoiceService.upsert(user, false);
|
||||
const httpResponse = new GenericResponse(null, response)
|
||||
res.send(httpResponse);
|
||||
const response = await this.invoiceService.upsert(invoice, false);
|
||||
if (!response) {
|
||||
const errorResponse = new GenericResponse({
|
||||
exception: true,
|
||||
exceptionSeverity: 'HIGH',
|
||||
exceptionMessage: 'ERR.NOT_FOUND',
|
||||
stackTrace: 'Invoice not updated'
|
||||
}, null);
|
||||
res.status(404).send(errorResponse);
|
||||
return;
|
||||
}
|
||||
const httpResponse = new GenericResponse(null, response);
|
||||
res.status(200).send(httpResponse);
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
@ApiOperation({ summary: 'Delete an invoice by ID' })
|
||||
@ApiParam({ name: 'id', type: Number, description: 'Invoice ID to delete' })
|
||||
@ApiResponse({
|
||||
status: 400,
|
||||
description: 'ID parameter is missing',
|
||||
example: {
|
||||
"notification": {
|
||||
"exception": true,
|
||||
"exceptionSeverity": "HIGH",
|
||||
"exceptionMessage": "ERR.NO_ID_IN_REQ",
|
||||
"stackTrace": "Request"
|
||||
},
|
||||
"data": null
|
||||
}
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 404,
|
||||
description: 'Invoice not found',
|
||||
example: {
|
||||
"notification": {
|
||||
"exception": true,
|
||||
"exceptionSeverity": "HIGH",
|
||||
"exceptionMessage": "ERR.NOT_FOUND",
|
||||
"stackTrace": "Invoice not found"
|
||||
},
|
||||
"data": null
|
||||
}
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 200,
|
||||
description: 'Invoice successfully deleted',
|
||||
})
|
||||
async deleteById(@Param('id') id: number, @Res() res: Response) {
|
||||
if (!id) {
|
||||
const response = new GenericResponse({
|
||||
exception: true,
|
||||
exceptionSeverity: 'HIGH',
|
||||
exceptionMessage: 'ERR.NO_REQ',
|
||||
exceptionMessage: 'ERR.NO_ID_IN_REQ',
|
||||
stackTrace: 'Request'
|
||||
}, null);
|
||||
res.send(response);
|
||||
res.status(400).send(response);
|
||||
return;
|
||||
}
|
||||
const response = await this.invoiceService.remove(id) || {};
|
||||
const httpResponse = new GenericResponse(null, response)
|
||||
res.send(httpResponse);
|
||||
const response = await this.invoiceService.remove(id);
|
||||
if (!response) {
|
||||
const errorResponse = new GenericResponse({
|
||||
exception: true,
|
||||
exceptionSeverity: 'HIGH',
|
||||
exceptionMessage: 'ERR.NOT_FOUND',
|
||||
stackTrace: `Invoice with ID ${id} not found`
|
||||
}, null);
|
||||
res.status(404).send(errorResponse);
|
||||
return;
|
||||
}
|
||||
const httpResponse = new GenericResponse(null, response);
|
||||
res.status(200).send(httpResponse);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import { MailerModule } from '@nestjs-modules/mailer';
|
||||
import { HandlebarsAdapter } from '@nestjs-modules/mailer/dist/adapters/handlebars.adapter';
|
||||
// import { MailerModule } from '@nestjs-modules/mailer';
|
||||
// import { HandlebarsAdapter } from '@nestjs-modules/mailer/dist/adapters/handlebars.adapter';
|
||||
import { Module } from '@nestjs/common';
|
||||
import { MailService } from './mail.service';
|
||||
import { join } from 'path';
|
||||
@ -7,21 +7,21 @@ import { Utility } from 'src/common/Utility';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
MailerModule.forRoot({
|
||||
// transport: 'smtps://user@example.com:topsecret@smtp.example.com',
|
||||
// or
|
||||
transport: Utility.mailConfig.transport,
|
||||
defaults: Utility.mailConfig.defaults,
|
||||
template: {
|
||||
dir: join(__dirname, 'templates'),
|
||||
adapter: new HandlebarsAdapter(), // or new PugAdapter() or new EjsAdapter()
|
||||
options: {
|
||||
strict: true,
|
||||
},
|
||||
},
|
||||
}),
|
||||
// MailerModule.forRoot({
|
||||
// // transport: 'smtps://user@example.com:topsecret@smtp.example.com',
|
||||
// // or
|
||||
// transport: Utility.mailConfig.transport,
|
||||
// defaults: Utility.mailConfig.defaults,
|
||||
// template: {
|
||||
// dir: join(__dirname, 'templates'),
|
||||
// adapter: new HandlebarsAdapter(), // or new PugAdapter() or new EjsAdapter()
|
||||
// options: {
|
||||
// strict: true,
|
||||
// },
|
||||
// },
|
||||
// }),
|
||||
],
|
||||
providers: [MailService],
|
||||
exports: [MailService], // 👈 export for DI
|
||||
// providers: [MailService],
|
||||
// exports: [MailService], // 👈 export for DI
|
||||
})
|
||||
export class MailModule {}
|
||||
|
||||
@ -1,19 +1,19 @@
|
||||
import { MailerService } from '@nestjs-modules/mailer';
|
||||
// import { MailerService } from '@nestjs-modules/mailer';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
|
||||
@Injectable()
|
||||
export class MailService {
|
||||
constructor(private mailerService: MailerService) { }
|
||||
// constructor(private mailerService: MailerService) { }
|
||||
|
||||
|
||||
async sendEmail(templateName: string, subject: string, context: any, toEmail: string, ccEmails?: string[], bccEmails?: string[]) {
|
||||
await this.mailerService.sendMail({
|
||||
to: toEmail,
|
||||
cc: ccEmails,
|
||||
bcc: bccEmails,
|
||||
subject: subject,
|
||||
template: templateName, // `.hbs` extension is appended automatically
|
||||
context,
|
||||
})
|
||||
}
|
||||
// async sendEmail(templateName: string, subject: string, context: any, toEmail: string, ccEmails?: string[], bccEmails?: string[]) {
|
||||
// await this.mailerService.sendMail({
|
||||
// to: toEmail,
|
||||
// cc: ccEmails,
|
||||
// bcc: bccEmails,
|
||||
// subject: subject,
|
||||
// template: templateName, // `.hbs` extension is appended automatically
|
||||
// context,
|
||||
// })
|
||||
// }
|
||||
}
|
||||
|
||||
@ -3,14 +3,18 @@ import { AppModule } from './app.module';
|
||||
import * as bodyParser from 'body-parser';
|
||||
import * as configMaster from './app-config/config.json';
|
||||
import { Utility } from './common/Utility';
|
||||
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
|
||||
|
||||
async function bootstrap() {
|
||||
Utility.appPort = configMaster.local.appConfig.port;
|
||||
Utility.mailConfig = configMaster.local.mailConfig;
|
||||
Utility.fileConfig = configMaster.local.fileConfig;
|
||||
const app = await NestFactory.create(AppModule, { cors: true });
|
||||
app.use(bodyParser.json({limit: '50mb'}));
|
||||
app.use(bodyParser.urlencoded({limit: '50mb', extended: true}));
|
||||
const config = new DocumentBuilder().setTitle('Payment API').setVersion('1.0').addTag('payments').build();
|
||||
const document = SwaggerModule.createDocument(app, config);
|
||||
SwaggerModule.setup('api', app, document);
|
||||
app.use(bodyParser.json({ limit: '50mb' }));
|
||||
app.use(bodyParser.urlencoded({ limit: '50mb', extended: true }));
|
||||
await app.listen(Utility.appPort);
|
||||
}
|
||||
bootstrap();
|
||||
|
||||
@ -2,102 +2,310 @@ import { Body, Controller, Delete, Get, Param, Post, Put, Res } from '@nestjs/co
|
||||
import { Response } from 'express';
|
||||
import { OffersRedemptionsService } from './offers-redemption.service';
|
||||
import { GenericResponse } from 'src/common/GenericResponse.model';
|
||||
import OffersRedemption from './offers-redemption.entity';
|
||||
import OffersRedemption from './offers-redemption.entity';
|
||||
import { ApiTags, ApiOperation, ApiResponse, ApiParam, ApiBody } from '@nestjs/swagger';
|
||||
|
||||
@ApiTags('offers-redemption')
|
||||
@Controller('offers-redemption')
|
||||
export class OffersRedemptionsController {
|
||||
constructor(private offersRedemptionService: OffersRedemptionsService) {}
|
||||
|
||||
@Get("/all")
|
||||
@ApiOperation({ summary: 'Get all offers redemptions' })
|
||||
@ApiResponse({ status: 200, description: 'Successfully retrieved all offers redemptions' })
|
||||
@ApiResponse({
|
||||
status: 404,
|
||||
description: 'No offers redemption found',
|
||||
example: {
|
||||
"notification": {
|
||||
"exception": true,
|
||||
"exceptionSeverity": "HIGH",
|
||||
"exceptionMessage": "ERR.NOT_FOUND",
|
||||
"stackTrace": "No offers redemptions found"
|
||||
},
|
||||
"data": null
|
||||
}
|
||||
})
|
||||
async getAllCompanys(@Res() res: Response) {
|
||||
const response = await this.offersRedemptionService.findAll() || [];
|
||||
const httpResponse = new GenericResponse(null, response)
|
||||
res.send(httpResponse);
|
||||
if (!response) {
|
||||
const errorResponse = new GenericResponse({
|
||||
exception: true,
|
||||
exceptionSeverity: 'HIGH',
|
||||
exceptionMessage: 'ERR.NOT_FOUND',
|
||||
stackTrace: 'No offers redemptions found'
|
||||
}, null);
|
||||
res.status(404).send(errorResponse);
|
||||
return;
|
||||
}
|
||||
const httpResponse = new GenericResponse(null, response);
|
||||
res.status(200).send(httpResponse);
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
@ApiOperation({ summary: 'Get an offer redemption by ID' })
|
||||
@ApiParam({ name: 'id', type: Number, description: 'Offer Redemption ID' })
|
||||
@ApiResponse({
|
||||
status: 400,
|
||||
description: 'ID parameter is missing',
|
||||
example: {
|
||||
"notification": {
|
||||
"exception": true,
|
||||
"exceptionSeverity": "HIGH",
|
||||
"exceptionMessage": "ERR.NO_ID_REQ",
|
||||
"stackTrace": "Request"
|
||||
},
|
||||
"data": null
|
||||
}
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 404,
|
||||
description: 'Offer redemption not found',
|
||||
example: {
|
||||
"notification": {
|
||||
"exception": true,
|
||||
"exceptionSeverity": "HIGH",
|
||||
"exceptionMessage": "ERR.NOT_FOUND",
|
||||
"stackTrace": "No offer redemption found matching criteria"
|
||||
},
|
||||
"data": null
|
||||
}
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 200,
|
||||
description: 'Successfully retrieved offer redemption',
|
||||
})
|
||||
async findById(@Param('id') id: number, @Res() res: Response) {
|
||||
if(!id) {
|
||||
if (!id) {
|
||||
const response = new GenericResponse({
|
||||
exception: true,
|
||||
exceptionSeverity: 'HIGH',
|
||||
exceptionMessage: 'ERR.NO_ID_REQ',
|
||||
stackTrace: 'Request'
|
||||
}, null);
|
||||
res.send(response);
|
||||
res.status(400).send(response);
|
||||
return;
|
||||
}
|
||||
const response = await this.offersRedemptionService.findByPk(id) || {};
|
||||
const httpResponse = new GenericResponse(null, response)
|
||||
res.send(httpResponse);
|
||||
const response = await this.offersRedemptionService.findByPk(id);
|
||||
if (!response) {
|
||||
const errorResponse = new GenericResponse({
|
||||
exception: true,
|
||||
exceptionSeverity: 'HIGH',
|
||||
exceptionMessage: 'ERR.NOT_FOUND',
|
||||
stackTrace: `Offer redemption with ID ${id} not found`
|
||||
}, null);
|
||||
res.status(404).send(errorResponse);
|
||||
return;
|
||||
}
|
||||
const httpResponse = new GenericResponse(null, response);
|
||||
res.status(200).send(httpResponse);
|
||||
}
|
||||
|
||||
@Post('/filter')
|
||||
@ApiOperation({ summary: 'Filter offers redemptions' })
|
||||
@ApiBody({ type: OffersRedemption })
|
||||
@ApiResponse({
|
||||
status: 404,
|
||||
description: 'Offer redemption not found',
|
||||
example: {
|
||||
"notification": {
|
||||
"exception": true,
|
||||
"exceptionSeverity": "HIGH",
|
||||
"exceptionMessage": "ERR.NOT_FOUND",
|
||||
"stackTrace": "No offer redemption found matching criteria"
|
||||
},
|
||||
"data": null
|
||||
}
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 200,
|
||||
description: 'Successfully filtered offers redemptions',
|
||||
})
|
||||
async filter(@Body() offersRedemption: OffersRedemption, @Res() res: Response) {
|
||||
if(!offersRedemption) {
|
||||
if (!offersRedemption) {
|
||||
const response = new GenericResponse({
|
||||
exception: true,
|
||||
exceptionSeverity: 'HIGH',
|
||||
exceptionMessage: 'ERR.NO_ID_REQ',
|
||||
stackTrace: 'Request'
|
||||
}, null);
|
||||
res.send(response);
|
||||
res.status(400).send(response);
|
||||
return;
|
||||
}
|
||||
const response = await this.offersRedemptionService.findOne(offersRedemption) || {};
|
||||
const httpResponse = new GenericResponse(null, response)
|
||||
res.send(httpResponse);
|
||||
const response = await this.offersRedemptionService.findOne(offersRedemption);
|
||||
if (!response) {
|
||||
const errorResponse = new GenericResponse({
|
||||
exception: true,
|
||||
exceptionSeverity: 'HIGH',
|
||||
exceptionMessage: 'ERR.NOT_FOUND',
|
||||
stackTrace: 'No offer redemption found matching criteria'
|
||||
}, null);
|
||||
res.status(404).send(errorResponse);
|
||||
return;
|
||||
}
|
||||
const httpResponse = new GenericResponse(null, response);
|
||||
res.status(200).send(httpResponse);
|
||||
}
|
||||
|
||||
@Post()
|
||||
@ApiOperation({ summary: 'Insert a new offer redemption' })
|
||||
@ApiBody({ type: OffersRedemption })
|
||||
@ApiResponse({
|
||||
status: 400,
|
||||
description: 'Failed to insert offer redemption',
|
||||
example: {
|
||||
"notification": {
|
||||
"exception": true,
|
||||
"exceptionSeverity": "HIGH",
|
||||
"exceptionMessage": "ERR.NOT_FOUND",
|
||||
"stackTrace": "Offer redemption not created"
|
||||
},
|
||||
"data": null
|
||||
}
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 201,
|
||||
description: 'Offer redemption successfully created',
|
||||
})
|
||||
async insert(@Body() offersRedemption: OffersRedemption, @Res() res: Response) {
|
||||
if(!offersRedemption) {
|
||||
if (!offersRedemption) {
|
||||
const response = new GenericResponse({
|
||||
exception: true,
|
||||
exceptionSeverity: 'HIGH',
|
||||
exceptionMessage: 'ERR.NO_ID_REQ',
|
||||
stackTrace: 'Request'
|
||||
}, null);
|
||||
res.send(response);
|
||||
res.status(400).send(response);
|
||||
return;
|
||||
}
|
||||
delete offersRedemption.id;
|
||||
const response = await this.offersRedemptionService.upsert(offersRedemption, true);
|
||||
const httpResponse = new GenericResponse(null, response)
|
||||
res.send(httpResponse);
|
||||
if (!response) {
|
||||
const errorResponse = new GenericResponse({
|
||||
exception: true,
|
||||
exceptionSeverity: 'HIGH',
|
||||
exceptionMessage: 'ERR.NOT_FOUND',
|
||||
stackTrace: 'Offer redemption not created'
|
||||
}, null);
|
||||
res.status(404).send(errorResponse);
|
||||
return;
|
||||
}
|
||||
const httpResponse = new GenericResponse(null, response);
|
||||
res.status(201).send(httpResponse);
|
||||
}
|
||||
|
||||
@Put()
|
||||
@ApiOperation({ summary: 'Update an existing offer redemption' })
|
||||
@ApiBody({ type: OffersRedemption })
|
||||
@ApiResponse({
|
||||
status: 400,
|
||||
description: 'Offer redemption not found',
|
||||
example: {
|
||||
"notification": {
|
||||
"exception": true,
|
||||
"exceptionSeverity": "HIGH",
|
||||
"exceptionMessage": "ERR.NOT_FOUND",
|
||||
"stackTrace": "Request"
|
||||
},
|
||||
"data": null
|
||||
}
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 404,
|
||||
description: 'Offer redemption not found',
|
||||
example: {
|
||||
"notification": {
|
||||
"exception": true,
|
||||
"exceptionSeverity": "HIGH",
|
||||
"exceptionMessage": "ERR.NOT_FOUND",
|
||||
"stackTrace": "Offer redemption not found"
|
||||
},
|
||||
"data": null
|
||||
}
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 200,
|
||||
description: 'Offer redemption successfully updated',
|
||||
})
|
||||
async update(@Body() offersRedemption: OffersRedemption, @Res() res: Response) {
|
||||
if(!offersRedemption || !offersRedemption.id) {
|
||||
if (!offersRedemption || !offersRedemption.id) {
|
||||
const response = new GenericResponse({
|
||||
exception: true,
|
||||
exceptionSeverity: 'HIGH',
|
||||
exceptionMessage: 'ERR.NO_ID_REQ',
|
||||
stackTrace: 'Request'
|
||||
}, null);
|
||||
res.send(response);
|
||||
res.status(400).send(response);
|
||||
return;
|
||||
}
|
||||
const response = await this.offersRedemptionService.upsert(offersRedemption, false);
|
||||
const httpResponse = new GenericResponse(null, response)
|
||||
res.send(httpResponse);
|
||||
if (!response) {
|
||||
const errorResponse = new GenericResponse({
|
||||
exception: true,
|
||||
exceptionSeverity: 'HIGH',
|
||||
exceptionMessage: 'ERR.NOT_FOUND',
|
||||
stackTrace: 'Offer redemption not found'
|
||||
}, null);
|
||||
res.status(404).send(errorResponse);
|
||||
return;
|
||||
}
|
||||
const httpResponse = new GenericResponse(null, response);
|
||||
res.status(200).send(httpResponse);
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
@ApiOperation({ summary: 'Delete an offer redemption by ID' })
|
||||
@ApiParam({ name: 'id', type: Number, description: 'Offer Redemption ID' })
|
||||
@ApiResponse({
|
||||
status: 400,
|
||||
description: 'ID parameter is missing',
|
||||
example: {
|
||||
"notification": {
|
||||
"exception": true,
|
||||
"exceptionSeverity": "HIGH",
|
||||
"exceptionMessage": "ERR.NO_ID_REQ",
|
||||
"stackTrace": "Request"
|
||||
},
|
||||
"data": null
|
||||
}
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 404,
|
||||
description: 'Offer redemption not found',
|
||||
example: {
|
||||
"notification": {
|
||||
"exception": true,
|
||||
"exceptionSeverity": "HIGH",
|
||||
"exceptionMessage": "ERR.NOT_FOUND",
|
||||
"stackTrace": "Offer redemption not found"
|
||||
},
|
||||
"data": null
|
||||
}
|
||||
})
|
||||
@ApiResponse({ status: 200, description: 'Offer redemption successfully deleted' })
|
||||
async deleteById(@Param('id') id: number, @Res() res: Response) {
|
||||
if(!id) {
|
||||
if (!id) {
|
||||
const response = new GenericResponse({
|
||||
exception: true,
|
||||
exceptionSeverity: 'HIGH',
|
||||
exceptionMessage: 'ERR.NO_ID_REQ',
|
||||
stackTrace: 'Request'
|
||||
}, null);
|
||||
res.send(response);
|
||||
res.status(400).send(response);
|
||||
return;
|
||||
}
|
||||
const response = await this.offersRedemptionService.remove(id) || {};
|
||||
const httpResponse = new GenericResponse(null, response)
|
||||
res.send(httpResponse);
|
||||
const response = await this.offersRedemptionService.remove(id);
|
||||
if (!response) {
|
||||
const errorResponse = new GenericResponse({
|
||||
exception: true,
|
||||
exceptionSeverity: 'HIGH',
|
||||
exceptionMessage: 'ERR.NOT_FOUND',
|
||||
stackTrace: `Offer redemption with ID ${id} not found`
|
||||
}, null);
|
||||
res.status(404).send(errorResponse);
|
||||
return;
|
||||
}
|
||||
const httpResponse = new GenericResponse(null, response);
|
||||
res.status(200).send(httpResponse);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,103 +1,311 @@
|
||||
import { Body, Controller, Delete, Get, Param, Post, Put, Res } from '@nestjs/common';
|
||||
import { OfferService } from './offers.service';
|
||||
import { Response } from 'express';
|
||||
import { OfferService } from './offers.service';
|
||||
import { GenericResponse } from 'src/common/GenericResponse.model';
|
||||
import Offer from './offers.entity';
|
||||
import { ApiTags, ApiOperation, ApiResponse, ApiParam, ApiBody } from '@nestjs/swagger';
|
||||
|
||||
@ApiTags('offers')
|
||||
@Controller('offers')
|
||||
export class OfferController {
|
||||
constructor(private offersService: OfferService) {}
|
||||
|
||||
@Get("/all")
|
||||
@ApiOperation({ summary: 'Get all offers' })
|
||||
@ApiResponse({ status: 200, description: 'Successfully retrieved all offers' })
|
||||
@ApiResponse({
|
||||
status: 404,
|
||||
description: 'No offers found',
|
||||
example: {
|
||||
"notification": {
|
||||
"exception": true,
|
||||
"exceptionSeverity": "HIGH",
|
||||
"exceptionMessage": "ERR.NOT_FOUND",
|
||||
"stackTrace": "No offers found"
|
||||
},
|
||||
"data": null
|
||||
}
|
||||
})
|
||||
async getAllOffers(@Res() res: Response) {
|
||||
const response = await this.offersService.findAll() || [];
|
||||
const httpResponse = new GenericResponse(null, response)
|
||||
res.send(httpResponse);
|
||||
if (!response) {
|
||||
const errorResponse = new GenericResponse({
|
||||
exception: true,
|
||||
exceptionSeverity: 'HIGH',
|
||||
exceptionMessage: 'ERR.NOT_FOUND',
|
||||
stackTrace: 'No offers found'
|
||||
}, null);
|
||||
res.status(404).send(errorResponse);
|
||||
return;
|
||||
}
|
||||
const httpResponse = new GenericResponse(null, response);
|
||||
res.status(200).send(httpResponse);
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
@ApiOperation({ summary: 'Get an offer by ID' })
|
||||
@ApiParam({ name: 'id', type: Number, description: 'Offer ID' })
|
||||
@ApiResponse({
|
||||
status: 400,
|
||||
description: 'ID parameter is missing',
|
||||
example: {
|
||||
"notification": {
|
||||
"exception": true,
|
||||
"exceptionSeverity": "HIGH",
|
||||
"exceptionMessage": "ERR.NO_ID_REQ",
|
||||
"stackTrace": "Request"
|
||||
},
|
||||
"data": null
|
||||
}
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 404,
|
||||
description: 'Offer not found',
|
||||
example: {
|
||||
"notification": {
|
||||
"exception": true,
|
||||
"exceptionSeverity": "HIGH",
|
||||
"exceptionMessage": "ERR.NOT_FOUND",
|
||||
"stackTrace": "Offer not found"
|
||||
},
|
||||
"data": null
|
||||
}
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 200,
|
||||
description: 'Successfully retrieved offer',
|
||||
})
|
||||
async findById(@Param('id') id: number, @Res() res: Response) {
|
||||
if(!id) {
|
||||
if (!id) {
|
||||
const response = new GenericResponse({
|
||||
exception: true,
|
||||
exceptionSeverity: 'HIGH',
|
||||
exceptionMessage: 'ERR.NO_ID_REQ',
|
||||
stackTrace: 'Request'
|
||||
}, null);
|
||||
res.send(response);
|
||||
res.status(400).send(response);
|
||||
return;
|
||||
}
|
||||
const response = await this.offersService.findByPk(id) || {};
|
||||
const httpResponse = new GenericResponse(null, response)
|
||||
res.send(httpResponse);
|
||||
const response = await this.offersService.findByPk(id);
|
||||
if (!response) {
|
||||
const errorResponse = new GenericResponse({
|
||||
exception: true,
|
||||
exceptionSeverity: 'HIGH',
|
||||
exceptionMessage: 'ERR.NOT_FOUND',
|
||||
stackTrace: `Offer with ID ${id} not found`
|
||||
}, null);
|
||||
res.status(404).send(errorResponse);
|
||||
return;
|
||||
}
|
||||
const httpResponse = new GenericResponse(null, response);
|
||||
res.status(200).send(httpResponse);
|
||||
}
|
||||
|
||||
@Post('/filter')
|
||||
@ApiOperation({ summary: 'Filter offers' })
|
||||
@ApiBody({ type: Offer })
|
||||
@ApiResponse({
|
||||
status: 404,
|
||||
description: 'No offers found matching criteria',
|
||||
example: {
|
||||
"notification": {
|
||||
"exception": true,
|
||||
"exceptionSeverity": "HIGH",
|
||||
"exceptionMessage": "ERR.NOT_FOUND",
|
||||
"stackTrace": "No offers found matching criteria"
|
||||
},
|
||||
"data": null
|
||||
}
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 200,
|
||||
description: 'Successfully filtered offers',
|
||||
})
|
||||
async filter(@Body() offers: Offer, @Res() res: Response) {
|
||||
if(!offers) {
|
||||
if (!offers) {
|
||||
const response = new GenericResponse({
|
||||
exception: true,
|
||||
exceptionSeverity: 'HIGH',
|
||||
exceptionMessage: 'ERR.NO_ID_REQ',
|
||||
stackTrace: 'Request'
|
||||
}, null);
|
||||
res.send(response);
|
||||
res.status(400).send(response);
|
||||
return;
|
||||
}
|
||||
const response = await this.offersService.filter(offers) || {};
|
||||
const httpResponse = new GenericResponse(null, response)
|
||||
res.send(httpResponse);
|
||||
const response = await this.offersService.filter(offers);
|
||||
if (!response) {
|
||||
const errorResponse = new GenericResponse({
|
||||
exception: true,
|
||||
exceptionSeverity: 'HIGH',
|
||||
exceptionMessage: 'ERR.NOT_FOUND',
|
||||
stackTrace: 'No offers found matching criteria'
|
||||
}, null);
|
||||
res.status(404).send(errorResponse);
|
||||
return;
|
||||
}
|
||||
const httpResponse = new GenericResponse(null, response);
|
||||
res.status(200).send(httpResponse);
|
||||
}
|
||||
|
||||
@Post()
|
||||
@ApiOperation({ summary: 'Create a new offer' })
|
||||
@ApiBody({ type: Offer })
|
||||
@ApiResponse({
|
||||
status: 400,
|
||||
description: 'Failed to create offer',
|
||||
example: {
|
||||
"notification": {
|
||||
"exception": true,
|
||||
"exceptionSeverity": "HIGH",
|
||||
"exceptionMessage": "ERR.NOT_FOUND",
|
||||
"stackTrace": "Offer not created"
|
||||
},
|
||||
"data": null
|
||||
}
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 201,
|
||||
description: 'Offer successfully created',
|
||||
})
|
||||
async insert(@Body() offers: Offer, @Res() res: Response) {
|
||||
if(!offers) {
|
||||
if (!offers) {
|
||||
const response = new GenericResponse({
|
||||
exception: true,
|
||||
exceptionSeverity: 'HIGH',
|
||||
exceptionMessage: 'ERR.NO_ID_REQ',
|
||||
stackTrace: 'Request'
|
||||
}, null);
|
||||
res.send(response);
|
||||
res.status(400).send(response);
|
||||
return;
|
||||
}
|
||||
delete offers.id;
|
||||
const response = await this.offersService.upsert(offers, true);
|
||||
const httpResponse = new GenericResponse(null, response)
|
||||
res.send(httpResponse);
|
||||
if (!response) {
|
||||
const errorResponse = new GenericResponse({
|
||||
exception: true,
|
||||
exceptionSeverity: 'HIGH',
|
||||
exceptionMessage: 'ERR.NOT_FOUND',
|
||||
stackTrace: 'Offer not created'
|
||||
}, null);
|
||||
res.status(404).send(errorResponse);
|
||||
return;
|
||||
}
|
||||
const httpResponse = new GenericResponse(null, response);
|
||||
res.status(201).send(httpResponse);
|
||||
}
|
||||
|
||||
@Put()
|
||||
@ApiOperation({ summary: 'Update an existing offer' })
|
||||
@ApiBody({ type: Offer })
|
||||
@ApiResponse({
|
||||
status: 400,
|
||||
description: 'Offer not found',
|
||||
example: {
|
||||
"notification": {
|
||||
"exception": true,
|
||||
"exceptionSeverity": "HIGH",
|
||||
"exceptionMessage": "ERR.NOT_FOUND",
|
||||
"stackTrace": "Request"
|
||||
},
|
||||
"data": null
|
||||
}
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 404,
|
||||
description: 'Offer not found',
|
||||
example: {
|
||||
"notification": {
|
||||
"exception": true,
|
||||
"exceptionSeverity": "HIGH",
|
||||
"exceptionMessage": "ERR.NOT_FOUND",
|
||||
"stackTrace": "Offer not found"
|
||||
},
|
||||
"data": null
|
||||
}
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 200,
|
||||
description: 'Offer successfully updated',
|
||||
})
|
||||
async update(@Body() offers: Offer, @Res() res: Response) {
|
||||
if(!Offer || !offers.id) {
|
||||
if (!offers || !offers.id) {
|
||||
const response = new GenericResponse({
|
||||
exception: true,
|
||||
exceptionSeverity: 'HIGH',
|
||||
exceptionMessage: 'ERR.NO_ID_REQ',
|
||||
stackTrace: 'Request'
|
||||
}, null);
|
||||
res.send(response);
|
||||
res.status(400).send(response);
|
||||
return;
|
||||
}
|
||||
const response = await this.offersService.upsert(offers, false);
|
||||
const httpResponse = new GenericResponse(null, response)
|
||||
res.send(httpResponse);
|
||||
if (!response) {
|
||||
const errorResponse = new GenericResponse({
|
||||
exception: true,
|
||||
exceptionSeverity: 'HIGH',
|
||||
exceptionMessage: 'ERR.NOT_FOUND',
|
||||
stackTrace: 'Offer not found'
|
||||
}, null);
|
||||
res.status(404).send(errorResponse);
|
||||
return;
|
||||
}
|
||||
const httpResponse = new GenericResponse(null, response);
|
||||
res.status(200).send(httpResponse);
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
@ApiOperation({ summary: 'Delete an offer by ID' })
|
||||
@ApiParam({ name: 'id', type: Number, description: 'Offer ID' })
|
||||
@ApiResponse({
|
||||
status: 400,
|
||||
description: 'ID parameter is missing',
|
||||
example: {
|
||||
"notification": {
|
||||
"exception": true,
|
||||
"exceptionSeverity": "HIGH",
|
||||
"exceptionMessage": "ERR.NO_ID_REQ",
|
||||
"stackTrace": "Request"
|
||||
},
|
||||
"data": null
|
||||
}
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 404,
|
||||
description: 'Offer not found',
|
||||
example: {
|
||||
"notification": {
|
||||
"exception": true,
|
||||
"exceptionSeverity": "HIGH",
|
||||
"exceptionMessage": "ERR.NOT_FOUND",
|
||||
"stackTrace": "Offer not found"
|
||||
},
|
||||
"data": null
|
||||
}
|
||||
})
|
||||
@ApiResponse({ status: 200, description: 'Offer successfully deleted' })
|
||||
async deleteById(@Param('id') id: number, @Res() res: Response) {
|
||||
if(!id) {
|
||||
if (!id) {
|
||||
const response = new GenericResponse({
|
||||
exception: true,
|
||||
exceptionSeverity: 'HIGH',
|
||||
exceptionMessage: 'ERR.NO_ID_REQ',
|
||||
stackTrace: 'Request'
|
||||
}, null);
|
||||
res.send(response);
|
||||
res.status(400).send(response);
|
||||
return;
|
||||
}
|
||||
const response = await this.offersService.remove(id) || {};
|
||||
const httpResponse = new GenericResponse(null, response)
|
||||
res.send(httpResponse);
|
||||
const response = await this.offersService.remove(id);
|
||||
if (!response) {
|
||||
const errorResponse = new GenericResponse({
|
||||
exception: true,
|
||||
exceptionSeverity: 'HIGH',
|
||||
exceptionMessage: 'ERR.NOT_FOUND',
|
||||
stackTrace: `Offer with ID ${id} not found`
|
||||
}, null);
|
||||
res.status(404).send(errorResponse);
|
||||
return;
|
||||
}
|
||||
const httpResponse = new GenericResponse(null, response);
|
||||
res.status(200).send(httpResponse);
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,20 +2,60 @@ import { Body, Controller, Delete, Get, Param, Post, Put, Res } from '@nestjs/co
|
||||
import { PaymentService } from './payment.service';
|
||||
import { Response } from 'express';
|
||||
import { GenericResponse } from '../common/GenericResponse.model';
|
||||
import Payment from './payment.entity';
|
||||
import Payment from './payment.entity';
|
||||
import { ApiTags, ApiOperation, ApiResponse, ApiParam, ApiBody } from '@nestjs/swagger';
|
||||
|
||||
@ApiTags('payments')
|
||||
@Controller('payments')
|
||||
export class PaymentController {
|
||||
constructor(private paymentService: PaymentService) { }
|
||||
|
||||
@Get("/all")
|
||||
@ApiOperation({ summary: 'Get all payments' })
|
||||
@ApiResponse({
|
||||
status: 200,
|
||||
description: 'Successfully retrieved all payments',
|
||||
})
|
||||
async getAllPayments(@Res() res: Response) {
|
||||
const response = await this.paymentService.findAll() || [];
|
||||
const httpResponse = new GenericResponse(null, response)
|
||||
res.send(httpResponse);
|
||||
const httpResponse = new GenericResponse(null, response);
|
||||
res.status(200).send(httpResponse);
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
@ApiOperation({ summary: 'Get a payment by ID' })
|
||||
@ApiParam({ name: 'id', type: Number, description: 'Payment ID' })
|
||||
@ApiResponse({
|
||||
status: 400,
|
||||
description: 'Payment not found',
|
||||
example: {
|
||||
"notification": {
|
||||
"exception": true,
|
||||
"exceptionSeverity": "HIGH",
|
||||
"exceptionMessage": "ERR.NOT_FOUND",
|
||||
"stackTrace": "Request"
|
||||
},
|
||||
"data": null
|
||||
}
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 404,
|
||||
description: 'Payment not found',
|
||||
example: {
|
||||
"notification": {
|
||||
"exception": true,
|
||||
"exceptionSeverity": "HIGH",
|
||||
"exceptionMessage": "ERR.NOT_FOUND",
|
||||
"stackTrace": "No payments found matching criteria"
|
||||
},
|
||||
"data": null
|
||||
}
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 200,
|
||||
description: 'Successfully retrieved payment',
|
||||
|
||||
})
|
||||
async findById(@Param('id') id: number, @Res() res: Response) {
|
||||
if (!id) {
|
||||
const response = new GenericResponse({
|
||||
@ -24,15 +64,58 @@ export class PaymentController {
|
||||
exceptionMessage: 'ERR.NO_ID_REQ',
|
||||
stackTrace: 'Request'
|
||||
}, null);
|
||||
res.send(response);
|
||||
res.status(400).send(response);
|
||||
return;
|
||||
}
|
||||
const response = await this.paymentService.findByPk(id) || {};
|
||||
const httpResponse = new GenericResponse(null, response)
|
||||
res.send(httpResponse);
|
||||
const response = await this.paymentService.findByPk(id);
|
||||
if (!response) {
|
||||
const errorResponse = new GenericResponse({
|
||||
exception: true,
|
||||
exceptionSeverity: 'HIGH',
|
||||
exceptionMessage: 'ERR.NOT_FOUND',
|
||||
stackTrace: `Payment with ID ${id} not found`
|
||||
}, null);
|
||||
res.status(404).send(errorResponse);
|
||||
return;
|
||||
}
|
||||
const httpResponse = new GenericResponse(null, response);
|
||||
res.status(200).send(httpResponse);
|
||||
}
|
||||
|
||||
@Post('/filter')
|
||||
@ApiOperation({ summary: 'Filter payments' })
|
||||
@ApiBody({ type: Payment })
|
||||
@ApiResponse({
|
||||
status: 400,
|
||||
description: 'Payment not found',
|
||||
example: {
|
||||
"notification": {
|
||||
"exception": true,
|
||||
"exceptionSeverity": "HIGH",
|
||||
"exceptionMessage": "ERR.NOT_FOUND",
|
||||
"stackTrace": "Request"
|
||||
},
|
||||
"data": null
|
||||
}
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 404,
|
||||
description: 'Payment not found',
|
||||
example: {
|
||||
"notification": {
|
||||
"exception": true,
|
||||
"exceptionSeverity": "HIGH",
|
||||
"exceptionMessage": "ERR.NOT_FOUND",
|
||||
"stackTrace": "No payments found matching criteria"
|
||||
},
|
||||
"data": null
|
||||
}
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 200,
|
||||
description: 'Successfully filtered payments',
|
||||
|
||||
})
|
||||
async filter(@Body() payment: Payment, @Res() res: Response) {
|
||||
if (!payment) {
|
||||
const response = new GenericResponse({
|
||||
@ -41,15 +124,63 @@ export class PaymentController {
|
||||
exceptionMessage: 'ERR.NO_ID_REQ',
|
||||
stackTrace: 'Request'
|
||||
}, null);
|
||||
res.send(response);
|
||||
res.status(400).send(response);
|
||||
return;
|
||||
}
|
||||
const response = await this.paymentService.filter(payment) || [];
|
||||
const httpResponse = new GenericResponse(null, response)
|
||||
const response = await this.paymentService.filter(payment);
|
||||
if (response && response.length === 0) {
|
||||
const successResponse = new GenericResponse(null, []);
|
||||
res.status(200).send(successResponse);
|
||||
return;
|
||||
}
|
||||
if (!response) {
|
||||
const errorResponse = new GenericResponse({
|
||||
exception: true,
|
||||
exceptionSeverity: 'HIGH',
|
||||
exceptionMessage: 'ERR.NOT_FOUND',
|
||||
stackTrace: `No payments found matching criteria`
|
||||
}, null);
|
||||
res.status(404).send(errorResponse);
|
||||
return;
|
||||
}
|
||||
const httpResponse = new GenericResponse(null, response);
|
||||
res.status(200).send(httpResponse);
|
||||
}
|
||||
|
||||
@Post()
|
||||
@ApiOperation({ summary: 'Insert a new payment' })
|
||||
@ApiBody({ type: Payment })
|
||||
@ApiResponse({
|
||||
status: 400,
|
||||
description: 'Payment not found',
|
||||
example: {
|
||||
"notification": {
|
||||
"exception": true,
|
||||
"exceptionSeverity": "HIGH",
|
||||
"exceptionMessage": "ERR.NOT_FOUND",
|
||||
"stackTrace": "Request"
|
||||
},
|
||||
"data": null
|
||||
}
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 404,
|
||||
description: 'Payment not found',
|
||||
example: {
|
||||
"notification": {
|
||||
"exception": true,
|
||||
"exceptionSeverity": "HIGH",
|
||||
"exceptionMessage": "ERR.NOT_FOUND",
|
||||
"stackTrace": "Payment not found"
|
||||
},
|
||||
"data": null
|
||||
}
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 201,
|
||||
description: 'Payment successfully created',
|
||||
|
||||
})
|
||||
async insert(@Body() payment: Payment, @Res() res: Response) {
|
||||
if (!payment) {
|
||||
const response = new GenericResponse({
|
||||
@ -58,16 +189,59 @@ export class PaymentController {
|
||||
exceptionMessage: 'ERR.NO_ID_REQ',
|
||||
stackTrace: 'Request'
|
||||
}, null);
|
||||
res.send(response);
|
||||
res.status(400).send(response);
|
||||
return;
|
||||
}
|
||||
delete payment.id;
|
||||
const response = await this.paymentService.upsert(payment, true);
|
||||
const httpResponse = new GenericResponse(null, response)
|
||||
res.send(httpResponse);
|
||||
if (!response) {
|
||||
const errorResponse = new GenericResponse({
|
||||
exception: true,
|
||||
exceptionSeverity: 'HIGH',
|
||||
exceptionMessage: 'ERR.NOT_FOUND',
|
||||
stackTrace: `Payment not found`
|
||||
}, null);
|
||||
res.status(404).send(errorResponse);
|
||||
return;
|
||||
}
|
||||
const httpResponse = new GenericResponse(null, response);
|
||||
res.status(201).send(httpResponse);
|
||||
}
|
||||
|
||||
@Put()
|
||||
@ApiOperation({ summary: 'Update an existing payment' })
|
||||
@ApiBody({ type: Payment })
|
||||
@ApiResponse({
|
||||
status: 400,
|
||||
description: 'Payment not found',
|
||||
example: {
|
||||
"notification": {
|
||||
"exception": true,
|
||||
"exceptionSeverity": "HIGH",
|
||||
"exceptionMessage": "ERR.NOT_FOUND",
|
||||
"stackTrace": "Request"
|
||||
},
|
||||
"data": null
|
||||
}
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 404,
|
||||
description: 'Payment not found',
|
||||
example: {
|
||||
"notification": {
|
||||
"exception": true,
|
||||
"exceptionSeverity": "HIGH",
|
||||
"exceptionMessage": "ERR.NOT_FOUND",
|
||||
"stackTrace": "Payment not found"
|
||||
},
|
||||
"data": null
|
||||
}
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 200,
|
||||
description: 'Payment successfully updated',
|
||||
|
||||
})
|
||||
async update(@Body() payment: Payment, @Res() res: Response) {
|
||||
if (!payment || !payment.id) {
|
||||
const response = new GenericResponse({
|
||||
@ -76,15 +250,54 @@ export class PaymentController {
|
||||
exceptionMessage: 'ERR.NO_ID_REQ',
|
||||
stackTrace: 'Request'
|
||||
}, null);
|
||||
res.send(response);
|
||||
res.status(400).send(response);
|
||||
return;
|
||||
}
|
||||
const response = await this.paymentService.upsert(payment, false);
|
||||
const httpResponse = new GenericResponse(null, response)
|
||||
res.send(httpResponse);
|
||||
if (!response) {
|
||||
const errorResponse = new GenericResponse({
|
||||
exception: true,
|
||||
exceptionSeverity: 'HIGH',
|
||||
exceptionMessage: 'ERR.NOT_FOUND',
|
||||
stackTrace: `Payment not found`
|
||||
}, null);
|
||||
res.status(404).send(errorResponse);
|
||||
return;
|
||||
}
|
||||
const httpResponse = new GenericResponse(null, response);
|
||||
res.status(200).send(httpResponse);
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
@ApiOperation({ summary: 'Delete a payment by ID' })
|
||||
@ApiParam({ name: 'id', type: Number, description: 'Payment ID' })
|
||||
@ApiResponse({
|
||||
status: 400,
|
||||
description: 'Payment not found',
|
||||
example: {
|
||||
"notification": {
|
||||
"exception": true,
|
||||
"exceptionSeverity": "HIGH",
|
||||
"exceptionMessage": "ERR.NOT_FOUND",
|
||||
"stackTrace": "Request"
|
||||
},
|
||||
"data": null
|
||||
}
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 404,
|
||||
description: 'Payment not found',
|
||||
example: {
|
||||
"notification": {
|
||||
"exception": true,
|
||||
"exceptionSeverity": "HIGH",
|
||||
"exceptionMessage": "ERR.NOT_FOUND",
|
||||
"stackTrace": "Payment with ID 1 not found"
|
||||
},
|
||||
"data": null
|
||||
}
|
||||
})
|
||||
@ApiResponse({ status: 200, description: 'Payment successfully deleted' })
|
||||
async deleteById(@Param('id') id: number, @Res() res: Response) {
|
||||
if (!id) {
|
||||
const response = new GenericResponse({
|
||||
@ -93,13 +306,21 @@ export class PaymentController {
|
||||
exceptionMessage: 'ERR.NO_ID_REQ',
|
||||
stackTrace: 'Request'
|
||||
}, null);
|
||||
res.send(response);
|
||||
res.status(400).send(response);
|
||||
return;
|
||||
}
|
||||
const response = await this.paymentService.remove(id) || {};
|
||||
const httpResponse = new GenericResponse(null, response)
|
||||
res.send(httpResponse);
|
||||
const response = await this.paymentService.remove(id);
|
||||
if (!response) {
|
||||
const errorResponse = new GenericResponse({
|
||||
exception: true,
|
||||
exceptionSeverity: 'HIGH',
|
||||
exceptionMessage: 'ERR.NOT_FOUND',
|
||||
stackTrace: `Payment with ID ${id} not found`
|
||||
}, null);
|
||||
res.status(404).send(errorResponse);
|
||||
return;
|
||||
}
|
||||
const httpResponse = new GenericResponse(null, response);
|
||||
res.status(200).send(httpResponse);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -3,101 +3,309 @@ import { Response } from 'express';
|
||||
import { GenericResponse } from 'src/common/GenericResponse.model';
|
||||
import { PlanUsageService } from './plan-usage.service';
|
||||
import PlanUsage from './plan-usage.entity';
|
||||
import { ApiTags, ApiOperation, ApiResponse, ApiParam, ApiBody } from '@nestjs/swagger';
|
||||
|
||||
@ApiTags('plan-usage')
|
||||
@Controller('plans-usage')
|
||||
export class PlanUsageController {
|
||||
constructor(private itemsService: PlanUsageService) {}
|
||||
constructor(private itemsService: PlanUsageService) { }
|
||||
|
||||
@Get("/all")
|
||||
@ApiOperation({ summary: 'Get all plan usage' })
|
||||
@ApiResponse({ status: 200, description: 'Successfully retrieved all plan usage' })
|
||||
async getAll(@Res() res: Response) {
|
||||
const response = await this.itemsService.findAll() || [];
|
||||
const httpResponse = new GenericResponse(null, response)
|
||||
res.send(httpResponse);
|
||||
const response = await this.itemsService.findAll();
|
||||
if (!response) {
|
||||
const errorResponse = new GenericResponse({
|
||||
exception: true,
|
||||
exceptionSeverity: 'HIGH',
|
||||
exceptionMessage: 'ERR.NOT_FOUND',
|
||||
stackTrace: 'No plan usage found'
|
||||
}, null);
|
||||
res.status(404).send(errorResponse);
|
||||
return;
|
||||
}
|
||||
const httpResponse = new GenericResponse(null, response);
|
||||
res.status(200).send(httpResponse);
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
@ApiOperation({ summary: 'Get a plan usage by ID' })
|
||||
@ApiParam({ name: 'id', type: Number, description: 'Plan Usage ID' })
|
||||
@ApiResponse({
|
||||
status: 400,
|
||||
description: 'ID parameter is missing',
|
||||
example: {
|
||||
"notification": {
|
||||
"exception": true,
|
||||
"exceptionSeverity": "HIGH",
|
||||
"exceptionMessage": "ERR.NO_ID_REQ",
|
||||
"stackTrace": "Request"
|
||||
},
|
||||
"data": null
|
||||
}
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 404,
|
||||
description: 'Plan usage not found',
|
||||
example: {
|
||||
"notification": {
|
||||
"exception": true,
|
||||
"exceptionSeverity": "HIGH",
|
||||
"exceptionMessage": "ERR.NOT_FOUND",
|
||||
"stackTrace": "No plan usage found matching criteria"
|
||||
},
|
||||
"data": null
|
||||
}
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 200,
|
||||
description: 'Successfully retrieved plan usage',
|
||||
})
|
||||
async findById(@Param('id') id: number, @Res() res: Response) {
|
||||
if(!id) {
|
||||
if (!id) {
|
||||
const response = new GenericResponse({
|
||||
exception: true,
|
||||
exceptionSeverity: 'HIGH',
|
||||
exceptionMessage: 'ERR.NO_ID_REQ',
|
||||
stackTrace: 'Request'
|
||||
}, null);
|
||||
res.send(response);
|
||||
res.status(400).send(response);
|
||||
return;
|
||||
}
|
||||
const response = await this.itemsService.findByPk(id) || {};
|
||||
const httpResponse = new GenericResponse(null, response)
|
||||
res.send(httpResponse);
|
||||
const response = await this.itemsService.findByPk(id);
|
||||
if (!response) {
|
||||
const errorResponse = new GenericResponse({
|
||||
exception: true,
|
||||
exceptionSeverity: 'HIGH',
|
||||
exceptionMessage: 'ERR.NOT_FOUND',
|
||||
stackTrace: `Plan usage with ID ${id} not found`
|
||||
}, null);
|
||||
res.status(404).send(errorResponse);
|
||||
return;
|
||||
}
|
||||
const httpResponse = new GenericResponse(null, response);
|
||||
res.status(200).send(httpResponse);
|
||||
}
|
||||
|
||||
@Post('/filter')
|
||||
@ApiOperation({ summary: 'Filter plan usage' })
|
||||
@ApiBody({ type: PlanUsage })
|
||||
@ApiResponse({
|
||||
status: 400,
|
||||
description: 'Plan usage not found',
|
||||
example: {
|
||||
"notification": {
|
||||
"exception": true,
|
||||
"exceptionSeverity": "HIGH",
|
||||
"exceptionMessage": "ERR.NOT_FOUND",
|
||||
"stackTrace": "Request"
|
||||
},
|
||||
"data": null
|
||||
}
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 404,
|
||||
description: 'Plan usage not found',
|
||||
example: {
|
||||
"notification": {
|
||||
"exception": true,
|
||||
"exceptionSeverity": "HIGH",
|
||||
"exceptionMessage": "ERR.NOT_FOUND",
|
||||
"stackTrace": "No plan usage found matching criteria"
|
||||
},
|
||||
"data": null
|
||||
}
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 200,
|
||||
description: 'Successfully filtered plan usage',
|
||||
})
|
||||
async filter(@Body() item: PlanUsage, @Res() res: Response) {
|
||||
if(!item) {
|
||||
if (!item) {
|
||||
const response = new GenericResponse({
|
||||
exception: true,
|
||||
exceptionSeverity: 'HIGH',
|
||||
exceptionMessage: 'ERR.NO_ID_REQ',
|
||||
stackTrace: 'Request'
|
||||
}, null);
|
||||
res.send(response);
|
||||
res.status(400).send(response);
|
||||
return;
|
||||
}
|
||||
const response = await this.itemsService.filter(item) || {};
|
||||
const httpResponse = new GenericResponse(null, response)
|
||||
res.send(httpResponse);
|
||||
const response = await this.itemsService.filter(item);
|
||||
if (!response) {
|
||||
const errorResponse = new GenericResponse({
|
||||
exception: true,
|
||||
exceptionSeverity: 'HIGH',
|
||||
exceptionMessage: 'ERR.NOT_FOUND',
|
||||
stackTrace: 'No plan usage found matching criteria'
|
||||
}, null);
|
||||
res.status(404).send(errorResponse);
|
||||
return;
|
||||
}
|
||||
const httpResponse = new GenericResponse(null, response);
|
||||
res.status(200).send(httpResponse);
|
||||
}
|
||||
|
||||
@Post()
|
||||
@ApiOperation({ summary: 'Insert a new plan usage' })
|
||||
@ApiBody({ type: PlanUsage })
|
||||
@ApiResponse({
|
||||
status: 400,
|
||||
description: 'Plan usage not found',
|
||||
example: {
|
||||
"notification": {
|
||||
"exception": true,
|
||||
"exceptionSeverity": "HIGH",
|
||||
"exceptionMessage": "ERR.NOT_FOUND",
|
||||
"stackTrace": "Request"
|
||||
},
|
||||
"data": null
|
||||
}
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 201,
|
||||
description: 'Plan usage successfully created',
|
||||
})
|
||||
async insert(@Body() item: PlanUsage, @Res() res: Response) {
|
||||
if(!item) {
|
||||
if (!item) {
|
||||
const response = new GenericResponse({
|
||||
exception: true,
|
||||
exceptionSeverity: 'HIGH',
|
||||
exceptionMessage: 'ERR.NO_ID_REQ',
|
||||
stackTrace: 'Request'
|
||||
}, null);
|
||||
res.send(response);
|
||||
res.status(400).send(response);
|
||||
return;
|
||||
}
|
||||
delete item.id;
|
||||
const response = await this.itemsService.upsert(item, true);
|
||||
const httpResponse = new GenericResponse(null, response)
|
||||
res.send(httpResponse);
|
||||
if (!response) {
|
||||
const errorResponse = new GenericResponse({
|
||||
exception: true,
|
||||
exceptionSeverity: 'HIGH',
|
||||
exceptionMessage: 'ERR.NOT_FOUND',
|
||||
stackTrace: 'Plan usage not created'
|
||||
}, null);
|
||||
res.status(404).send(errorResponse);
|
||||
return;
|
||||
}
|
||||
const httpResponse = new GenericResponse(null, response);
|
||||
res.status(201).send(httpResponse);
|
||||
}
|
||||
|
||||
@Put()
|
||||
@ApiOperation({ summary: 'Update an existing plan usage' })
|
||||
@ApiBody({ type: PlanUsage })
|
||||
@ApiResponse({
|
||||
status: 400,
|
||||
description: 'Plan usage not found',
|
||||
example: {
|
||||
"notification": {
|
||||
"exception": true,
|
||||
"exceptionSeverity": "HIGH",
|
||||
"exceptionMessage": "ERR.NOT_FOUND",
|
||||
"stackTrace": "Request"
|
||||
},
|
||||
"data": null
|
||||
}
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 404,
|
||||
description: 'Plan usage not found',
|
||||
example: {
|
||||
"notification": {
|
||||
"exception": true,
|
||||
"exceptionSeverity": "HIGH",
|
||||
"exceptionMessage": "ERR.NOT_FOUND",
|
||||
"stackTrace": "Plan usage not found"
|
||||
},
|
||||
"data": null
|
||||
}
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 200,
|
||||
description: 'Plan usage successfully updated',
|
||||
})
|
||||
async update(@Body() item: PlanUsage, @Res() res: Response) {
|
||||
if(!item || !item.id) {
|
||||
if (!item || !item.id) {
|
||||
const response = new GenericResponse({
|
||||
exception: true,
|
||||
exceptionSeverity: 'HIGH',
|
||||
exceptionMessage: 'ERR.NO_ID_REQ',
|
||||
stackTrace: 'Request'
|
||||
}, null);
|
||||
res.send(response);
|
||||
res.status(400).send(response);
|
||||
return;
|
||||
}
|
||||
const response = await this.itemsService.upsert(item, false);
|
||||
const httpResponse = new GenericResponse(null, response)
|
||||
res.send(httpResponse);
|
||||
if (!response) {
|
||||
const errorResponse = new GenericResponse({
|
||||
exception: true,
|
||||
exceptionSeverity: 'HIGH',
|
||||
exceptionMessage: 'ERR.NOT_FOUND',
|
||||
stackTrace: 'Plan usage not found'
|
||||
}, null);
|
||||
res.status(404).send(errorResponse);
|
||||
return;
|
||||
}
|
||||
const httpResponse = new GenericResponse(null, response);
|
||||
res.status(200).send(httpResponse);
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
@ApiOperation({ summary: 'Delete a plan usage by ID' })
|
||||
@ApiParam({ name: 'id', type: Number, description: 'Plan Usage ID' })
|
||||
@ApiResponse({
|
||||
status: 400,
|
||||
description: 'ID parameter is missing',
|
||||
example: {
|
||||
"notification": {
|
||||
"exception": true,
|
||||
"exceptionSeverity": "HIGH",
|
||||
"exceptionMessage": "ERR.NO_ID_REQ",
|
||||
"stackTrace": "Request"
|
||||
},
|
||||
"data": null
|
||||
}
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 404,
|
||||
description: 'Plan usage not found',
|
||||
example: {
|
||||
"notification": {
|
||||
"exception": true,
|
||||
"exceptionSeverity": "HIGH",
|
||||
"exceptionMessage": "ERR.NOT_FOUND",
|
||||
"stackTrace": "Plan usage not found"
|
||||
},
|
||||
"data": null
|
||||
}
|
||||
})
|
||||
@ApiResponse({ status: 200, description: 'Plan usage successfully deleted' })
|
||||
async deleteById(@Param('id') id: number, @Res() res: Response) {
|
||||
if(!id) {
|
||||
if (!id) {
|
||||
const response = new GenericResponse({
|
||||
exception: true,
|
||||
exceptionSeverity: 'HIGH',
|
||||
exceptionMessage: 'ERR.NO_ID_REQ',
|
||||
stackTrace: 'Request'
|
||||
}, null);
|
||||
res.send(response);
|
||||
res.status(400).send(response);
|
||||
return;
|
||||
}
|
||||
const response = await this.itemsService.remove(id) || {};
|
||||
const httpResponse = new GenericResponse(null, response)
|
||||
res.send(httpResponse);
|
||||
const response = await this.itemsService.remove(id);
|
||||
if (!response) {
|
||||
const errorResponse = new GenericResponse({
|
||||
exception: true,
|
||||
exceptionSeverity: 'HIGH',
|
||||
exceptionMessage: 'ERR.NOT_FOUND',
|
||||
stackTrace: `Plan usage with ID ${id} not found`
|
||||
}, null);
|
||||
res.status(404).send(errorResponse);
|
||||
return;
|
||||
}
|
||||
const httpResponse = new GenericResponse(null, response);
|
||||
res.status(200).send(httpResponse);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,108 +1,318 @@
|
||||
import { Body, Controller, Delete, Get, Param, Post, Put, Res } from '@nestjs/common';
|
||||
import { Response } from 'express';
|
||||
import { GenericResponse } from 'src/common/GenericResponse.model';
|
||||
import Plan from './plans.entity';
|
||||
import Plan from './plans.entity';
|
||||
import { PlansService } from './plans.service';
|
||||
import { ApiTags, ApiOperation, ApiResponse, ApiParam, ApiBody } from '@nestjs/swagger';
|
||||
|
||||
@ApiTags('plans')
|
||||
@Controller('plans')
|
||||
export class PlansController {
|
||||
|
||||
constructor(private planService?: PlansService) {
|
||||
if(!planService) {
|
||||
planService = new PlansService();
|
||||
}
|
||||
}
|
||||
constructor(private planService: PlansService) { }
|
||||
|
||||
@Get("/all")
|
||||
@ApiOperation({ summary: 'Get all plans' })
|
||||
@ApiResponse({
|
||||
status: 200,
|
||||
description: 'Successfully retrieved all plans',
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 404,
|
||||
description: 'No plans found',
|
||||
example: {
|
||||
"notification": {
|
||||
"exception": true,
|
||||
"exceptionSeverity": "HIGH",
|
||||
"exceptionMessage": "ERR.NOT_FOUND",
|
||||
"stackTrace": "No plans found"
|
||||
},
|
||||
"data": null
|
||||
}
|
||||
})
|
||||
async plangetAll(@Res() res: Response) {
|
||||
const response = await this.planService.findAll() || [];
|
||||
const httpResponse = new GenericResponse(null, response)
|
||||
res.send(httpResponse);
|
||||
if (!response) {
|
||||
const errorResponse = new GenericResponse({
|
||||
exception: true,
|
||||
exceptionSeverity: 'HIGH',
|
||||
exceptionMessage: 'ERR.NOT_FOUND',
|
||||
stackTrace: 'No plans found'
|
||||
}, null);
|
||||
res.status(404).send(errorResponse);
|
||||
return;
|
||||
}
|
||||
const httpResponse = new GenericResponse(null, response);
|
||||
res.status(200).send(httpResponse);
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
@ApiOperation({ summary: 'Get a plan by ID' })
|
||||
@ApiParam({ name: 'id', type: Number, description: 'Plan ID' })
|
||||
@ApiResponse({
|
||||
status: 400,
|
||||
description: 'ID parameter is missing',
|
||||
example: {
|
||||
"notification": {
|
||||
"exception": true,
|
||||
"exceptionSeverity": "HIGH",
|
||||
"exceptionMessage": "ERR.NO_ID_IN_REQ",
|
||||
"stackTrace": "Request"
|
||||
},
|
||||
"data": null
|
||||
}
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 404,
|
||||
description: 'Plan not found',
|
||||
example: {
|
||||
"notification": {
|
||||
"exception": true,
|
||||
"exceptionSeverity": "HIGH",
|
||||
"exceptionMessage": "ERR.NOT_FOUND",
|
||||
"stackTrace": "Plan not found"
|
||||
},
|
||||
"data": null
|
||||
}
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 200,
|
||||
description: 'Successfully retrieved plan',
|
||||
})
|
||||
async planFindById(@Param('id') id: number, @Res() res: Response) {
|
||||
if(!id) {
|
||||
if (!id) {
|
||||
const response = new GenericResponse({
|
||||
exception: true,
|
||||
exceptionSeverity: 'HIGH',
|
||||
exceptionMessage: 'ERR.NO_ID_IN_REQ',
|
||||
stackTrace: 'Request'
|
||||
}, null);
|
||||
res.send(response);
|
||||
res.status(400).send(response);
|
||||
return;
|
||||
}
|
||||
const response = await this.planService.findByPk(id) || {};
|
||||
const httpResponse = new GenericResponse(null, response)
|
||||
res.send(httpResponse);
|
||||
const response = await this.planService.findByPk(id);
|
||||
if (!response) {
|
||||
const errorResponse = new GenericResponse({
|
||||
exception: true,
|
||||
exceptionSeverity: 'HIGH',
|
||||
exceptionMessage: 'ERR.NOT_FOUND',
|
||||
stackTrace: `Plan with ID ${id} not found`
|
||||
}, null);
|
||||
res.status(404).send(errorResponse);
|
||||
return;
|
||||
}
|
||||
const httpResponse = new GenericResponse(null, response);
|
||||
res.status(200).send(httpResponse);
|
||||
}
|
||||
|
||||
@Post('/filter')
|
||||
async planFilter(@Body() user: Plan, @Res() res: Response) {
|
||||
if(!user) {
|
||||
@ApiOperation({ summary: 'Filter plans based on criteria' })
|
||||
@ApiBody({ type: Plan })
|
||||
@ApiResponse({
|
||||
status: 404,
|
||||
description: 'No plans found matching criteria',
|
||||
example: {
|
||||
"notification": {
|
||||
"exception": true,
|
||||
"exceptionSeverity": "HIGH",
|
||||
"exceptionMessage": "ERR.NOT_FOUND",
|
||||
"stackTrace": "No plans found matching criteria"
|
||||
},
|
||||
"data": null
|
||||
}
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 200,
|
||||
description: 'Successfully filtered plans',
|
||||
})
|
||||
async planFilter(@Body() plan: Plan, @Res() res: Response) {
|
||||
if (!plan) {
|
||||
const response = new GenericResponse({
|
||||
exception: true,
|
||||
exceptionSeverity: 'HIGH',
|
||||
exceptionMessage: 'ERR.NO_REQ',
|
||||
stackTrace: 'Request'
|
||||
}, null);
|
||||
res.send(response);
|
||||
res.status(400).send(response);
|
||||
return;
|
||||
}
|
||||
const response = await this.planService.filter(user) || [];
|
||||
const httpResponse = new GenericResponse(null, response)
|
||||
res.send(httpResponse);
|
||||
const response = await this.planService.filter(plan);
|
||||
if (!response) {
|
||||
const errorResponse = new GenericResponse({
|
||||
exception: true,
|
||||
exceptionSeverity: 'HIGH',
|
||||
exceptionMessage: 'ERR.NOT_FOUND',
|
||||
stackTrace: 'No plans found matching criteria'
|
||||
}, null);
|
||||
res.status(404).send(errorResponse);
|
||||
return;
|
||||
}
|
||||
const httpResponse = new GenericResponse(null, response);
|
||||
res.status(200).send(httpResponse);
|
||||
}
|
||||
|
||||
@Post()
|
||||
async planInsert(@Body() user: Plan, @Res() res: Response) {
|
||||
if(!user) {
|
||||
@ApiOperation({ summary: 'Create a new plan' })
|
||||
@ApiBody({ type: Plan })
|
||||
@ApiResponse({
|
||||
status: 400,
|
||||
description: 'Failed to create plan',
|
||||
example: {
|
||||
"notification": {
|
||||
"exception": true,
|
||||
"exceptionSeverity": "HIGH",
|
||||
"exceptionMessage": "ERR.NOT_CREATED",
|
||||
"stackTrace": "Plan not created"
|
||||
},
|
||||
"data": null
|
||||
}
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 201,
|
||||
description: 'Plan successfully created',
|
||||
})
|
||||
async planInsert(@Body() plan: Plan, @Res() res: Response) {
|
||||
if (!plan) {
|
||||
const response = new GenericResponse({
|
||||
exception: true,
|
||||
exceptionSeverity: 'HIGH',
|
||||
exceptionMessage: 'ERR.NO_REQ',
|
||||
stackTrace: 'Request'
|
||||
}, null);
|
||||
res.send(response);
|
||||
res.status(400).send(response);
|
||||
return;
|
||||
}
|
||||
delete user.id;
|
||||
const response = await this.planService.upsert(user, true);
|
||||
const httpResponse = new GenericResponse(null, response)
|
||||
res.send(httpResponse);
|
||||
delete plan.id;
|
||||
const response = await this.planService.upsert(plan, true);
|
||||
if (!response) {
|
||||
const errorResponse = new GenericResponse({
|
||||
exception: true,
|
||||
exceptionSeverity: 'HIGH',
|
||||
exceptionMessage: 'ERR.NOT_CREATED',
|
||||
stackTrace: 'Plan not created'
|
||||
}, null);
|
||||
res.status(400).send(errorResponse);
|
||||
return;
|
||||
}
|
||||
const httpResponse = new GenericResponse(null, response);
|
||||
res.status(201).send(httpResponse);
|
||||
}
|
||||
|
||||
@Put()
|
||||
async planUpdate(@Body() user: Plan, @Res() res: Response) {
|
||||
if(!user || !user.id) {
|
||||
@ApiOperation({ summary: 'Update an existing plan' })
|
||||
@ApiBody({ type: Plan })
|
||||
@ApiResponse({
|
||||
status: 400,
|
||||
description: 'Failed to update plan',
|
||||
example: {
|
||||
"notification": {
|
||||
"exception": true,
|
||||
"exceptionSeverity": "HIGH",
|
||||
"exceptionMessage": "ERR.NOT_UPDATED",
|
||||
"stackTrace": "Plan not updated"
|
||||
},
|
||||
"data": null
|
||||
}
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 404,
|
||||
description: 'Plan not found',
|
||||
example: {
|
||||
"notification": {
|
||||
"exception": true,
|
||||
"exceptionSeverity": "HIGH",
|
||||
"exceptionMessage": "ERR.NOT_FOUND",
|
||||
"stackTrace": "Plan not found"
|
||||
},
|
||||
"data": null
|
||||
}
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 200,
|
||||
description: 'Plan successfully updated',
|
||||
})
|
||||
async planUpdate(@Body() plan: Plan, @Res() res: Response) {
|
||||
if (!plan || !plan.id) {
|
||||
const response = new GenericResponse({
|
||||
exception: true,
|
||||
exceptionSeverity: 'HIGH',
|
||||
exceptionMessage: 'ERR.NO_REQ',
|
||||
stackTrace: 'Request'
|
||||
}, null);
|
||||
res.send(response);
|
||||
res.status(400).send(response);
|
||||
return;
|
||||
}
|
||||
const response = await this.planService.upsert(user, false);
|
||||
const httpResponse = new GenericResponse(null, response)
|
||||
res.send(httpResponse);
|
||||
const response = await this.planService.upsert(plan, false);
|
||||
if (!response) {
|
||||
const errorResponse = new GenericResponse({
|
||||
exception: true,
|
||||
exceptionSeverity: 'HIGH',
|
||||
exceptionMessage: 'ERR.NOT_FOUND',
|
||||
stackTrace: 'Plan not found'
|
||||
}, null);
|
||||
res.status(404).send(errorResponse);
|
||||
return;
|
||||
}
|
||||
const httpResponse = new GenericResponse(null, response);
|
||||
res.status(200).send(httpResponse);
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
@ApiOperation({ summary: 'Delete a plan by ID' })
|
||||
@ApiParam({ name: 'id', type: Number, description: 'Plan ID' })
|
||||
@ApiResponse({
|
||||
status: 400,
|
||||
description: 'ID parameter is missing',
|
||||
example: {
|
||||
"notification": {
|
||||
"exception": true,
|
||||
"exceptionSeverity": "HIGH",
|
||||
"exceptionMessage": "ERR.NO_ID_IN_REQ",
|
||||
"stackTrace": "Request"
|
||||
},
|
||||
"data": null
|
||||
}
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 404,
|
||||
description: 'Plan not found',
|
||||
example: {
|
||||
"notification": {
|
||||
"exception": true,
|
||||
"exceptionSeverity": "HIGH",
|
||||
"exceptionMessage": "ERR.NOT_FOUND",
|
||||
"stackTrace": "Plan not found"
|
||||
},
|
||||
"data": null
|
||||
}
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 200,
|
||||
description: 'Plan successfully deleted',
|
||||
})
|
||||
async planDeleteById(@Param('id') id: number, @Res() res: Response) {
|
||||
if(!id) {
|
||||
if (!id) {
|
||||
const response = new GenericResponse({
|
||||
exception: true,
|
||||
exceptionSeverity: 'HIGH',
|
||||
exceptionMessage: 'ERR.NO_REQ',
|
||||
exceptionMessage: 'ERR.NO_ID_IN_REQ',
|
||||
stackTrace: 'Request'
|
||||
}, null);
|
||||
res.send(response);
|
||||
res.status(400).send(response);
|
||||
return;
|
||||
}
|
||||
const response = await this.planService.remove(id) || {};
|
||||
const httpResponse = new GenericResponse(null, response)
|
||||
res.send(httpResponse);
|
||||
const response = await this.planService.remove(id);
|
||||
if (!response) {
|
||||
const errorResponse = new GenericResponse({
|
||||
exception: true,
|
||||
exceptionSeverity: 'HIGH',
|
||||
exceptionMessage: 'ERR.NOT_FOUND',
|
||||
stackTrace: `Plan with ID ${id} not found`
|
||||
}, null);
|
||||
res.status(404).send(errorResponse);
|
||||
return;
|
||||
}
|
||||
const httpResponse = new GenericResponse(null, response);
|
||||
res.status(200).send(httpResponse);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user