swagger updation for quotes and refund
This commit is contained in:
parent
1d40b6544a
commit
cd3678f9b0
@ -3,101 +3,313 @@ import { QuoteService } from './quotes.service';
|
||||
import { Response } from 'express';
|
||||
import { GenericResponse } from 'src/common/GenericResponse.model';
|
||||
import Quote from './quotes.entity';
|
||||
import { ApiTags, ApiOperation, ApiResponse, ApiParam, ApiBody } from '@nestjs/swagger';
|
||||
|
||||
@ApiTags('quotes')
|
||||
@Controller('quotes')
|
||||
export class QuoteController {
|
||||
constructor(private quotesService: QuoteService) {}
|
||||
|
||||
@Get("/all")
|
||||
@ApiOperation({ summary: 'Get all quotes' })
|
||||
@ApiResponse({
|
||||
status: 200,
|
||||
description: 'Successfully retrieved all quotes',
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 404,
|
||||
description: 'No quotes found',
|
||||
example: {
|
||||
"notification": {
|
||||
"exception": true,
|
||||
"exceptionSeverity": "HIGH",
|
||||
"exceptionMessage": "ERR.NOT_FOUND",
|
||||
"stackTrace": "No quotes found"
|
||||
},
|
||||
"data": null
|
||||
}
|
||||
})
|
||||
async getAllQuotes(@Res() res: Response) {
|
||||
const response = await this.quotesService.findAll() || [];
|
||||
const httpResponse = new GenericResponse(null, response)
|
||||
res.send(httpResponse);
|
||||
if (!response) {
|
||||
const errorResponse = new GenericResponse({
|
||||
exception: true,
|
||||
exceptionSeverity: 'HIGH',
|
||||
exceptionMessage: 'ERR.NOT_FOUND',
|
||||
stackTrace: 'No quotes found'
|
||||
}, null);
|
||||
return res.status(404).send(errorResponse);
|
||||
}
|
||||
const httpResponse = new GenericResponse(null, response);
|
||||
res.status(200).send(httpResponse);
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
@ApiOperation({ summary: 'Get quote by ID' })
|
||||
@ApiParam({ name: 'id', type: Number, description: 'Quote ID' })
|
||||
@ApiResponse({
|
||||
status: 400,
|
||||
description: 'ID is required',
|
||||
example: {
|
||||
"notification": {
|
||||
"exception": true,
|
||||
"exceptionSeverity": "HIGH",
|
||||
"exceptionMessage": "ERR.NO_ID_REQ",
|
||||
"stackTrace": "Request"
|
||||
},
|
||||
"data": null
|
||||
}
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 404,
|
||||
description: 'Quote not found',
|
||||
example: {
|
||||
"notification": {
|
||||
"exception": true,
|
||||
"exceptionSeverity": "HIGH",
|
||||
"exceptionMessage": "ERR.NOT_FOUND",
|
||||
"stackTrace": "Quote not found"
|
||||
},
|
||||
"data": null
|
||||
}
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 200,
|
||||
description: 'Successfully retrieved quote by ID',
|
||||
})
|
||||
async findById(@Param('id') id: number, @Res() res: Response) {
|
||||
if(!id) {
|
||||
if (!id) {
|
||||
const response = new GenericResponse({
|
||||
exception: true,
|
||||
exceptionSeverity: 'HIGH',
|
||||
exceptionMessage: 'ERR.NO_ID_REQ',
|
||||
stackTrace: 'Request'
|
||||
}, null);
|
||||
res.send(response);
|
||||
res.status(400).send(response);
|
||||
return;
|
||||
}
|
||||
const response = await this.quotesService.findByPk(id) || {};
|
||||
const httpResponse = new GenericResponse(null, response)
|
||||
res.send(httpResponse);
|
||||
if (!response) {
|
||||
const errorResponse = new GenericResponse({
|
||||
exception: true,
|
||||
exceptionSeverity: 'HIGH',
|
||||
exceptionMessage: 'ERR.NOT_FOUND',
|
||||
stackTrace: `Quote with ID ${id} not found`
|
||||
}, null);
|
||||
return res.status(404).send(errorResponse);
|
||||
}
|
||||
const httpResponse = new GenericResponse(null, response);
|
||||
res.status(200).send(httpResponse);
|
||||
}
|
||||
|
||||
@Post('/filter')
|
||||
@ApiOperation({ summary: 'Filter quotes based on criteria' })
|
||||
@ApiBody({ type: Quote, description: 'Filter criteria for quotes' })
|
||||
@ApiResponse({
|
||||
status: 400,
|
||||
description: 'Filter criteria required',
|
||||
example: {
|
||||
"notification": {
|
||||
"exception": true,
|
||||
"exceptionSeverity": "HIGH",
|
||||
"exceptionMessage": "ERR.NO_ID_REQ",
|
||||
"stackTrace": "Request"
|
||||
},
|
||||
"data": null
|
||||
}
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 404,
|
||||
description: 'No quotes found based on the criteria',
|
||||
example: {
|
||||
"notification": {
|
||||
"exception": true,
|
||||
"exceptionSeverity": "HIGH",
|
||||
"exceptionMessage": "ERR.NOT_FOUND",
|
||||
"stackTrace": "No quotes found based on the filter criteria"
|
||||
},
|
||||
"data": null
|
||||
}
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 200,
|
||||
description: 'Successfully filtered quotes',
|
||||
})
|
||||
async filter(@Body() quotes: Quote, @Res() res: Response) {
|
||||
if(!quotes) {
|
||||
if (!quotes) {
|
||||
const response = new GenericResponse({
|
||||
exception: true,
|
||||
exceptionSeverity: 'HIGH',
|
||||
exceptionMessage: 'ERR.NO_ID_REQ',
|
||||
stackTrace: 'Request'
|
||||
}, null);
|
||||
res.send(response);
|
||||
res.status(400).send(response);
|
||||
return;
|
||||
}
|
||||
const response = await this.quotesService.filter(quotes) || {};
|
||||
const httpResponse = new GenericResponse(null, response)
|
||||
res.send(httpResponse);
|
||||
if (!response) {
|
||||
const errorResponse = new GenericResponse({
|
||||
exception: true,
|
||||
exceptionSeverity: 'HIGH',
|
||||
exceptionMessage: 'ERR.NOT_FOUND',
|
||||
stackTrace: 'No quotes found based on the filter criteria'
|
||||
}, null);
|
||||
return res.status(404).send(errorResponse);
|
||||
}
|
||||
const httpResponse = new GenericResponse(null, response);
|
||||
res.status(200).send(httpResponse);
|
||||
}
|
||||
|
||||
|
||||
@Post()
|
||||
@ApiOperation({ summary: 'Insert a new quote' })
|
||||
@ApiBody({ type: Quote, description: 'Quote data to insert' })
|
||||
@ApiResponse({
|
||||
status: 400,
|
||||
description: 'Invalid quote data',
|
||||
example: {
|
||||
"notification": {
|
||||
"exception": true,
|
||||
"exceptionSeverity": "HIGH",
|
||||
"exceptionMessage": "ERR.INVALID_DATA",
|
||||
"stackTrace": "Request"
|
||||
},
|
||||
"data": null
|
||||
}
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 201,
|
||||
description: 'Quote successfully created',
|
||||
})
|
||||
async insert(@Body() quotes: Quote, @Res() res: Response) {
|
||||
if(!quotes) {
|
||||
if (!quotes) {
|
||||
const response = new GenericResponse({
|
||||
exception: true,
|
||||
exceptionSeverity: 'HIGH',
|
||||
exceptionMessage: 'ERR.NO_ID_REQ',
|
||||
stackTrace: 'Request'
|
||||
}, null);
|
||||
res.send(response);
|
||||
res.status(400).send(response);
|
||||
return;
|
||||
}
|
||||
delete quotes.id;
|
||||
const response = await this.quotesService.upsert(quotes, true);
|
||||
const httpResponse = new GenericResponse(null, response)
|
||||
res.send(httpResponse);
|
||||
const httpResponse = new GenericResponse(null, response);
|
||||
res.status(201).send(httpResponse);
|
||||
}
|
||||
|
||||
@Put()
|
||||
@ApiOperation({ summary: 'Update an existing quote' })
|
||||
@ApiBody({ type: Quote, description: 'Quote data to update' })
|
||||
@ApiResponse({
|
||||
status: 400,
|
||||
description: 'Invalid quote data or ID is missing',
|
||||
example: {
|
||||
"notification": {
|
||||
"exception": true,
|
||||
"exceptionSeverity": "HIGH",
|
||||
"exceptionMessage": "ERR.INVALID_DATA",
|
||||
"stackTrace": "Request"
|
||||
},
|
||||
"data": null
|
||||
}
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 404,
|
||||
description: 'Quote not found',
|
||||
example: {
|
||||
"notification": {
|
||||
"exception": true,
|
||||
"exceptionSeverity": "HIGH",
|
||||
"exceptionMessage": "ERR.NOT_FOUND",
|
||||
"stackTrace": "Quote not found"
|
||||
},
|
||||
"data": null
|
||||
}
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 200,
|
||||
description: 'Quote successfully updated',
|
||||
})
|
||||
async update(@Body() quotes: Quote, @Res() res: Response) {
|
||||
if(!Quote || !quotes.id) {
|
||||
if (!quotes || !quotes.id) {
|
||||
const response = new GenericResponse({
|
||||
exception: true,
|
||||
exceptionSeverity: 'HIGH',
|
||||
exceptionMessage: 'ERR.NO_ID_REQ',
|
||||
stackTrace: 'Request'
|
||||
}, null);
|
||||
res.send(response);
|
||||
res.status(400).send(response);
|
||||
return;
|
||||
}
|
||||
const response = await this.quotesService.upsert(quotes, false);
|
||||
const httpResponse = new GenericResponse(null, response)
|
||||
res.send(httpResponse);
|
||||
if (!response) {
|
||||
const errorResponse = new GenericResponse({
|
||||
exception: true,
|
||||
exceptionSeverity: 'HIGH',
|
||||
exceptionMessage: 'ERR.NOT_FOUND',
|
||||
stackTrace: `Quote with ID ${quotes.id} not found`
|
||||
}, null);
|
||||
return res.status(404).send(errorResponse);
|
||||
}
|
||||
const httpResponse = new GenericResponse(null, response);
|
||||
res.status(200).send(httpResponse);
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
@ApiOperation({ summary: 'Delete a quote by ID' })
|
||||
@ApiParam({ name: 'id', type: Number, description: 'Quote ID to delete' })
|
||||
@ApiResponse({
|
||||
status: 400,
|
||||
description: 'ID parameter is required',
|
||||
example: {
|
||||
"notification": {
|
||||
"exception": true,
|
||||
"exceptionSeverity": "HIGH",
|
||||
"exceptionMessage": "ERR.NO_ID_REQ",
|
||||
"stackTrace": "Request"
|
||||
},
|
||||
"data": null
|
||||
}
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 404,
|
||||
description: 'Quote not found',
|
||||
example: {
|
||||
"notification": {
|
||||
"exception": true,
|
||||
"exceptionSeverity": "HIGH",
|
||||
"exceptionMessage": "ERR.NOT_FOUND",
|
||||
"stackTrace": "Quote not found"
|
||||
},
|
||||
"data": null
|
||||
}
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 200,
|
||||
description: 'Quote successfully deleted',
|
||||
})
|
||||
async deleteById(@Param('id') id: number, @Res() res: Response) {
|
||||
if(!id) {
|
||||
if (!id) {
|
||||
const response = new GenericResponse({
|
||||
exception: true,
|
||||
exceptionSeverity: 'HIGH',
|
||||
exceptionMessage: 'ERR.NO_ID_REQ',
|
||||
stackTrace: 'Request'
|
||||
}, null);
|
||||
res.send(response);
|
||||
res.status(400).send(response);
|
||||
return;
|
||||
}
|
||||
const response = await this.quotesService.remove(id) || {};
|
||||
const httpResponse = new GenericResponse(null, response)
|
||||
res.send(httpResponse);
|
||||
if (!response) {
|
||||
const errorResponse = new GenericResponse({
|
||||
exception: true,
|
||||
exceptionSeverity: 'HIGH',
|
||||
exceptionMessage: 'ERR.NOT_FOUND',
|
||||
stackTrace: `Quote with ID ${id} not found`
|
||||
}, null);
|
||||
return res.status(404).send(errorResponse);
|
||||
}
|
||||
const httpResponse = new GenericResponse(null, response);
|
||||
res.status(200).send(httpResponse);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,52 +1,68 @@
|
||||
import { Table, Column, Model, Default, DataType } from 'sequelize-typescript';
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
|
||||
@Table({ tableName: 'quotes' , paranoid : true})
|
||||
@Table({ tableName: 'quotes', paranoid: true })
|
||||
export default class Quote extends Model {
|
||||
|
||||
@ApiProperty({ type: Number })
|
||||
@Column(DataType.BIGINT)
|
||||
user_id: number;
|
||||
|
||||
@ApiProperty({ type: String })
|
||||
@Column(DataType.TEXT)
|
||||
user_email: string;
|
||||
|
||||
@ApiProperty({ type: Number })
|
||||
@Column(DataType.BIGINT)
|
||||
institute_id: number;
|
||||
|
||||
@ApiProperty({ type: String })
|
||||
@Column(DataType.TEXT)
|
||||
quote_type: string;
|
||||
|
||||
@ApiProperty({ type: Number })
|
||||
@Column(DataType.NUMBER)
|
||||
quote_est: number;
|
||||
|
||||
@ApiProperty({ type: Number })
|
||||
@Column(DataType.NUMBER)
|
||||
cust_estimate: number;
|
||||
|
||||
@ApiProperty({ type: String })
|
||||
@Column(DataType.TEXT)
|
||||
status: string;
|
||||
|
||||
@ApiProperty({ type: Date, default: new Date() })
|
||||
@Default(new Date())
|
||||
@Column(DataType.DATEONLY)
|
||||
validFrom: Date;
|
||||
|
||||
@ApiProperty({ type: Date, default: new Date("2070-12-31") })
|
||||
@Default(new Date("2070-12-31"))
|
||||
@Column(DataType.DATEONLY)
|
||||
validTill: Date;
|
||||
|
||||
@ApiProperty({ type: Date })
|
||||
@Column(DataType.DATEONLY)
|
||||
createdAt: Date;
|
||||
|
||||
@ApiProperty({ type: Date })
|
||||
@Column(DataType.DATEONLY)
|
||||
updatedAt: Date;
|
||||
|
||||
@ApiProperty({ type: String })
|
||||
@Column(DataType.TEXT)
|
||||
createdBy: string;
|
||||
|
||||
@ApiProperty({ type: String })
|
||||
@Column(DataType.TEXT)
|
||||
modifiedBy: string;
|
||||
|
||||
@ApiProperty({ type: Date })
|
||||
@Column(DataType.DATEONLY)
|
||||
deletedAt: Date;
|
||||
|
||||
@ApiProperty({ type: Number })
|
||||
@Column(DataType.NUMBER)
|
||||
version: number;
|
||||
}
|
||||
|
||||
@ -3,101 +3,313 @@ import { Response } from 'express';
|
||||
import { GenericResponse } from 'src/common/GenericResponse.model';
|
||||
import { RefundService } from './refund.service';
|
||||
import Refund from './refund.entity';
|
||||
import { ApiTags, ApiOperation, ApiResponse, ApiParam, ApiBody } from '@nestjs/swagger';
|
||||
|
||||
@ApiTags('refunds')
|
||||
@Controller('refunds')
|
||||
export class RefundController {
|
||||
constructor(private refundsService: RefundService) {}
|
||||
|
||||
@Get("/all")
|
||||
@ApiOperation({ summary: 'Get all refunds' })
|
||||
@ApiResponse({
|
||||
status: 200,
|
||||
description: 'Successfully retrieved all refunds',
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 404,
|
||||
description: 'No refunds found',
|
||||
example: {
|
||||
"notification": {
|
||||
"exception": true,
|
||||
"exceptionSeverity": "HIGH",
|
||||
"exceptionMessage": "ERR.NOT_FOUND",
|
||||
"stackTrace": "No refunds found"
|
||||
},
|
||||
"data": null
|
||||
}
|
||||
})
|
||||
async getAll(@Res() res: Response) {
|
||||
const response = await this.refundsService.findAll() || [];
|
||||
const httpResponse = new GenericResponse(null, response)
|
||||
res.send(httpResponse);
|
||||
if (!response) {
|
||||
const errorResponse = new GenericResponse({
|
||||
exception: true,
|
||||
exceptionSeverity: 'HIGH',
|
||||
exceptionMessage: 'ERR.NOT_FOUND',
|
||||
stackTrace: 'No refunds found'
|
||||
}, null);
|
||||
return res.status(404).send(errorResponse);
|
||||
}
|
||||
const httpResponse = new GenericResponse(null, response);
|
||||
res.status(200).send(httpResponse);
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
@ApiOperation({ summary: 'Get refund by ID' })
|
||||
@ApiParam({ name: 'id', type: Number, description: 'Refund ID' })
|
||||
@ApiResponse({
|
||||
status: 400,
|
||||
description: 'ID is required',
|
||||
example: {
|
||||
"notification": {
|
||||
"exception": true,
|
||||
"exceptionSeverity": "HIGH",
|
||||
"exceptionMessage": "ERR.NO_ID_REQ",
|
||||
"stackTrace": "Request"
|
||||
},
|
||||
"data": null
|
||||
}
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 404,
|
||||
description: 'Refund not found',
|
||||
example: {
|
||||
"notification": {
|
||||
"exception": true,
|
||||
"exceptionSeverity": "HIGH",
|
||||
"exceptionMessage": "ERR.NOT_FOUND",
|
||||
"stackTrace": "Refund not found"
|
||||
},
|
||||
"data": null
|
||||
}
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 200,
|
||||
description: 'Successfully retrieved refund by ID',
|
||||
})
|
||||
async findById(@Param('id') id: number, @Res() res: Response) {
|
||||
if(!id) {
|
||||
if (!id) {
|
||||
const response = new GenericResponse({
|
||||
exception: true,
|
||||
exceptionSeverity: 'HIGH',
|
||||
exceptionMessage: 'ERR.NO_ID_REQ',
|
||||
stackTrace: 'Request'
|
||||
}, null);
|
||||
res.send(response);
|
||||
res.status(400).send(response);
|
||||
return;
|
||||
}
|
||||
const response = await this.refundsService.findByPk(id) || {};
|
||||
const httpResponse = new GenericResponse(null, response)
|
||||
res.send(httpResponse);
|
||||
if (!response) {
|
||||
const errorResponse = new GenericResponse({
|
||||
exception: true,
|
||||
exceptionSeverity: 'HIGH',
|
||||
exceptionMessage: 'ERR.NOT_FOUND',
|
||||
stackTrace: `Refund with ID ${id} not found`
|
||||
}, null);
|
||||
return res.status(404).send(errorResponse);
|
||||
}
|
||||
const httpResponse = new GenericResponse(null, response);
|
||||
res.status(200).send(httpResponse);
|
||||
}
|
||||
|
||||
@Post('/filter')
|
||||
@ApiOperation({ summary: 'Filter refunds based on criteria' })
|
||||
@ApiBody({ type: Refund, description: 'Filter criteria for refunds' })
|
||||
@ApiResponse({
|
||||
status: 400,
|
||||
description: 'Invalid filter criteria',
|
||||
example: {
|
||||
"notification": {
|
||||
"exception": true,
|
||||
"exceptionSeverity": "HIGH",
|
||||
"exceptionMessage": "ERR.INVALID_CRITERIA",
|
||||
"stackTrace": "Request"
|
||||
},
|
||||
"data": null
|
||||
}
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 404,
|
||||
description: 'No refunds found based on the criteria',
|
||||
example: {
|
||||
"notification": {
|
||||
"exception": true,
|
||||
"exceptionSeverity": "HIGH",
|
||||
"exceptionMessage": "ERR.NOT_FOUND",
|
||||
"stackTrace": "No refunds found based on the criteria"
|
||||
},
|
||||
"data": null
|
||||
}
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 200,
|
||||
description: 'Successfully filtered refunds',
|
||||
})
|
||||
async filter(@Body() refund: Refund, @Res() res: Response) {
|
||||
if(!refund) {
|
||||
if (!refund) {
|
||||
const response = new GenericResponse({
|
||||
exception: true,
|
||||
exceptionSeverity: 'HIGH',
|
||||
exceptionMessage: 'ERR.NO_ID_REQ',
|
||||
exceptionMessage: 'ERR.INVALID_CRITERIA',
|
||||
stackTrace: 'Request'
|
||||
}, null);
|
||||
res.send(response);
|
||||
res.status(400).send(response);
|
||||
return;
|
||||
}
|
||||
const response = await this.refundsService.filter(refund) || {};
|
||||
const httpResponse = new GenericResponse(null, response)
|
||||
res.send(httpResponse);
|
||||
if (!response) {
|
||||
const errorResponse = new GenericResponse({
|
||||
exception: true,
|
||||
exceptionSeverity: 'HIGH',
|
||||
exceptionMessage: 'ERR.NOT_FOUND',
|
||||
stackTrace: 'No refunds found based on the filter criteria'
|
||||
}, null);
|
||||
return res.status(404).send(errorResponse);
|
||||
}
|
||||
const httpResponse = new GenericResponse(null, response);
|
||||
res.status(200).send(httpResponse);
|
||||
}
|
||||
|
||||
|
||||
@Post()
|
||||
@ApiOperation({ summary: 'Insert a new refund' })
|
||||
@ApiBody({ type: Refund, description: 'Refund data to insert' })
|
||||
@ApiResponse({
|
||||
status: 400,
|
||||
description: 'Invalid refund data',
|
||||
example: {
|
||||
"notification": {
|
||||
"exception": true,
|
||||
"exceptionSeverity": "HIGH",
|
||||
"exceptionMessage": "ERR.INVALID_DATA",
|
||||
"stackTrace": "Request"
|
||||
},
|
||||
"data": null
|
||||
}
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 201,
|
||||
description: 'Refund successfully created',
|
||||
})
|
||||
async insert(@Body() refund: Refund, @Res() res: Response) {
|
||||
if(!refund) {
|
||||
if (!refund) {
|
||||
const response = new GenericResponse({
|
||||
exception: true,
|
||||
exceptionSeverity: 'HIGH',
|
||||
exceptionMessage: 'ERR.NO_ID_REQ',
|
||||
stackTrace: 'Request'
|
||||
}, null);
|
||||
res.send(response);
|
||||
res.status(400).send(response);
|
||||
return;
|
||||
}
|
||||
delete refund.id;
|
||||
const response = await this.refundsService.upsert(refund, true);
|
||||
const httpResponse = new GenericResponse(null, response)
|
||||
res.send(httpResponse);
|
||||
const httpResponse = new GenericResponse(null, response);
|
||||
res.status(201).send(httpResponse);
|
||||
}
|
||||
|
||||
@Put()
|
||||
@ApiOperation({ summary: 'Update an existing refund' })
|
||||
@ApiBody({ type: Refund, description: 'Refund data to update' })
|
||||
@ApiResponse({
|
||||
status: 400,
|
||||
description: 'Invalid refund data or ID missing',
|
||||
example: {
|
||||
"notification": {
|
||||
"exception": true,
|
||||
"exceptionSeverity": "HIGH",
|
||||
"exceptionMessage": "ERR.INVALID_DATA",
|
||||
"stackTrace": "Request"
|
||||
},
|
||||
"data": null
|
||||
}
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 404,
|
||||
description: 'Refund not found',
|
||||
example: {
|
||||
"notification": {
|
||||
"exception": true,
|
||||
"exceptionSeverity": "HIGH",
|
||||
"exceptionMessage": "ERR.NOT_FOUND",
|
||||
"stackTrace": "Refund not found"
|
||||
},
|
||||
"data": null
|
||||
}
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 200,
|
||||
description: 'Refund successfully updated',
|
||||
})
|
||||
async update(@Body() refund: Refund, @Res() res: Response) {
|
||||
if(!refund || !refund.id) {
|
||||
if (!refund || !refund.id) {
|
||||
const response = new GenericResponse({
|
||||
exception: true,
|
||||
exceptionSeverity: 'HIGH',
|
||||
exceptionMessage: 'ERR.NO_ID_REQ',
|
||||
stackTrace: 'Request'
|
||||
}, null);
|
||||
res.send(response);
|
||||
res.status(400).send(response);
|
||||
return;
|
||||
}
|
||||
const response = await this.refundsService.upsert(refund, false);
|
||||
const httpResponse = new GenericResponse(null, response)
|
||||
res.send(httpResponse);
|
||||
if (!response) {
|
||||
const errorResponse = new GenericResponse({
|
||||
exception: true,
|
||||
exceptionSeverity: 'HIGH',
|
||||
exceptionMessage: 'ERR.NOT_FOUND',
|
||||
stackTrace: `Refund with ID ${refund.id} not found`
|
||||
}, null);
|
||||
return res.status(404).send(errorResponse);
|
||||
}
|
||||
const httpResponse = new GenericResponse(null, response);
|
||||
res.status(200).send(httpResponse);
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
@ApiOperation({ summary: 'Delete a refund by ID' })
|
||||
@ApiParam({ name: 'id', type: Number, description: 'Refund ID to delete' })
|
||||
@ApiResponse({
|
||||
status: 400,
|
||||
description: 'ID parameter is required',
|
||||
example: {
|
||||
"notification": {
|
||||
"exception": true,
|
||||
"exceptionSeverity": "HIGH",
|
||||
"exceptionMessage": "ERR.NO_ID_REQ",
|
||||
"stackTrace": "Request"
|
||||
},
|
||||
"data": null
|
||||
}
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 404,
|
||||
description: 'Refund not found',
|
||||
example: {
|
||||
"notification": {
|
||||
"exception": true,
|
||||
"exceptionSeverity": "HIGH",
|
||||
"exceptionMessage": "ERR.NOT_FOUND",
|
||||
"stackTrace": "Refund not found"
|
||||
},
|
||||
"data": null
|
||||
}
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 200,
|
||||
description: 'Refund successfully deleted',
|
||||
})
|
||||
async deleteById(@Param('id') id: number, @Res() res: Response) {
|
||||
if(!id) {
|
||||
if (!id) {
|
||||
const response = new GenericResponse({
|
||||
exception: true,
|
||||
exceptionSeverity: 'HIGH',
|
||||
exceptionMessage: 'ERR.NO_ID_REQ',
|
||||
stackTrace: 'Request'
|
||||
}, null);
|
||||
res.send(response);
|
||||
res.status(400).send(response);
|
||||
return;
|
||||
}
|
||||
const response = await this.refundsService.remove(id) || {};
|
||||
const httpResponse = new GenericResponse(null, response)
|
||||
res.send(httpResponse);
|
||||
if (!response) {
|
||||
const errorResponse = new GenericResponse({
|
||||
exception: true,
|
||||
exceptionSeverity: 'HIGH',
|
||||
exceptionMessage: 'ERR.NOT_FOUND',
|
||||
stackTrace: `Refund with ID ${id} not found`
|
||||
}, null);
|
||||
return res.status(404).send(errorResponse);
|
||||
}
|
||||
const httpResponse = new GenericResponse(null, response);
|
||||
res.status(200).send(httpResponse);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,49 +1,64 @@
|
||||
import { Table, Column, Model, Default, DataType } from 'sequelize-typescript';
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
|
||||
@Table({ tableName: 'refund' , paranoid : true})
|
||||
@Table({ tableName: 'refund', paranoid: true })
|
||||
export default class Refund extends Model {
|
||||
|
||||
@ApiProperty({ type: Number })
|
||||
@Column(DataType.BIGINT)
|
||||
payment_id: number;
|
||||
|
||||
@ApiProperty({ type: Number })
|
||||
@Column(DataType.NUMBER)
|
||||
amount: number;
|
||||
|
||||
@ApiProperty({ type: Date })
|
||||
@Column(DataType.DATEONLY)
|
||||
refund_date: Date;
|
||||
|
||||
@ApiProperty({ type: String })
|
||||
@Column(DataType.TEXT)
|
||||
reason: string;
|
||||
|
||||
@ApiProperty({ type: String })
|
||||
@Column(DataType.TEXT)
|
||||
to_account: string;
|
||||
|
||||
@ApiProperty({ type: String })
|
||||
@Column(DataType.TEXT)
|
||||
status: string;
|
||||
|
||||
@ApiProperty({ type: Date, default: new Date() })
|
||||
@Default(new Date())
|
||||
@Column(DataType.DATEONLY)
|
||||
validFrom: Date;
|
||||
|
||||
@ApiProperty({ type: Date, default: new Date("2070-12-31") })
|
||||
@Default(new Date("2070-12-31"))
|
||||
@Column(DataType.DATEONLY)
|
||||
validTill: Date;
|
||||
|
||||
@ApiProperty({ type: Date })
|
||||
@Column(DataType.DATEONLY)
|
||||
createdAt: Date;
|
||||
|
||||
@ApiProperty({ type: Date })
|
||||
@Column(DataType.DATEONLY)
|
||||
updatedAt: Date;
|
||||
|
||||
@ApiProperty({ type: String })
|
||||
@Column(DataType.TEXT)
|
||||
createdBy: string;
|
||||
|
||||
@ApiProperty({ type: String })
|
||||
@Column(DataType.TEXT)
|
||||
modifiedBy: string;
|
||||
|
||||
@ApiProperty({ type: Date })
|
||||
@Column(DataType.DATEONLY)
|
||||
deletedAt: Date;
|
||||
|
||||
@ApiProperty({ type: Number })
|
||||
@Column(DataType.NUMBER)
|
||||
version: number;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user