Compare commits
2 Commits
7966124df6
...
1d40b6544a
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1d40b6544a | ||
|
|
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",
|
"version": "0.0.1",
|
||||||
"description": "",
|
"description": "",
|
||||||
"author": "",
|
"author": "",
|
||||||
@ -23,11 +23,11 @@
|
|||||||
"test:e2e": "jest --config ./test/jest-e2e.json"
|
"test:e2e": "jest --config ./test/jest-e2e.json"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@nestjs-modules/mailer": "^1.10.3",
|
|
||||||
"@nestjs/common": "^10.0.0",
|
"@nestjs/common": "^10.0.0",
|
||||||
"@nestjs/config": "^3.1.1",
|
"@nestjs/config": "^3.1.1",
|
||||||
"@nestjs/core": "^10.0.0",
|
"@nestjs/core": "^10.0.0",
|
||||||
"@nestjs/platform-express": "^10.0.0",
|
"@nestjs/platform-express": "^10.0.0",
|
||||||
|
"@nestjs/swagger": "^8.1.1",
|
||||||
"@nestjs/typeorm": "^10.0.1",
|
"@nestjs/typeorm": "^10.0.1",
|
||||||
"dotenv": "^16.3.1",
|
"dotenv": "^16.3.1",
|
||||||
"handlebars": "^4.7.8",
|
"handlebars": "^4.7.8",
|
||||||
|
|||||||
@ -41,4 +41,8 @@ export class AppConfigService {
|
|||||||
getMailConfig() {
|
getMailConfig() {
|
||||||
return configMaster[this.defaultEnv].mailConfig;
|
return configMaster[this.defaultEnv].mailConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getSwaggerConfig() {
|
||||||
|
return configMaster[this.defaultEnv].swaggerConfig;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -29,6 +29,13 @@
|
|||||||
"defaults": {
|
"defaults": {
|
||||||
"from": "\"No Reply\" <admin@wct.co.in>"
|
"from": "\"No Reply\" <admin@wct.co.in>"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"swaggerConfig": {
|
||||||
|
"swagger": {
|
||||||
|
"title": "Remedify Payment API",
|
||||||
|
"description": "Remedify Payment API",
|
||||||
|
"version": "1.0.0"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -29,6 +29,14 @@
|
|||||||
"defaults": {
|
"defaults": {
|
||||||
"from": "\"No Reply\" <admin@wct.co.in>"
|
"from": "\"No Reply\" <admin@wct.co.in>"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"swaggerConfig": {
|
||||||
|
"swagger": {
|
||||||
|
"title": "Remedify Payment API",
|
||||||
|
"description": "Remedify Payment API",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"tag": "Remedify Payment API"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -30,8 +30,8 @@ import { RefundsModule } from './refund/refund.module';
|
|||||||
QuoteModule,
|
QuoteModule,
|
||||||
RefundsModule,
|
RefundsModule,
|
||||||
DataModule,
|
DataModule,
|
||||||
MailModule,
|
// MailModule,
|
||||||
MasterConfigModule,
|
// MasterConfigModule,
|
||||||
ConfigModule,
|
ConfigModule,
|
||||||
],
|
],
|
||||||
controllers: [AppController, AppConfigController],
|
controllers: [AppController, AppConfigController],
|
||||||
|
|||||||
@ -41,6 +41,10 @@ export class AppService {
|
|||||||
const emailConfig = this.configService.getMailConfig();
|
const emailConfig = this.configService.getMailConfig();
|
||||||
this.commonService.mailConfig = emailConfig;
|
this.commonService.mailConfig = emailConfig;
|
||||||
Utility.mailConfig = emailConfig;
|
Utility.mailConfig = emailConfig;
|
||||||
|
|
||||||
|
const swaggerConfig = this.configService.getSwaggerConfig();
|
||||||
|
this.commonService.swaggerConfig = swaggerConfig;
|
||||||
|
Utility.swaggerConfig = swaggerConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
getModels() {
|
getModels() {
|
||||||
|
|||||||
@ -4,7 +4,8 @@ export class Utility {
|
|||||||
static sequelize: Sequelize;
|
static sequelize: Sequelize;
|
||||||
static appPort: number = 3000;
|
static appPort: number = 3000;
|
||||||
static models: any;
|
static models: any;
|
||||||
static fileConfig: any = {"storagePath": "./uploads"};
|
static fileConfig: any = { "storagePath": "./uploads" };
|
||||||
|
static swaggerConfig: any;
|
||||||
static mailConfig: any = {
|
static mailConfig: any = {
|
||||||
"transport": {
|
"transport": {
|
||||||
"host": "smtppro.zoho.in",
|
"host": "smtppro.zoho.in",
|
||||||
|
|||||||
@ -7,6 +7,7 @@ export class CommonService {
|
|||||||
models: any;
|
models: any;
|
||||||
fileConfig: any;
|
fileConfig: any;
|
||||||
mailConfig: any;
|
mailConfig: any;
|
||||||
|
swaggerConfig: any;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,29 +1,36 @@
|
|||||||
import { Table, Column, Model, Default, DataType } from 'sequelize-typescript';
|
import { Table, Column, Model, Default, DataType } from 'sequelize-typescript';
|
||||||
|
import { ApiProperty } from '@nestjs/swagger';
|
||||||
|
|
||||||
@Table({tableName: 'crud_config_info', paranoid : true})
|
@Table({tableName: 'crud_config_info', paranoid: true})
|
||||||
export default class DataModel extends Model {
|
export default class DataModel extends Model {
|
||||||
|
|
||||||
|
@ApiProperty({ type: Number })
|
||||||
@Column({type: DataType.NUMBER})
|
@Column({type: DataType.NUMBER})
|
||||||
endPtNm: number;
|
endPtNm: number;
|
||||||
|
|
||||||
|
@ApiProperty({ type: String })
|
||||||
@Column({type: DataType.TEXT})
|
@Column({type: DataType.TEXT})
|
||||||
sqlQueryText: string;
|
sqlQueryText: string;
|
||||||
|
|
||||||
|
@ApiProperty({ type: String })
|
||||||
@Column({type: DataType.TEXT})
|
@Column({type: DataType.TEXT})
|
||||||
opsTypeName: string;
|
opsTypeName: string;
|
||||||
|
|
||||||
|
@ApiProperty({ type: Date, default: new Date() })
|
||||||
@Default(new Date())
|
@Default(new Date())
|
||||||
@Column({type: DataType.DATEONLY})
|
@Column({type: DataType.DATEONLY})
|
||||||
validFrom: Date;
|
validFrom: Date;
|
||||||
|
|
||||||
|
@ApiProperty({ type: Date, default: new Date('2070-12-31') })
|
||||||
@Default(new Date("2070-12-31"))
|
@Default(new Date("2070-12-31"))
|
||||||
@Column({type: DataType.DATEONLY})
|
@Column({type: DataType.DATEONLY})
|
||||||
validTill: Date;
|
validTill: Date;
|
||||||
|
|
||||||
|
@ApiProperty({ type: String })
|
||||||
@Column({type: DataType.TEXT})
|
@Column({type: DataType.TEXT})
|
||||||
createBy: string;
|
createBy: string;
|
||||||
|
|
||||||
|
@ApiProperty({ type: String })
|
||||||
@Column({type: DataType.TEXT})
|
@Column({type: DataType.TEXT})
|
||||||
modifiedBy: string;
|
modifiedBy: string;
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -3,19 +3,81 @@ import { Response } from 'express';
|
|||||||
import { InvoicesService } from './invoice.service';
|
import { InvoicesService } from './invoice.service';
|
||||||
import { GenericResponse } from 'src/common/GenericResponse.model';
|
import { GenericResponse } from 'src/common/GenericResponse.model';
|
||||||
import Invoice from './invoice.entity';
|
import Invoice from './invoice.entity';
|
||||||
|
import { ApiTags, ApiOperation, ApiResponse, ApiParam, ApiBody } from '@nestjs/swagger';
|
||||||
|
|
||||||
|
@ApiTags('invoices')
|
||||||
@Controller('invoice')
|
@Controller('invoice')
|
||||||
export class InvoicesController {
|
export class InvoicesController {
|
||||||
constructor(private invoiceService: InvoicesService) { }
|
constructor(private invoiceService: InvoicesService) {}
|
||||||
|
|
||||||
@Get("/all")
|
@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) {
|
async getAll(@Res() res: Response) {
|
||||||
const response = await this.invoiceService.findAll() || [];
|
const response = await this.invoiceService.findAll();
|
||||||
const httpResponse = new GenericResponse(null, response)
|
if (!response) {
|
||||||
res.send(httpResponse);
|
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')
|
@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) {
|
async findById(@Param('id') id: number, @Res() res: Response) {
|
||||||
if (!id) {
|
if (!id) {
|
||||||
const response = new GenericResponse({
|
const response = new GenericResponse({
|
||||||
@ -24,80 +86,232 @@ export class InvoicesController {
|
|||||||
exceptionMessage: 'ERR.NO_ID_IN_REQ',
|
exceptionMessage: 'ERR.NO_ID_IN_REQ',
|
||||||
stackTrace: 'Request'
|
stackTrace: 'Request'
|
||||||
}, null);
|
}, null);
|
||||||
res.send(response);
|
res.status(400).send(response);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const response = await this.invoiceService.findByPk(id) || {};
|
const response = await this.invoiceService.findByPk(id);
|
||||||
const httpResponse = new GenericResponse(null, response)
|
if (!response) {
|
||||||
res.send(httpResponse);
|
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')
|
@Post('/filter')
|
||||||
async filter(@Body() user: Invoice, @Res() res: Response) {
|
@ApiOperation({ summary: 'Filter invoices based on criteria' })
|
||||||
if (!user) {
|
@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({
|
const response = new GenericResponse({
|
||||||
exception: true,
|
exception: true,
|
||||||
exceptionSeverity: 'HIGH',
|
exceptionSeverity: 'HIGH',
|
||||||
exceptionMessage: 'ERR.NO_REQ',
|
exceptionMessage: 'ERR.NO_REQ',
|
||||||
stackTrace: 'Request'
|
stackTrace: 'Request'
|
||||||
}, null);
|
}, null);
|
||||||
res.send(response);
|
res.status(400).send(response);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const response = await this.invoiceService.filter(user) || [];
|
const response = await this.invoiceService.filter(invoice);
|
||||||
const httpResponse = new GenericResponse(null, response)
|
if (!response) {
|
||||||
res.send(httpResponse);
|
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()
|
@Post()
|
||||||
async insert(@Body() user: Invoice, @Res() res: Response) {
|
@ApiOperation({ summary: 'Insert a new invoice' })
|
||||||
if (!user) {
|
@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({
|
const response = new GenericResponse({
|
||||||
exception: true,
|
exception: true,
|
||||||
exceptionSeverity: 'HIGH',
|
exceptionSeverity: 'HIGH',
|
||||||
exceptionMessage: 'ERR.NO_REQ',
|
exceptionMessage: 'ERR.NO_REQ',
|
||||||
stackTrace: 'Request'
|
stackTrace: 'Request'
|
||||||
}, null);
|
}, null);
|
||||||
res.send(response);
|
res.status(400).send(response);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
delete user.id;
|
delete invoice.id;
|
||||||
const response = await this.invoiceService.upsert(user, true);
|
const response = await this.invoiceService.upsert(invoice, true);
|
||||||
const httpResponse = new GenericResponse(null, response)
|
if (!response) {
|
||||||
res.send(httpResponse);
|
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()
|
@Put()
|
||||||
async update(@Body() user: Invoice, @Res() res: Response) {
|
@ApiOperation({ summary: 'Update an existing invoice' })
|
||||||
if (!user || !user.id) {
|
@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({
|
const response = new GenericResponse({
|
||||||
exception: true,
|
exception: true,
|
||||||
exceptionSeverity: 'HIGH',
|
exceptionSeverity: 'HIGH',
|
||||||
exceptionMessage: 'ERR.NO_REQ',
|
exceptionMessage: 'ERR.NO_REQ',
|
||||||
stackTrace: 'Request'
|
stackTrace: 'Request'
|
||||||
}, null);
|
}, null);
|
||||||
res.send(response);
|
res.status(400).send(response);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const response = await this.invoiceService.upsert(user, false);
|
const response = await this.invoiceService.upsert(invoice, false);
|
||||||
const httpResponse = new GenericResponse(null, response)
|
if (!response) {
|
||||||
res.send(httpResponse);
|
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')
|
@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) {
|
async deleteById(@Param('id') id: number, @Res() res: Response) {
|
||||||
if (!id) {
|
if (!id) {
|
||||||
const response = new GenericResponse({
|
const response = new GenericResponse({
|
||||||
exception: true,
|
exception: true,
|
||||||
exceptionSeverity: 'HIGH',
|
exceptionSeverity: 'HIGH',
|
||||||
exceptionMessage: 'ERR.NO_REQ',
|
exceptionMessage: 'ERR.NO_ID_IN_REQ',
|
||||||
stackTrace: 'Request'
|
stackTrace: 'Request'
|
||||||
}, null);
|
}, null);
|
||||||
res.send(response);
|
res.status(400).send(response);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const response = await this.invoiceService.remove(id) || {};
|
const response = await this.invoiceService.remove(id);
|
||||||
const httpResponse = new GenericResponse(null, response)
|
if (!response) {
|
||||||
res.send(httpResponse);
|
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,60 +1,78 @@
|
|||||||
import { Table, Column, Model, Default, DataType, ForeignKey } from 'sequelize-typescript';
|
import { Table, Column, Model, Default, DataType, ForeignKey } from 'sequelize-typescript';
|
||||||
import Payment from 'src/payment/payment.entity';
|
import { ApiProperty } from '@nestjs/swagger';
|
||||||
|
import Payment from 'src/payment/payment.entity';
|
||||||
|
|
||||||
@Table({ tableName: 'invoice' , paranoid : true})
|
@Table({ tableName: 'invoice', paranoid: true })
|
||||||
export default class Invoice extends Model {
|
export default class Invoice extends Model {
|
||||||
|
|
||||||
|
@ApiProperty({ type: Number })
|
||||||
@Column({ type: DataType.BIGINT, allowNull: false })
|
@Column({ type: DataType.BIGINT, allowNull: false })
|
||||||
user_id: number;
|
user_id: number;
|
||||||
|
|
||||||
|
@ApiProperty({ type: Number })
|
||||||
@ForeignKey(() => Payment)
|
@ForeignKey(() => Payment)
|
||||||
@Column({ type: DataType.BIGINT, allowNull: false, field: 'payment_id' })
|
@Column({ type: DataType.BIGINT, allowNull: false, field: 'payment_id' })
|
||||||
payment_id: number;
|
payment_id: number;
|
||||||
|
|
||||||
|
@ApiProperty({ type: String })
|
||||||
@Column({ type: DataType.TEXT, field: 'invoice_number' })
|
@Column({ type: DataType.TEXT, field: 'invoice_number' })
|
||||||
invoice_number: string;
|
invoice_number: string;
|
||||||
|
|
||||||
|
@ApiProperty({ type: Number })
|
||||||
@Column({ type: DataType.NUMBER, field: 'amount' })
|
@Column({ type: DataType.NUMBER, field: 'amount' })
|
||||||
amount: number;
|
amount: number;
|
||||||
|
|
||||||
|
@ApiProperty({ type: Number })
|
||||||
@Column({ type: DataType.NUMBER, field: 'remaining_balance' })
|
@Column({ type: DataType.NUMBER, field: 'remaining_balance' })
|
||||||
remaining_balance: number;
|
remaining_balance: number;
|
||||||
|
|
||||||
|
@ApiProperty({ type: Number })
|
||||||
@Column({ type: DataType.NUMBER, field: 'tax' })
|
@Column({ type: DataType.NUMBER, field: 'tax' })
|
||||||
tax: number;
|
tax: number;
|
||||||
|
|
||||||
|
@ApiProperty({ type: Date })
|
||||||
@Column({ type: DataType.DATEONLY, field: 'issue_date' })
|
@Column({ type: DataType.DATEONLY, field: 'issue_date' })
|
||||||
issue_date: Date;
|
issue_date: Date;
|
||||||
|
|
||||||
|
@ApiProperty({ type: Date })
|
||||||
@Column({ type: DataType.DATEONLY, field: 'due_date' })
|
@Column({ type: DataType.DATEONLY, field: 'due_date' })
|
||||||
due_date: Date;
|
due_date: Date;
|
||||||
|
|
||||||
|
@ApiProperty({ type: String })
|
||||||
@Column({ type: DataType.TEXT, field: 'status' })
|
@Column({ type: DataType.TEXT, field: 'status' })
|
||||||
status: string;
|
status: string;
|
||||||
|
|
||||||
|
@ApiProperty({ type: Date, default: new Date() })
|
||||||
@Default(new Date())
|
@Default(new Date())
|
||||||
@Column({ type: DataType.DATEONLY, field: 'validFrom' })
|
@Column({ type: DataType.DATEONLY, field: 'validFrom' })
|
||||||
valid_from: Date;
|
valid_from: Date;
|
||||||
|
|
||||||
|
@ApiProperty({ type: Date, default: new Date("2070-12-31") })
|
||||||
@Default(new Date("2070-12-31"))
|
@Default(new Date("2070-12-31"))
|
||||||
@Column({ type: DataType.DATEONLY, field: 'validTill' })
|
@Column({ type: DataType.DATEONLY, field: 'validTill' })
|
||||||
valid_till: Date;
|
valid_till: Date;
|
||||||
|
|
||||||
|
@ApiProperty({ type: Date })
|
||||||
@Column({ type: DataType.DATEONLY, field: 'createdAt' })
|
@Column({ type: DataType.DATEONLY, field: 'createdAt' })
|
||||||
created_at: Date;
|
created_at: Date;
|
||||||
|
|
||||||
|
@ApiProperty({ type: Date })
|
||||||
@Column({ type: DataType.DATEONLY, field: 'updatedAt' })
|
@Column({ type: DataType.DATEONLY, field: 'updatedAt' })
|
||||||
updated_at: Date;
|
updated_at: Date;
|
||||||
|
|
||||||
|
@ApiProperty({ type: String })
|
||||||
@Column({ type: DataType.TEXT, field: 'createdBy' })
|
@Column({ type: DataType.TEXT, field: 'createdBy' })
|
||||||
created_by: string;
|
created_by: string;
|
||||||
|
|
||||||
|
@ApiProperty({ type: String })
|
||||||
@Column({ type: DataType.TEXT, field: 'modifiedBy' })
|
@Column({ type: DataType.TEXT, field: 'modifiedBy' })
|
||||||
modified_by: string;
|
modified_by: string;
|
||||||
|
|
||||||
|
@ApiProperty({ type: Date })
|
||||||
@Column({ type: DataType.DATEONLY, field: 'deletedAt' })
|
@Column({ type: DataType.DATEONLY, field: 'deletedAt' })
|
||||||
deleted_at: Date;
|
deleted_at: Date;
|
||||||
|
|
||||||
|
@ApiProperty({ type: Number })
|
||||||
@Column({ type: DataType.NUMBER, field: 'version' })
|
@Column({ type: DataType.NUMBER, field: 'version' })
|
||||||
version: number;
|
version: number;
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import { MailerModule } from '@nestjs-modules/mailer';
|
// import { MailerModule } from '@nestjs-modules/mailer';
|
||||||
import { HandlebarsAdapter } from '@nestjs-modules/mailer/dist/adapters/handlebars.adapter';
|
// import { HandlebarsAdapter } from '@nestjs-modules/mailer/dist/adapters/handlebars.adapter';
|
||||||
import { Module } from '@nestjs/common';
|
import { Module } from '@nestjs/common';
|
||||||
import { MailService } from './mail.service';
|
import { MailService } from './mail.service';
|
||||||
import { join } from 'path';
|
import { join } from 'path';
|
||||||
@ -7,21 +7,21 @@ import { Utility } from 'src/common/Utility';
|
|||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
MailerModule.forRoot({
|
// MailerModule.forRoot({
|
||||||
// transport: 'smtps://user@example.com:topsecret@smtp.example.com',
|
// // transport: 'smtps://user@example.com:topsecret@smtp.example.com',
|
||||||
// or
|
// // or
|
||||||
transport: Utility.mailConfig.transport,
|
// transport: Utility.mailConfig.transport,
|
||||||
defaults: Utility.mailConfig.defaults,
|
// defaults: Utility.mailConfig.defaults,
|
||||||
template: {
|
// template: {
|
||||||
dir: join(__dirname, 'templates'),
|
// dir: join(__dirname, 'templates'),
|
||||||
adapter: new HandlebarsAdapter(), // or new PugAdapter() or new EjsAdapter()
|
// adapter: new HandlebarsAdapter(), // or new PugAdapter() or new EjsAdapter()
|
||||||
options: {
|
// options: {
|
||||||
strict: true,
|
// strict: true,
|
||||||
},
|
// },
|
||||||
},
|
// },
|
||||||
}),
|
// }),
|
||||||
],
|
],
|
||||||
providers: [MailService],
|
// providers: [MailService],
|
||||||
exports: [MailService], // 👈 export for DI
|
// exports: [MailService], // 👈 export for DI
|
||||||
})
|
})
|
||||||
export class MailModule {}
|
export class MailModule {}
|
||||||
|
|||||||
@ -1,19 +1,19 @@
|
|||||||
import { MailerService } from '@nestjs-modules/mailer';
|
// import { MailerService } from '@nestjs-modules/mailer';
|
||||||
import { Injectable } from '@nestjs/common';
|
import { Injectable } from '@nestjs/common';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class MailService {
|
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[]) {
|
// async sendEmail(templateName: string, subject: string, context: any, toEmail: string, ccEmails?: string[], bccEmails?: string[]) {
|
||||||
await this.mailerService.sendMail({
|
// await this.mailerService.sendMail({
|
||||||
to: toEmail,
|
// to: toEmail,
|
||||||
cc: ccEmails,
|
// cc: ccEmails,
|
||||||
bcc: bccEmails,
|
// bcc: bccEmails,
|
||||||
subject: subject,
|
// subject: subject,
|
||||||
template: templateName, // `.hbs` extension is appended automatically
|
// template: templateName, // `.hbs` extension is appended automatically
|
||||||
context,
|
// context,
|
||||||
})
|
// })
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|||||||
17
src/main.ts
17
src/main.ts
@ -3,14 +3,27 @@ import { AppModule } from './app.module';
|
|||||||
import * as bodyParser from 'body-parser';
|
import * as bodyParser from 'body-parser';
|
||||||
import * as configMaster from './app-config/config.json';
|
import * as configMaster from './app-config/config.json';
|
||||||
import { Utility } from './common/Utility';
|
import { Utility } from './common/Utility';
|
||||||
|
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
|
||||||
|
|
||||||
async function bootstrap() {
|
async function bootstrap() {
|
||||||
Utility.appPort = configMaster.local.appConfig.port;
|
Utility.appPort = configMaster.local.appConfig.port;
|
||||||
Utility.mailConfig = configMaster.local.mailConfig;
|
Utility.mailConfig = configMaster.local.mailConfig;
|
||||||
Utility.fileConfig = configMaster.local.fileConfig;
|
Utility.fileConfig = configMaster.local.fileConfig;
|
||||||
|
Utility.swaggerConfig = configMaster.local.swaggerConfig;
|
||||||
|
|
||||||
const app = await NestFactory.create(AppModule, { cors: true });
|
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(Utility.swaggerConfig.swagger.title)
|
||||||
|
.setVersion(Utility.swaggerConfig.swagger.version)
|
||||||
|
.addTag(Utility.swaggerConfig.swagger.tag)
|
||||||
|
.setDescription(Utility.swaggerConfig.swagger.description)
|
||||||
|
.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);
|
await app.listen(Utility.appPort);
|
||||||
}
|
}
|
||||||
bootstrap();
|
bootstrap();
|
||||||
|
|||||||
@ -2,102 +2,310 @@ import { Body, Controller, Delete, Get, Param, Post, Put, Res } from '@nestjs/co
|
|||||||
import { Response } from 'express';
|
import { Response } from 'express';
|
||||||
import { OffersRedemptionsService } from './offers-redemption.service';
|
import { OffersRedemptionsService } from './offers-redemption.service';
|
||||||
import { GenericResponse } from 'src/common/GenericResponse.model';
|
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')
|
@Controller('offers-redemption')
|
||||||
export class OffersRedemptionsController {
|
export class OffersRedemptionsController {
|
||||||
constructor(private offersRedemptionService: OffersRedemptionsService) {}
|
constructor(private offersRedemptionService: OffersRedemptionsService) {}
|
||||||
|
|
||||||
@Get("/all")
|
@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) {
|
async getAllCompanys(@Res() res: Response) {
|
||||||
const response = await this.offersRedemptionService.findAll() || [];
|
const response = await this.offersRedemptionService.findAll() || [];
|
||||||
const httpResponse = new GenericResponse(null, response)
|
if (!response) {
|
||||||
res.send(httpResponse);
|
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')
|
@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) {
|
async findById(@Param('id') id: number, @Res() res: Response) {
|
||||||
if(!id) {
|
if (!id) {
|
||||||
const response = new GenericResponse({
|
const response = new GenericResponse({
|
||||||
exception: true,
|
exception: true,
|
||||||
exceptionSeverity: 'HIGH',
|
exceptionSeverity: 'HIGH',
|
||||||
exceptionMessage: 'ERR.NO_ID_REQ',
|
exceptionMessage: 'ERR.NO_ID_REQ',
|
||||||
stackTrace: 'Request'
|
stackTrace: 'Request'
|
||||||
}, null);
|
}, null);
|
||||||
res.send(response);
|
res.status(400).send(response);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const response = await this.offersRedemptionService.findByPk(id) || {};
|
const response = await this.offersRedemptionService.findByPk(id);
|
||||||
const httpResponse = new GenericResponse(null, response)
|
if (!response) {
|
||||||
res.send(httpResponse);
|
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')
|
@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) {
|
async filter(@Body() offersRedemption: OffersRedemption, @Res() res: Response) {
|
||||||
if(!offersRedemption) {
|
if (!offersRedemption) {
|
||||||
const response = new GenericResponse({
|
const response = new GenericResponse({
|
||||||
exception: true,
|
exception: true,
|
||||||
exceptionSeverity: 'HIGH',
|
exceptionSeverity: 'HIGH',
|
||||||
exceptionMessage: 'ERR.NO_ID_REQ',
|
exceptionMessage: 'ERR.NO_ID_REQ',
|
||||||
stackTrace: 'Request'
|
stackTrace: 'Request'
|
||||||
}, null);
|
}, null);
|
||||||
res.send(response);
|
res.status(400).send(response);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const response = await this.offersRedemptionService.findOne(offersRedemption) || {};
|
const response = await this.offersRedemptionService.findOne(offersRedemption);
|
||||||
const httpResponse = new GenericResponse(null, response)
|
if (!response) {
|
||||||
res.send(httpResponse);
|
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()
|
@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) {
|
async insert(@Body() offersRedemption: OffersRedemption, @Res() res: Response) {
|
||||||
if(!offersRedemption) {
|
if (!offersRedemption) {
|
||||||
const response = new GenericResponse({
|
const response = new GenericResponse({
|
||||||
exception: true,
|
exception: true,
|
||||||
exceptionSeverity: 'HIGH',
|
exceptionSeverity: 'HIGH',
|
||||||
exceptionMessage: 'ERR.NO_ID_REQ',
|
exceptionMessage: 'ERR.NO_ID_REQ',
|
||||||
stackTrace: 'Request'
|
stackTrace: 'Request'
|
||||||
}, null);
|
}, null);
|
||||||
res.send(response);
|
res.status(400).send(response);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
delete offersRedemption.id;
|
delete offersRedemption.id;
|
||||||
const response = await this.offersRedemptionService.upsert(offersRedemption, true);
|
const response = await this.offersRedemptionService.upsert(offersRedemption, true);
|
||||||
const httpResponse = new GenericResponse(null, response)
|
if (!response) {
|
||||||
res.send(httpResponse);
|
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()
|
@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) {
|
async update(@Body() offersRedemption: OffersRedemption, @Res() res: Response) {
|
||||||
if(!offersRedemption || !offersRedemption.id) {
|
if (!offersRedemption || !offersRedemption.id) {
|
||||||
const response = new GenericResponse({
|
const response = new GenericResponse({
|
||||||
exception: true,
|
exception: true,
|
||||||
exceptionSeverity: 'HIGH',
|
exceptionSeverity: 'HIGH',
|
||||||
exceptionMessage: 'ERR.NO_ID_REQ',
|
exceptionMessage: 'ERR.NO_ID_REQ',
|
||||||
stackTrace: 'Request'
|
stackTrace: 'Request'
|
||||||
}, null);
|
}, null);
|
||||||
res.send(response);
|
res.status(400).send(response);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const response = await this.offersRedemptionService.upsert(offersRedemption, false);
|
const response = await this.offersRedemptionService.upsert(offersRedemption, false);
|
||||||
const httpResponse = new GenericResponse(null, response)
|
if (!response) {
|
||||||
res.send(httpResponse);
|
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')
|
@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) {
|
async deleteById(@Param('id') id: number, @Res() res: Response) {
|
||||||
if(!id) {
|
if (!id) {
|
||||||
const response = new GenericResponse({
|
const response = new GenericResponse({
|
||||||
exception: true,
|
exception: true,
|
||||||
exceptionSeverity: 'HIGH',
|
exceptionSeverity: 'HIGH',
|
||||||
exceptionMessage: 'ERR.NO_ID_REQ',
|
exceptionMessage: 'ERR.NO_ID_REQ',
|
||||||
stackTrace: 'Request'
|
stackTrace: 'Request'
|
||||||
}, null);
|
}, null);
|
||||||
res.send(response);
|
res.status(400).send(response);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const response = await this.offersRedemptionService.remove(id) || {};
|
const response = await this.offersRedemptionService.remove(id);
|
||||||
const httpResponse = new GenericResponse(null, response)
|
if (!response) {
|
||||||
res.send(httpResponse);
|
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,46 +1,60 @@
|
|||||||
import { Table, Column, Model, Default, DataType } from 'sequelize-typescript';
|
import { Table, Column, Model, Default, DataType } from 'sequelize-typescript';
|
||||||
|
import { ApiProperty } from '@nestjs/swagger';
|
||||||
|
|
||||||
@Table({ tableName: 'offers_redemption' , paranoid : true})
|
@Table({ tableName: 'offers_redemption', paranoid: true })
|
||||||
export default class OfferRedemption extends Model {
|
export default class OfferRedemption extends Model {
|
||||||
|
|
||||||
|
@ApiProperty({ type: Number })
|
||||||
@Column(DataType.BIGINT)
|
@Column(DataType.BIGINT)
|
||||||
user_id: number;
|
user_id: number;
|
||||||
|
|
||||||
|
@ApiProperty({ type: Number })
|
||||||
@Column(DataType.BIGINT)
|
@Column(DataType.BIGINT)
|
||||||
offer_id: number;
|
offer_id: number;
|
||||||
|
|
||||||
|
@ApiProperty({ type: Number })
|
||||||
@Column(DataType.BIGINT)
|
@Column(DataType.BIGINT)
|
||||||
payment_id: number;
|
payment_id: number;
|
||||||
|
|
||||||
|
@ApiProperty({ type: Date })
|
||||||
@Column(DataType.DATEONLY)
|
@Column(DataType.DATEONLY)
|
||||||
redemption_date: Date;
|
redemption_date: Date;
|
||||||
|
|
||||||
|
@ApiProperty({ type: String })
|
||||||
@Column(DataType.TEXT)
|
@Column(DataType.TEXT)
|
||||||
status: string;
|
status: string;
|
||||||
|
|
||||||
|
@ApiProperty({ type: Date, default: new Date() })
|
||||||
@Default(new Date())
|
@Default(new Date())
|
||||||
@Column(DataType.DATEONLY)
|
@Column(DataType.DATEONLY)
|
||||||
validFrom: Date;
|
validFrom: Date;
|
||||||
|
|
||||||
|
@ApiProperty({ type: Date, default: new Date("2070-12-31") })
|
||||||
@Default(new Date("2070-12-31"))
|
@Default(new Date("2070-12-31"))
|
||||||
@Column(DataType.DATEONLY)
|
@Column(DataType.DATEONLY)
|
||||||
validTill: Date;
|
validTill: Date;
|
||||||
|
|
||||||
|
@ApiProperty({ type: Date })
|
||||||
@Column(DataType.DATEONLY)
|
@Column(DataType.DATEONLY)
|
||||||
createdAt: Date;
|
createdAt: Date;
|
||||||
|
|
||||||
|
@ApiProperty({ type: Date })
|
||||||
@Column(DataType.DATEONLY)
|
@Column(DataType.DATEONLY)
|
||||||
updatedAt: Date;
|
updatedAt: Date;
|
||||||
|
|
||||||
|
@ApiProperty({ type: String })
|
||||||
@Column(DataType.TEXT)
|
@Column(DataType.TEXT)
|
||||||
createdBy: string;
|
createdBy: string;
|
||||||
|
|
||||||
|
@ApiProperty({ type: String })
|
||||||
@Column(DataType.TEXT)
|
@Column(DataType.TEXT)
|
||||||
modifiedBy: string;
|
modifiedBy: string;
|
||||||
|
|
||||||
|
@ApiProperty({ type: Date })
|
||||||
@Column(DataType.DATEONLY)
|
@Column(DataType.DATEONLY)
|
||||||
deletedAt: Date;
|
deletedAt: Date;
|
||||||
|
|
||||||
|
@ApiProperty({ type: Number })
|
||||||
@Column(DataType.NUMBER)
|
@Column(DataType.NUMBER)
|
||||||
version: number;
|
version: number;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,103 +1,311 @@
|
|||||||
import { Body, Controller, Delete, Get, Param, Post, Put, Res } from '@nestjs/common';
|
import { Body, Controller, Delete, Get, Param, Post, Put, Res } from '@nestjs/common';
|
||||||
import { OfferService } from './offers.service';
|
|
||||||
import { Response } from 'express';
|
import { Response } from 'express';
|
||||||
|
import { OfferService } from './offers.service';
|
||||||
import { GenericResponse } from 'src/common/GenericResponse.model';
|
import { GenericResponse } from 'src/common/GenericResponse.model';
|
||||||
import Offer from './offers.entity';
|
import Offer from './offers.entity';
|
||||||
|
import { ApiTags, ApiOperation, ApiResponse, ApiParam, ApiBody } from '@nestjs/swagger';
|
||||||
|
|
||||||
|
@ApiTags('offers')
|
||||||
@Controller('offers')
|
@Controller('offers')
|
||||||
export class OfferController {
|
export class OfferController {
|
||||||
constructor(private offersService: OfferService) {}
|
constructor(private offersService: OfferService) {}
|
||||||
|
|
||||||
@Get("/all")
|
@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) {
|
async getAllOffers(@Res() res: Response) {
|
||||||
const response = await this.offersService.findAll() || [];
|
const response = await this.offersService.findAll() || [];
|
||||||
const httpResponse = new GenericResponse(null, response)
|
if (!response) {
|
||||||
res.send(httpResponse);
|
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')
|
@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) {
|
async findById(@Param('id') id: number, @Res() res: Response) {
|
||||||
if(!id) {
|
if (!id) {
|
||||||
const response = new GenericResponse({
|
const response = new GenericResponse({
|
||||||
exception: true,
|
exception: true,
|
||||||
exceptionSeverity: 'HIGH',
|
exceptionSeverity: 'HIGH',
|
||||||
exceptionMessage: 'ERR.NO_ID_REQ',
|
exceptionMessage: 'ERR.NO_ID_REQ',
|
||||||
stackTrace: 'Request'
|
stackTrace: 'Request'
|
||||||
}, null);
|
}, null);
|
||||||
res.send(response);
|
res.status(400).send(response);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const response = await this.offersService.findByPk(id) || {};
|
const response = await this.offersService.findByPk(id);
|
||||||
const httpResponse = new GenericResponse(null, response)
|
if (!response) {
|
||||||
res.send(httpResponse);
|
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')
|
@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) {
|
async filter(@Body() offers: Offer, @Res() res: Response) {
|
||||||
if(!offers) {
|
if (!offers) {
|
||||||
const response = new GenericResponse({
|
const response = new GenericResponse({
|
||||||
exception: true,
|
exception: true,
|
||||||
exceptionSeverity: 'HIGH',
|
exceptionSeverity: 'HIGH',
|
||||||
exceptionMessage: 'ERR.NO_ID_REQ',
|
exceptionMessage: 'ERR.NO_ID_REQ',
|
||||||
stackTrace: 'Request'
|
stackTrace: 'Request'
|
||||||
}, null);
|
}, null);
|
||||||
res.send(response);
|
res.status(400).send(response);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const response = await this.offersService.filter(offers) || {};
|
const response = await this.offersService.filter(offers);
|
||||||
const httpResponse = new GenericResponse(null, response)
|
if (!response) {
|
||||||
res.send(httpResponse);
|
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()
|
@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) {
|
async insert(@Body() offers: Offer, @Res() res: Response) {
|
||||||
if(!offers) {
|
if (!offers) {
|
||||||
const response = new GenericResponse({
|
const response = new GenericResponse({
|
||||||
exception: true,
|
exception: true,
|
||||||
exceptionSeverity: 'HIGH',
|
exceptionSeverity: 'HIGH',
|
||||||
exceptionMessage: 'ERR.NO_ID_REQ',
|
exceptionMessage: 'ERR.NO_ID_REQ',
|
||||||
stackTrace: 'Request'
|
stackTrace: 'Request'
|
||||||
}, null);
|
}, null);
|
||||||
res.send(response);
|
res.status(400).send(response);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
delete offers.id;
|
delete offers.id;
|
||||||
const response = await this.offersService.upsert(offers, true);
|
const response = await this.offersService.upsert(offers, true);
|
||||||
const httpResponse = new GenericResponse(null, response)
|
if (!response) {
|
||||||
res.send(httpResponse);
|
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()
|
@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) {
|
async update(@Body() offers: Offer, @Res() res: Response) {
|
||||||
if(!Offer || !offers.id) {
|
if (!offers || !offers.id) {
|
||||||
const response = new GenericResponse({
|
const response = new GenericResponse({
|
||||||
exception: true,
|
exception: true,
|
||||||
exceptionSeverity: 'HIGH',
|
exceptionSeverity: 'HIGH',
|
||||||
exceptionMessage: 'ERR.NO_ID_REQ',
|
exceptionMessage: 'ERR.NO_ID_REQ',
|
||||||
stackTrace: 'Request'
|
stackTrace: 'Request'
|
||||||
}, null);
|
}, null);
|
||||||
res.send(response);
|
res.status(400).send(response);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const response = await this.offersService.upsert(offers, false);
|
const response = await this.offersService.upsert(offers, false);
|
||||||
const httpResponse = new GenericResponse(null, response)
|
if (!response) {
|
||||||
res.send(httpResponse);
|
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')
|
@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) {
|
async deleteById(@Param('id') id: number, @Res() res: Response) {
|
||||||
if(!id) {
|
if (!id) {
|
||||||
const response = new GenericResponse({
|
const response = new GenericResponse({
|
||||||
exception: true,
|
exception: true,
|
||||||
exceptionSeverity: 'HIGH',
|
exceptionSeverity: 'HIGH',
|
||||||
exceptionMessage: 'ERR.NO_ID_REQ',
|
exceptionMessage: 'ERR.NO_ID_REQ',
|
||||||
stackTrace: 'Request'
|
stackTrace: 'Request'
|
||||||
}, null);
|
}, null);
|
||||||
res.send(response);
|
res.status(400).send(response);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const response = await this.offersService.remove(id) || {};
|
const response = await this.offersService.remove(id);
|
||||||
const httpResponse = new GenericResponse(null, response)
|
if (!response) {
|
||||||
res.send(httpResponse);
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,43 +1,56 @@
|
|||||||
import { Table, Column, Model, Default, DataType, Unique } from 'sequelize-typescript';
|
import { Table, Column, Model, Default, DataType, Unique } from 'sequelize-typescript';
|
||||||
|
import { ApiProperty } from '@nestjs/swagger';
|
||||||
|
|
||||||
@Table({ tableName: 'offers' , paranoid : true})
|
@Table({ tableName: 'offers', paranoid: true })
|
||||||
export default class Offer extends Model {
|
export default class Offer extends Model {
|
||||||
|
|
||||||
|
@ApiProperty({ type: String })
|
||||||
@Column(DataType.TEXT)
|
@Column(DataType.TEXT)
|
||||||
code: string;
|
code: string;
|
||||||
|
|
||||||
|
@ApiProperty({ type: String })
|
||||||
@Column(DataType.TEXT)
|
@Column(DataType.TEXT)
|
||||||
description: string;
|
description: string;
|
||||||
|
|
||||||
|
@ApiProperty({ type: Number })
|
||||||
@Column(DataType.NUMBER)
|
@Column(DataType.NUMBER)
|
||||||
discount_value: number;
|
discount_value: number;
|
||||||
|
|
||||||
|
@ApiProperty({ type: String })
|
||||||
@Column(DataType.TEXT)
|
@Column(DataType.TEXT)
|
||||||
status: string;
|
status: string;
|
||||||
|
|
||||||
|
@ApiProperty({ type: Date, default: new Date() })
|
||||||
@Default(new Date())
|
@Default(new Date())
|
||||||
@Column(DataType.DATEONLY)
|
@Column(DataType.DATEONLY)
|
||||||
validFrom: Date;
|
validFrom: Date;
|
||||||
|
|
||||||
|
@ApiProperty({ type: Date, default: new Date("2070-12-31") })
|
||||||
@Default(new Date("2070-12-31"))
|
@Default(new Date("2070-12-31"))
|
||||||
@Column(DataType.DATEONLY)
|
@Column(DataType.DATEONLY)
|
||||||
validTill: Date;
|
validTill: Date;
|
||||||
|
|
||||||
|
@ApiProperty({ type: Date })
|
||||||
@Column(DataType.DATEONLY)
|
@Column(DataType.DATEONLY)
|
||||||
createdAt: Date;
|
createdAt: Date;
|
||||||
|
|
||||||
|
@ApiProperty({ type: Date })
|
||||||
@Column(DataType.DATEONLY)
|
@Column(DataType.DATEONLY)
|
||||||
updatedAt: Date;
|
updatedAt: Date;
|
||||||
|
|
||||||
|
@ApiProperty({ type: String })
|
||||||
@Column(DataType.TEXT)
|
@Column(DataType.TEXT)
|
||||||
createdBy: string;
|
createdBy: string;
|
||||||
|
|
||||||
|
@ApiProperty({ type: String })
|
||||||
@Column(DataType.TEXT)
|
@Column(DataType.TEXT)
|
||||||
modifiedBy: string;
|
modifiedBy: string;
|
||||||
|
|
||||||
|
@ApiProperty({ type: Date })
|
||||||
@Column(DataType.DATEONLY)
|
@Column(DataType.DATEONLY)
|
||||||
deletedAt: Date;
|
deletedAt: Date;
|
||||||
|
|
||||||
|
@ApiProperty({ type: Number })
|
||||||
@Column(DataType.NUMBER)
|
@Column(DataType.NUMBER)
|
||||||
version: number;
|
version: number;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,20 +2,60 @@ import { Body, Controller, Delete, Get, Param, Post, Put, Res } from '@nestjs/co
|
|||||||
import { PaymentService } from './payment.service';
|
import { PaymentService } from './payment.service';
|
||||||
import { Response } from 'express';
|
import { Response } from 'express';
|
||||||
import { GenericResponse } from '../common/GenericResponse.model';
|
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')
|
@Controller('payments')
|
||||||
export class PaymentController {
|
export class PaymentController {
|
||||||
constructor(private paymentService: PaymentService) { }
|
constructor(private paymentService: PaymentService) { }
|
||||||
|
|
||||||
@Get("/all")
|
@Get("/all")
|
||||||
|
@ApiOperation({ summary: 'Get all payments' })
|
||||||
|
@ApiResponse({
|
||||||
|
status: 200,
|
||||||
|
description: 'Successfully retrieved all payments',
|
||||||
|
})
|
||||||
async getAllPayments(@Res() res: Response) {
|
async getAllPayments(@Res() res: Response) {
|
||||||
const response = await this.paymentService.findAll() || [];
|
const response = await this.paymentService.findAll() || [];
|
||||||
const httpResponse = new GenericResponse(null, response)
|
const httpResponse = new GenericResponse(null, response);
|
||||||
res.send(httpResponse);
|
res.status(200).send(httpResponse);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get(':id')
|
@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) {
|
async findById(@Param('id') id: number, @Res() res: Response) {
|
||||||
if (!id) {
|
if (!id) {
|
||||||
const response = new GenericResponse({
|
const response = new GenericResponse({
|
||||||
@ -24,15 +64,58 @@ export class PaymentController {
|
|||||||
exceptionMessage: 'ERR.NO_ID_REQ',
|
exceptionMessage: 'ERR.NO_ID_REQ',
|
||||||
stackTrace: 'Request'
|
stackTrace: 'Request'
|
||||||
}, null);
|
}, null);
|
||||||
res.send(response);
|
res.status(400).send(response);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const response = await this.paymentService.findByPk(id) || {};
|
const response = await this.paymentService.findByPk(id);
|
||||||
const httpResponse = new GenericResponse(null, response)
|
if (!response) {
|
||||||
res.send(httpResponse);
|
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')
|
@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) {
|
async filter(@Body() payment: Payment, @Res() res: Response) {
|
||||||
if (!payment) {
|
if (!payment) {
|
||||||
const response = new GenericResponse({
|
const response = new GenericResponse({
|
||||||
@ -41,15 +124,63 @@ export class PaymentController {
|
|||||||
exceptionMessage: 'ERR.NO_ID_REQ',
|
exceptionMessage: 'ERR.NO_ID_REQ',
|
||||||
stackTrace: 'Request'
|
stackTrace: 'Request'
|
||||||
}, null);
|
}, null);
|
||||||
res.send(response);
|
res.status(400).send(response);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const response = await this.paymentService.filter(payment) || [];
|
const response = await this.paymentService.filter(payment);
|
||||||
const httpResponse = new GenericResponse(null, response)
|
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);
|
res.status(200).send(httpResponse);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post()
|
@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) {
|
async insert(@Body() payment: Payment, @Res() res: Response) {
|
||||||
if (!payment) {
|
if (!payment) {
|
||||||
const response = new GenericResponse({
|
const response = new GenericResponse({
|
||||||
@ -58,16 +189,59 @@ export class PaymentController {
|
|||||||
exceptionMessage: 'ERR.NO_ID_REQ',
|
exceptionMessage: 'ERR.NO_ID_REQ',
|
||||||
stackTrace: 'Request'
|
stackTrace: 'Request'
|
||||||
}, null);
|
}, null);
|
||||||
res.send(response);
|
res.status(400).send(response);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
delete payment.id;
|
delete payment.id;
|
||||||
const response = await this.paymentService.upsert(payment, true);
|
const response = await this.paymentService.upsert(payment, true);
|
||||||
const httpResponse = new GenericResponse(null, response)
|
if (!response) {
|
||||||
res.send(httpResponse);
|
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()
|
@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) {
|
async update(@Body() payment: Payment, @Res() res: Response) {
|
||||||
if (!payment || !payment.id) {
|
if (!payment || !payment.id) {
|
||||||
const response = new GenericResponse({
|
const response = new GenericResponse({
|
||||||
@ -76,15 +250,54 @@ export class PaymentController {
|
|||||||
exceptionMessage: 'ERR.NO_ID_REQ',
|
exceptionMessage: 'ERR.NO_ID_REQ',
|
||||||
stackTrace: 'Request'
|
stackTrace: 'Request'
|
||||||
}, null);
|
}, null);
|
||||||
res.send(response);
|
res.status(400).send(response);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const response = await this.paymentService.upsert(payment, false);
|
const response = await this.paymentService.upsert(payment, false);
|
||||||
const httpResponse = new GenericResponse(null, response)
|
if (!response) {
|
||||||
res.send(httpResponse);
|
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')
|
@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) {
|
async deleteById(@Param('id') id: number, @Res() res: Response) {
|
||||||
if (!id) {
|
if (!id) {
|
||||||
const response = new GenericResponse({
|
const response = new GenericResponse({
|
||||||
@ -93,13 +306,21 @@ export class PaymentController {
|
|||||||
exceptionMessage: 'ERR.NO_ID_REQ',
|
exceptionMessage: 'ERR.NO_ID_REQ',
|
||||||
stackTrace: 'Request'
|
stackTrace: 'Request'
|
||||||
}, null);
|
}, null);
|
||||||
res.send(response);
|
res.status(400).send(response);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const response = await this.paymentService.remove(id) || {};
|
const response = await this.paymentService.remove(id);
|
||||||
const httpResponse = new GenericResponse(null, response)
|
if (!response) {
|
||||||
res.send(httpResponse);
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,58 +1,76 @@
|
|||||||
import { Table, Column, Model, Default, DataType } from 'sequelize-typescript';
|
import { Table, Column, Model, Default, DataType } from 'sequelize-typescript';
|
||||||
|
import { ApiProperty } from '@nestjs/swagger';
|
||||||
|
|
||||||
@Table({ tableName: 'payment' , paranoid : true})
|
@Table({ tableName: 'payment', paranoid: true })
|
||||||
export default class Payment extends Model {
|
export default class Payment extends Model {
|
||||||
|
|
||||||
|
@ApiProperty({ type: Number })
|
||||||
@Column(DataType.BIGINT)
|
@Column(DataType.BIGINT)
|
||||||
user_id: number;
|
user_id: number;
|
||||||
|
|
||||||
|
@ApiProperty({ type: Number })
|
||||||
@Column(DataType.NUMBER)
|
@Column(DataType.NUMBER)
|
||||||
amount: number;
|
amount: number;
|
||||||
|
|
||||||
|
@ApiProperty({ type: Date })
|
||||||
@Column(DataType.DATEONLY)
|
@Column(DataType.DATEONLY)
|
||||||
payment_date: Date;
|
payment_date: Date;
|
||||||
|
|
||||||
|
@ApiProperty({ type: String })
|
||||||
@Column(DataType.TEXT)
|
@Column(DataType.TEXT)
|
||||||
method: string;
|
method: string;
|
||||||
|
|
||||||
|
@ApiProperty({ type: String })
|
||||||
@Column(DataType.TEXT)
|
@Column(DataType.TEXT)
|
||||||
payment_signature: string;
|
payment_signature: string;
|
||||||
|
|
||||||
|
@ApiProperty({ type: String })
|
||||||
@Column(DataType.TEXT)
|
@Column(DataType.TEXT)
|
||||||
from_account: string;
|
from_account: string;
|
||||||
|
|
||||||
|
@ApiProperty({ type: String })
|
||||||
@Column(DataType.TEXT)
|
@Column(DataType.TEXT)
|
||||||
to_account: string;
|
to_account: string;
|
||||||
|
|
||||||
|
@ApiProperty({ type: Number })
|
||||||
@Column(DataType.NUMBER)
|
@Column(DataType.NUMBER)
|
||||||
remaining_amount: number;
|
remaining_amount: number;
|
||||||
|
|
||||||
|
@ApiProperty({ type: String })
|
||||||
@Column(DataType.TEXT)
|
@Column(DataType.TEXT)
|
||||||
status: string;
|
status: string;
|
||||||
|
|
||||||
|
@ApiProperty({ type: Date, default: new Date() })
|
||||||
@Default(new Date())
|
@Default(new Date())
|
||||||
@Column(DataType.DATEONLY)
|
@Column(DataType.DATEONLY)
|
||||||
validFrom: Date;
|
validFrom: Date;
|
||||||
|
|
||||||
|
@ApiProperty({ type: Date, default: new Date("2070-12-31") })
|
||||||
@Default(new Date("2070-12-31"))
|
@Default(new Date("2070-12-31"))
|
||||||
@Column(DataType.DATEONLY)
|
@Column(DataType.DATEONLY)
|
||||||
validTill: Date;
|
validTill: Date;
|
||||||
|
|
||||||
|
@ApiProperty({ type: Date })
|
||||||
@Column(DataType.DATEONLY)
|
@Column(DataType.DATEONLY)
|
||||||
createdAt: Date;
|
createdAt: Date;
|
||||||
|
|
||||||
|
@ApiProperty({ type: Date })
|
||||||
@Column(DataType.DATEONLY)
|
@Column(DataType.DATEONLY)
|
||||||
updatedAt: Date;
|
updatedAt: Date;
|
||||||
|
|
||||||
|
@ApiProperty({ type: String })
|
||||||
@Column(DataType.TEXT)
|
@Column(DataType.TEXT)
|
||||||
createdBy: string;
|
createdBy: string;
|
||||||
|
|
||||||
|
@ApiProperty({ type: String })
|
||||||
@Column(DataType.TEXT)
|
@Column(DataType.TEXT)
|
||||||
modifiedBy: string;
|
modifiedBy: string;
|
||||||
|
|
||||||
|
@ApiProperty({ type: Date })
|
||||||
@Column(DataType.DATEONLY)
|
@Column(DataType.DATEONLY)
|
||||||
deletedAt: Date;
|
deletedAt: Date;
|
||||||
|
|
||||||
|
@ApiProperty({ type: Number })
|
||||||
@Column(DataType.NUMBER)
|
@Column(DataType.NUMBER)
|
||||||
version: number;
|
version: number;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,101 +3,309 @@ import { Response } from 'express';
|
|||||||
import { GenericResponse } from 'src/common/GenericResponse.model';
|
import { GenericResponse } from 'src/common/GenericResponse.model';
|
||||||
import { PlanUsageService } from './plan-usage.service';
|
import { PlanUsageService } from './plan-usage.service';
|
||||||
import PlanUsage from './plan-usage.entity';
|
import PlanUsage from './plan-usage.entity';
|
||||||
|
import { ApiTags, ApiOperation, ApiResponse, ApiParam, ApiBody } from '@nestjs/swagger';
|
||||||
|
|
||||||
|
@ApiTags('plan-usage')
|
||||||
@Controller('plans-usage')
|
@Controller('plans-usage')
|
||||||
export class PlanUsageController {
|
export class PlanUsageController {
|
||||||
constructor(private itemsService: PlanUsageService) {}
|
constructor(private itemsService: PlanUsageService) { }
|
||||||
|
|
||||||
@Get("/all")
|
@Get("/all")
|
||||||
|
@ApiOperation({ summary: 'Get all plan usage' })
|
||||||
|
@ApiResponse({ status: 200, description: 'Successfully retrieved all plan usage' })
|
||||||
async getAll(@Res() res: Response) {
|
async getAll(@Res() res: Response) {
|
||||||
const response = await this.itemsService.findAll() || [];
|
const response = await this.itemsService.findAll();
|
||||||
const httpResponse = new GenericResponse(null, response)
|
if (!response) {
|
||||||
res.send(httpResponse);
|
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')
|
@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) {
|
async findById(@Param('id') id: number, @Res() res: Response) {
|
||||||
if(!id) {
|
if (!id) {
|
||||||
const response = new GenericResponse({
|
const response = new GenericResponse({
|
||||||
exception: true,
|
exception: true,
|
||||||
exceptionSeverity: 'HIGH',
|
exceptionSeverity: 'HIGH',
|
||||||
exceptionMessage: 'ERR.NO_ID_REQ',
|
exceptionMessage: 'ERR.NO_ID_REQ',
|
||||||
stackTrace: 'Request'
|
stackTrace: 'Request'
|
||||||
}, null);
|
}, null);
|
||||||
res.send(response);
|
res.status(400).send(response);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const response = await this.itemsService.findByPk(id) || {};
|
const response = await this.itemsService.findByPk(id);
|
||||||
const httpResponse = new GenericResponse(null, response)
|
if (!response) {
|
||||||
res.send(httpResponse);
|
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')
|
@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) {
|
async filter(@Body() item: PlanUsage, @Res() res: Response) {
|
||||||
if(!item) {
|
if (!item) {
|
||||||
const response = new GenericResponse({
|
const response = new GenericResponse({
|
||||||
exception: true,
|
exception: true,
|
||||||
exceptionSeverity: 'HIGH',
|
exceptionSeverity: 'HIGH',
|
||||||
exceptionMessage: 'ERR.NO_ID_REQ',
|
exceptionMessage: 'ERR.NO_ID_REQ',
|
||||||
stackTrace: 'Request'
|
stackTrace: 'Request'
|
||||||
}, null);
|
}, null);
|
||||||
res.send(response);
|
res.status(400).send(response);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const response = await this.itemsService.filter(item) || {};
|
const response = await this.itemsService.filter(item);
|
||||||
const httpResponse = new GenericResponse(null, response)
|
if (!response) {
|
||||||
res.send(httpResponse);
|
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()
|
@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) {
|
async insert(@Body() item: PlanUsage, @Res() res: Response) {
|
||||||
if(!item) {
|
if (!item) {
|
||||||
const response = new GenericResponse({
|
const response = new GenericResponse({
|
||||||
exception: true,
|
exception: true,
|
||||||
exceptionSeverity: 'HIGH',
|
exceptionSeverity: 'HIGH',
|
||||||
exceptionMessage: 'ERR.NO_ID_REQ',
|
exceptionMessage: 'ERR.NO_ID_REQ',
|
||||||
stackTrace: 'Request'
|
stackTrace: 'Request'
|
||||||
}, null);
|
}, null);
|
||||||
res.send(response);
|
res.status(400).send(response);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
delete item.id;
|
delete item.id;
|
||||||
const response = await this.itemsService.upsert(item, true);
|
const response = await this.itemsService.upsert(item, true);
|
||||||
const httpResponse = new GenericResponse(null, response)
|
if (!response) {
|
||||||
res.send(httpResponse);
|
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()
|
@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) {
|
async update(@Body() item: PlanUsage, @Res() res: Response) {
|
||||||
if(!item || !item.id) {
|
if (!item || !item.id) {
|
||||||
const response = new GenericResponse({
|
const response = new GenericResponse({
|
||||||
exception: true,
|
exception: true,
|
||||||
exceptionSeverity: 'HIGH',
|
exceptionSeverity: 'HIGH',
|
||||||
exceptionMessage: 'ERR.NO_ID_REQ',
|
exceptionMessage: 'ERR.NO_ID_REQ',
|
||||||
stackTrace: 'Request'
|
stackTrace: 'Request'
|
||||||
}, null);
|
}, null);
|
||||||
res.send(response);
|
res.status(400).send(response);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const response = await this.itemsService.upsert(item, false);
|
const response = await this.itemsService.upsert(item, false);
|
||||||
const httpResponse = new GenericResponse(null, response)
|
if (!response) {
|
||||||
res.send(httpResponse);
|
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')
|
@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) {
|
async deleteById(@Param('id') id: number, @Res() res: Response) {
|
||||||
if(!id) {
|
if (!id) {
|
||||||
const response = new GenericResponse({
|
const response = new GenericResponse({
|
||||||
exception: true,
|
exception: true,
|
||||||
exceptionSeverity: 'HIGH',
|
exceptionSeverity: 'HIGH',
|
||||||
exceptionMessage: 'ERR.NO_ID_REQ',
|
exceptionMessage: 'ERR.NO_ID_REQ',
|
||||||
stackTrace: 'Request'
|
stackTrace: 'Request'
|
||||||
}, null);
|
}, null);
|
||||||
res.send(response);
|
res.status(400).send(response);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const response = await this.itemsService.remove(id) || {};
|
const response = await this.itemsService.remove(id);
|
||||||
const httpResponse = new GenericResponse(null, response)
|
if (!response) {
|
||||||
res.send(httpResponse);
|
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,46 +1,60 @@
|
|||||||
import { Table, Column, Model, Default, DataType } from 'sequelize-typescript';
|
import { Table, Column, Model, Default, DataType } from 'sequelize-typescript';
|
||||||
|
import { ApiProperty } from '@nestjs/swagger';
|
||||||
|
|
||||||
@Table({ tableName: 'plan_usage' , paranoid : true})
|
@Table({ tableName: 'plan_usage', paranoid: true })
|
||||||
export default class PlanUsage extends Model {
|
export default class PlanUsage extends Model {
|
||||||
|
|
||||||
|
@ApiProperty({ type: Number })
|
||||||
@Column(DataType.BIGINT)
|
@Column(DataType.BIGINT)
|
||||||
user_id: number;
|
user_id: number;
|
||||||
|
|
||||||
|
@ApiProperty({ type: Number })
|
||||||
@Column(DataType.BIGINT)
|
@Column(DataType.BIGINT)
|
||||||
plan_id: number;
|
plan_id: number;
|
||||||
|
|
||||||
|
@ApiProperty({ type: String })
|
||||||
@Column(DataType.TEXT)
|
@Column(DataType.TEXT)
|
||||||
usage_type: string;
|
usage_type: string;
|
||||||
|
|
||||||
|
@ApiProperty({ type: Date })
|
||||||
@Column(DataType.DATEONLY)
|
@Column(DataType.DATEONLY)
|
||||||
usage_quantity: Date;
|
usage_quantity: Date;
|
||||||
|
|
||||||
|
@ApiProperty({ type: String })
|
||||||
@Column(DataType.TEXT)
|
@Column(DataType.TEXT)
|
||||||
status: string;
|
status: string;
|
||||||
|
|
||||||
|
@ApiProperty({ type: Date, default: new Date() })
|
||||||
@Default(new Date())
|
@Default(new Date())
|
||||||
@Column(DataType.DATEONLY)
|
@Column(DataType.DATEONLY)
|
||||||
validFrom: Date;
|
validFrom: Date;
|
||||||
|
|
||||||
|
@ApiProperty({ type: Date, default: new Date("2070-12-31") })
|
||||||
@Default(new Date("2070-12-31"))
|
@Default(new Date("2070-12-31"))
|
||||||
@Column(DataType.DATEONLY)
|
@Column(DataType.DATEONLY)
|
||||||
validTill: Date;
|
validTill: Date;
|
||||||
|
|
||||||
|
@ApiProperty({ type: Date })
|
||||||
@Column(DataType.DATEONLY)
|
@Column(DataType.DATEONLY)
|
||||||
createdAt: Date;
|
createdAt: Date;
|
||||||
|
|
||||||
|
@ApiProperty({ type: Date })
|
||||||
@Column(DataType.DATEONLY)
|
@Column(DataType.DATEONLY)
|
||||||
updatedAt: Date;
|
updatedAt: Date;
|
||||||
|
|
||||||
|
@ApiProperty({ type: String })
|
||||||
@Column(DataType.TEXT)
|
@Column(DataType.TEXT)
|
||||||
createdBy: string;
|
createdBy: string;
|
||||||
|
|
||||||
|
@ApiProperty({ type: String })
|
||||||
@Column(DataType.TEXT)
|
@Column(DataType.TEXT)
|
||||||
modifiedBy: string;
|
modifiedBy: string;
|
||||||
|
|
||||||
|
@ApiProperty({ type: Date })
|
||||||
@Column(DataType.DATEONLY)
|
@Column(DataType.DATEONLY)
|
||||||
deletedAt: Date;
|
deletedAt: Date;
|
||||||
|
|
||||||
|
@ApiProperty({ type: Number })
|
||||||
@Column(DataType.NUMBER)
|
@Column(DataType.NUMBER)
|
||||||
version: number;
|
version: number;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,108 +1,318 @@
|
|||||||
import { Body, Controller, Delete, Get, Param, Post, Put, Res } from '@nestjs/common';
|
import { Body, Controller, Delete, Get, Param, Post, Put, Res } from '@nestjs/common';
|
||||||
import { Response } from 'express';
|
import { Response } from 'express';
|
||||||
import { GenericResponse } from 'src/common/GenericResponse.model';
|
import { GenericResponse } from 'src/common/GenericResponse.model';
|
||||||
import Plan from './plans.entity';
|
import Plan from './plans.entity';
|
||||||
import { PlansService } from './plans.service';
|
import { PlansService } from './plans.service';
|
||||||
|
import { ApiTags, ApiOperation, ApiResponse, ApiParam, ApiBody } from '@nestjs/swagger';
|
||||||
|
|
||||||
|
@ApiTags('plans')
|
||||||
@Controller('plans')
|
@Controller('plans')
|
||||||
export class PlansController {
|
export class PlansController {
|
||||||
|
|
||||||
constructor(private planService?: PlansService) {
|
constructor(private planService: PlansService) { }
|
||||||
if(!planService) {
|
|
||||||
planService = new PlansService();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Get("/all")
|
@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) {
|
async plangetAll(@Res() res: Response) {
|
||||||
const response = await this.planService.findAll() || [];
|
const response = await this.planService.findAll() || [];
|
||||||
const httpResponse = new GenericResponse(null, response)
|
if (!response) {
|
||||||
res.send(httpResponse);
|
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')
|
@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) {
|
async planFindById(@Param('id') id: number, @Res() res: Response) {
|
||||||
if(!id) {
|
if (!id) {
|
||||||
const response = new GenericResponse({
|
const response = new GenericResponse({
|
||||||
exception: true,
|
exception: true,
|
||||||
exceptionSeverity: 'HIGH',
|
exceptionSeverity: 'HIGH',
|
||||||
exceptionMessage: 'ERR.NO_ID_IN_REQ',
|
exceptionMessage: 'ERR.NO_ID_IN_REQ',
|
||||||
stackTrace: 'Request'
|
stackTrace: 'Request'
|
||||||
}, null);
|
}, null);
|
||||||
res.send(response);
|
res.status(400).send(response);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const response = await this.planService.findByPk(id) || {};
|
const response = await this.planService.findByPk(id);
|
||||||
const httpResponse = new GenericResponse(null, response)
|
if (!response) {
|
||||||
res.send(httpResponse);
|
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')
|
@Post('/filter')
|
||||||
async planFilter(@Body() user: Plan, @Res() res: Response) {
|
@ApiOperation({ summary: 'Filter plans based on criteria' })
|
||||||
if(!user) {
|
@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({
|
const response = new GenericResponse({
|
||||||
exception: true,
|
exception: true,
|
||||||
exceptionSeverity: 'HIGH',
|
exceptionSeverity: 'HIGH',
|
||||||
exceptionMessage: 'ERR.NO_REQ',
|
exceptionMessage: 'ERR.NO_REQ',
|
||||||
stackTrace: 'Request'
|
stackTrace: 'Request'
|
||||||
}, null);
|
}, null);
|
||||||
res.send(response);
|
res.status(400).send(response);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const response = await this.planService.filter(user) || [];
|
const response = await this.planService.filter(plan);
|
||||||
const httpResponse = new GenericResponse(null, response)
|
if (!response) {
|
||||||
res.send(httpResponse);
|
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()
|
@Post()
|
||||||
async planInsert(@Body() user: Plan, @Res() res: Response) {
|
@ApiOperation({ summary: 'Create a new plan' })
|
||||||
if(!user) {
|
@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({
|
const response = new GenericResponse({
|
||||||
exception: true,
|
exception: true,
|
||||||
exceptionSeverity: 'HIGH',
|
exceptionSeverity: 'HIGH',
|
||||||
exceptionMessage: 'ERR.NO_REQ',
|
exceptionMessage: 'ERR.NO_REQ',
|
||||||
stackTrace: 'Request'
|
stackTrace: 'Request'
|
||||||
}, null);
|
}, null);
|
||||||
res.send(response);
|
res.status(400).send(response);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
delete user.id;
|
delete plan.id;
|
||||||
const response = await this.planService.upsert(user, true);
|
const response = await this.planService.upsert(plan, true);
|
||||||
const httpResponse = new GenericResponse(null, response)
|
if (!response) {
|
||||||
res.send(httpResponse);
|
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()
|
@Put()
|
||||||
async planUpdate(@Body() user: Plan, @Res() res: Response) {
|
@ApiOperation({ summary: 'Update an existing plan' })
|
||||||
if(!user || !user.id) {
|
@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({
|
const response = new GenericResponse({
|
||||||
exception: true,
|
exception: true,
|
||||||
exceptionSeverity: 'HIGH',
|
exceptionSeverity: 'HIGH',
|
||||||
exceptionMessage: 'ERR.NO_REQ',
|
exceptionMessage: 'ERR.NO_REQ',
|
||||||
stackTrace: 'Request'
|
stackTrace: 'Request'
|
||||||
}, null);
|
}, null);
|
||||||
res.send(response);
|
res.status(400).send(response);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const response = await this.planService.upsert(user, false);
|
const response = await this.planService.upsert(plan, false);
|
||||||
const httpResponse = new GenericResponse(null, response)
|
if (!response) {
|
||||||
res.send(httpResponse);
|
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')
|
@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) {
|
async planDeleteById(@Param('id') id: number, @Res() res: Response) {
|
||||||
if(!id) {
|
if (!id) {
|
||||||
const response = new GenericResponse({
|
const response = new GenericResponse({
|
||||||
exception: true,
|
exception: true,
|
||||||
exceptionSeverity: 'HIGH',
|
exceptionSeverity: 'HIGH',
|
||||||
exceptionMessage: 'ERR.NO_REQ',
|
exceptionMessage: 'ERR.NO_ID_IN_REQ',
|
||||||
stackTrace: 'Request'
|
stackTrace: 'Request'
|
||||||
}, null);
|
}, null);
|
||||||
res.send(response);
|
res.status(400).send(response);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const response = await this.planService.remove(id) || {};
|
const response = await this.planService.remove(id);
|
||||||
const httpResponse = new GenericResponse(null, response)
|
if (!response) {
|
||||||
res.send(httpResponse);
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1,46 +1,60 @@
|
|||||||
import { Table, Column, Model, Default, DataType } from 'sequelize-typescript';
|
import { Table, Column, Model, Default, DataType } from 'sequelize-typescript';
|
||||||
|
import { ApiProperty } from '@nestjs/swagger';
|
||||||
|
|
||||||
@Table({ tableName: 'plans_ref' , paranoid : true})
|
@Table({ tableName: 'plans_ref', paranoid: true })
|
||||||
export default class Plan extends Model {
|
export default class Plan extends Model {
|
||||||
|
|
||||||
|
@ApiProperty({ type: String })
|
||||||
@Column(DataType.TEXT)
|
@Column(DataType.TEXT)
|
||||||
name: string;
|
name: string;
|
||||||
|
|
||||||
|
@ApiProperty({ type: Number })
|
||||||
@Column(DataType.NUMBER)
|
@Column(DataType.NUMBER)
|
||||||
price: number;
|
price: number;
|
||||||
|
|
||||||
|
@ApiProperty({ type: Date })
|
||||||
@Column(DataType.DATEONLY)
|
@Column(DataType.DATEONLY)
|
||||||
duration: Date;
|
duration: Date;
|
||||||
|
|
||||||
|
@ApiProperty({ type: String })
|
||||||
@Column(DataType.TEXT)
|
@Column(DataType.TEXT)
|
||||||
description: string;
|
description: string;
|
||||||
|
|
||||||
|
@ApiProperty({ type: String })
|
||||||
@Column(DataType.TEXT)
|
@Column(DataType.TEXT)
|
||||||
status: string;
|
status: string;
|
||||||
|
|
||||||
|
@ApiProperty({ type: Date, default: new Date() })
|
||||||
@Default(new Date())
|
@Default(new Date())
|
||||||
@Column(DataType.DATEONLY)
|
@Column(DataType.DATEONLY)
|
||||||
validFrom: Date;
|
validFrom: Date;
|
||||||
|
|
||||||
|
@ApiProperty({ type: Date, default: new Date("2070-12-31") })
|
||||||
@Default(new Date("2070-12-31"))
|
@Default(new Date("2070-12-31"))
|
||||||
@Column(DataType.DATEONLY)
|
@Column(DataType.DATEONLY)
|
||||||
validTill: Date;
|
validTill: Date;
|
||||||
|
|
||||||
|
@ApiProperty({ type: Date })
|
||||||
@Column(DataType.DATEONLY)
|
@Column(DataType.DATEONLY)
|
||||||
createdAt: Date;
|
createdAt: Date;
|
||||||
|
|
||||||
|
@ApiProperty({ type: Date })
|
||||||
@Column(DataType.DATEONLY)
|
@Column(DataType.DATEONLY)
|
||||||
updatedAt: Date;
|
updatedAt: Date;
|
||||||
|
|
||||||
|
@ApiProperty({ type: String })
|
||||||
@Column(DataType.TEXT)
|
@Column(DataType.TEXT)
|
||||||
createdBy: string;
|
createdBy: string;
|
||||||
|
|
||||||
|
@ApiProperty({ type: String })
|
||||||
@Column(DataType.TEXT)
|
@Column(DataType.TEXT)
|
||||||
modifiedBy: string;
|
modifiedBy: string;
|
||||||
|
|
||||||
|
@ApiProperty({ type: Date })
|
||||||
@Column(DataType.DATEONLY)
|
@Column(DataType.DATEONLY)
|
||||||
deletedAt: Date;
|
deletedAt: Date;
|
||||||
|
|
||||||
|
@ApiProperty({ type: Number })
|
||||||
@Column(DataType.NUMBER)
|
@Column(DataType.NUMBER)
|
||||||
version: number;
|
version: number;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user