swagger update
This commit is contained in:
parent
1333957d58
commit
ab2932c127
17881
package-lock.json
generated
17881
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -23,16 +23,15 @@
|
|||||||
"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",
|
||||||
"moment": "^2.30.1",
|
"moment": "^2.30.1",
|
||||||
"nexe": "^4.0.0-rc.6",
|
|
||||||
"nodemailer": "^6.9.9",
|
"nodemailer": "^6.9.9",
|
||||||
"otp-generator": "^4.0.1",
|
"otp-generator": "^4.0.1",
|
||||||
"pg": "^8.11.3",
|
"pg": "^8.11.3",
|
||||||
|
|||||||
@ -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,15 @@
|
|||||||
"defaults": {
|
"defaults": {
|
||||||
"from": "\"No Reply\" <admin@wct.co.in>"
|
"from": "\"No Reply\" <admin@wct.co.in>"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"swaggerConfig": {
|
||||||
|
"swagger": {
|
||||||
|
"title": "Remedify Users API",
|
||||||
|
"description": "Remedify Users API",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"tag": "Remedify Users API"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -29,6 +29,15 @@
|
|||||||
"defaults": {
|
"defaults": {
|
||||||
"from": "\"No Reply\" <admin@wct.co.in>"
|
"from": "\"No Reply\" <admin@wct.co.in>"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"swaggerConfig": {
|
||||||
|
"swagger": {
|
||||||
|
"title": "Remedify Users API",
|
||||||
|
"description": "Remedify Users API",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"tag": "Remedify Users API"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -17,10 +17,10 @@ import { InstituteModule } from './institute/institute.module';
|
|||||||
UserModule,
|
UserModule,
|
||||||
InstituteModule,
|
InstituteModule,
|
||||||
DataModule,
|
DataModule,
|
||||||
MailModule,
|
// MailModule,
|
||||||
ItemsModule,
|
ItemsModule,
|
||||||
SubscriptionsModule,
|
SubscriptionsModule,
|
||||||
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,6 +4,7 @@ export class Utility {
|
|||||||
static sequelize: Sequelize;
|
static sequelize: Sequelize;
|
||||||
static appPort: number = 3000;
|
static appPort: number = 3000;
|
||||||
static models: any;
|
static models: any;
|
||||||
|
static swaggerConfig: any;
|
||||||
static fileConfig: any = {"storagePath": "./uploads"};
|
static fileConfig: any = {"storagePath": "./uploads"};
|
||||||
static mailConfig: any = {
|
static mailConfig: any = {
|
||||||
"transport": {
|
"transport": {
|
||||||
|
|||||||
@ -7,6 +7,7 @@ export class CommonService {
|
|||||||
models: any;
|
models: any;
|
||||||
fileConfig: any;
|
fileConfig: any;
|
||||||
mailConfig: any;
|
mailConfig: any;
|
||||||
|
swaggerConfig: any;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,103 +1,337 @@
|
|||||||
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 { InstituteService } from './institute.service';
|
|
||||||
import { Response } from 'express';
|
import { Response } from 'express';
|
||||||
import { GenericResponse } from 'src/common/GenericResponse.model';
|
import { GenericResponse } from 'src/common/GenericResponse.model';
|
||||||
|
import { InstituteService } from './institute.service';
|
||||||
import Institute from './institute.entity';
|
import Institute from './institute.entity';
|
||||||
|
import { ApiTags, ApiOperation, ApiResponse, ApiParam, ApiBody } from '@nestjs/swagger';
|
||||||
|
|
||||||
|
@ApiTags('institute')
|
||||||
@Controller('institute')
|
@Controller('institute')
|
||||||
export class InstituteController {
|
export class InstituteController {
|
||||||
constructor(private instituteService: InstituteService) {}
|
constructor(private instituteService: InstituteService) {}
|
||||||
|
|
||||||
@Get("/all")
|
@Get("/all")
|
||||||
|
@ApiOperation({ summary: 'Get all institutes' })
|
||||||
|
@ApiResponse({
|
||||||
|
status: 200,
|
||||||
|
description: 'Successfully retrieved all institutes',
|
||||||
|
})
|
||||||
|
@ApiResponse({
|
||||||
|
status: 404,
|
||||||
|
description: 'No institutes found',
|
||||||
|
example: {
|
||||||
|
"notification": {
|
||||||
|
"exception": true,
|
||||||
|
"exceptionSeverity": "HIGH",
|
||||||
|
"exceptionMessage": "ERR.NOT_FOUND",
|
||||||
|
"stackTrace": "No institutes found"
|
||||||
|
},
|
||||||
|
"data": null
|
||||||
|
}
|
||||||
|
})
|
||||||
async getAllInstitutes(@Res() res: Response) {
|
async getAllInstitutes(@Res() res: Response) {
|
||||||
const response = await this.instituteService.findAll() || [];
|
const response = await this.instituteService.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 institutes found'
|
||||||
|
}, null);
|
||||||
|
return res.status(404).send(errorResponse);
|
||||||
|
}
|
||||||
|
const httpResponse = new GenericResponse(null, response);
|
||||||
|
res.status(200).send(httpResponse);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get(':id')
|
@Get(':id')
|
||||||
|
@ApiOperation({ summary: 'Get institute by ID' })
|
||||||
|
@ApiParam({ name: 'id', type: Number, description: 'Institute 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: 'Institute not found',
|
||||||
|
example: {
|
||||||
|
"notification": {
|
||||||
|
"exception": true,
|
||||||
|
"exceptionSeverity": "HIGH",
|
||||||
|
"exceptionMessage": "ERR.NOT_FOUND",
|
||||||
|
"stackTrace": "Institute not found"
|
||||||
|
},
|
||||||
|
"data": null
|
||||||
|
}
|
||||||
|
})
|
||||||
|
@ApiResponse({
|
||||||
|
status: 200,
|
||||||
|
description: 'Successfully retrieved institute by ID',
|
||||||
|
})
|
||||||
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.instituteService.findByPk(id) || {};
|
const response = await this.instituteService.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: `Institute 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')
|
@Post('/filter')
|
||||||
|
@ApiOperation({ summary: 'Filter institutes based on criteria' })
|
||||||
|
@ApiBody({ type: Institute, description: 'Filter criteria for institutes' })
|
||||||
|
@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: 'Institute not found',
|
||||||
|
example: {
|
||||||
|
"notification": {
|
||||||
|
"exception": true,
|
||||||
|
"exceptionSeverity": "HIGH",
|
||||||
|
"exceptionMessage": "ERR.NOT_FOUND",
|
||||||
|
"stackTrace": "Institute not found"
|
||||||
|
},
|
||||||
|
"data": null
|
||||||
|
}
|
||||||
|
})
|
||||||
|
@ApiResponse({
|
||||||
|
status: 200,
|
||||||
|
description: 'Successfully filtered institutes',
|
||||||
|
})
|
||||||
async filter(@Body() institute: Institute, @Res() res: Response) {
|
async filter(@Body() institute: Institute, @Res() res: Response) {
|
||||||
if(!institute) {
|
if (!institute) {
|
||||||
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.instituteService.filter(institute) || {};
|
const response = await this.instituteService.filter(institute) || {};
|
||||||
const httpResponse = new GenericResponse(null, response)
|
if (!response) {
|
||||||
res.send(httpResponse);
|
const errorResponse = new GenericResponse({
|
||||||
|
exception: true,
|
||||||
|
exceptionSeverity: 'HIGH',
|
||||||
|
exceptionMessage: 'ERR.NOT_FOUND',
|
||||||
|
stackTrace: 'Institute not found'
|
||||||
|
}, null);
|
||||||
|
return res.status(404).send(errorResponse);
|
||||||
|
}
|
||||||
|
const httpResponse = new GenericResponse(null, response);
|
||||||
|
res.status(200).send(httpResponse);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post()
|
@Post()
|
||||||
|
@ApiOperation({ summary: 'Insert a new institute' })
|
||||||
|
@ApiBody({ type: Institute, description: 'Institute data to insert' })
|
||||||
|
@ApiResponse({
|
||||||
|
status: 400,
|
||||||
|
description: 'Invalid institute data',
|
||||||
|
example: {
|
||||||
|
"notification": {
|
||||||
|
"exception": true,
|
||||||
|
"exceptionSeverity": "HIGH",
|
||||||
|
"exceptionMessage": "ERR.INVALID_DATA",
|
||||||
|
"stackTrace": "Request"
|
||||||
|
},
|
||||||
|
"data": null
|
||||||
|
}
|
||||||
|
})
|
||||||
|
@ApiResponse({
|
||||||
|
status: 404,
|
||||||
|
description: 'Institute not found',
|
||||||
|
example: {
|
||||||
|
"notification": {
|
||||||
|
"exception": true,
|
||||||
|
"exceptionSeverity": "HIGH",
|
||||||
|
"exceptionMessage": "ERR.NOT_FOUND",
|
||||||
|
"stackTrace": "Institute not found"
|
||||||
|
},
|
||||||
|
"data": null
|
||||||
|
}
|
||||||
|
})
|
||||||
|
@ApiResponse({
|
||||||
|
status: 201,
|
||||||
|
description: 'Institute successfully created',
|
||||||
|
})
|
||||||
async insert(@Body() institute: Institute, @Res() res: Response) {
|
async insert(@Body() institute: Institute, @Res() res: Response) {
|
||||||
if(!institute) {
|
if (!institute) {
|
||||||
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 institute.id;
|
delete institute.id;
|
||||||
const response = await this.instituteService.upsert(institute, true);
|
const response = await this.instituteService.upsert(institute, true);
|
||||||
const httpResponse = new GenericResponse(null, response)
|
if (!response) {
|
||||||
res.send(httpResponse);
|
const errorResponse = new GenericResponse({
|
||||||
|
exception: true,
|
||||||
|
exceptionSeverity: 'HIGH',
|
||||||
|
exceptionMessage: 'ERR.INVALID_DATA',
|
||||||
|
stackTrace: 'Institute data invalid'
|
||||||
|
}, null);
|
||||||
|
return res.status(404).send(errorResponse);
|
||||||
|
}
|
||||||
|
const httpResponse = new GenericResponse(null, response);
|
||||||
|
res.status(201).send(httpResponse);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Put()
|
@Put()
|
||||||
|
@ApiOperation({ summary: 'Update an existing institute' })
|
||||||
|
@ApiBody({ type: Institute, description: 'Institute data to update' })
|
||||||
|
@ApiResponse({
|
||||||
|
status: 400,
|
||||||
|
description: 'Invalid institute data or ID is missing',
|
||||||
|
example: {
|
||||||
|
"notification": {
|
||||||
|
"exception": true,
|
||||||
|
"exceptionSeverity": "HIGH",
|
||||||
|
"exceptionMessage": "ERR.INVALID_DATA",
|
||||||
|
"stackTrace": "Institute data or ID missing"
|
||||||
|
},
|
||||||
|
"data": null
|
||||||
|
}
|
||||||
|
})
|
||||||
|
@ApiResponse({
|
||||||
|
status: 404,
|
||||||
|
description: 'Institute not found',
|
||||||
|
example: {
|
||||||
|
"notification": {
|
||||||
|
"exception": true,
|
||||||
|
"exceptionSeverity": "HIGH",
|
||||||
|
"exceptionMessage": "ERR.NOT_FOUND",
|
||||||
|
"stackTrace": "Institute not found"
|
||||||
|
},
|
||||||
|
"data": null
|
||||||
|
}
|
||||||
|
})
|
||||||
|
@ApiResponse({
|
||||||
|
status: 200,
|
||||||
|
description: 'Institute successfully updated',
|
||||||
|
})
|
||||||
async update(@Body() institute: Institute, @Res() res: Response) {
|
async update(@Body() institute: Institute, @Res() res: Response) {
|
||||||
if(!Institute || !institute.id) {
|
if (!institute || !institute.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.instituteService.upsert(institute, false);
|
const response = await this.instituteService.upsert(institute, 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: `Institute with ID ${institute.id} not found`
|
||||||
|
}, null);
|
||||||
|
return res.status(404).send(errorResponse);
|
||||||
|
}
|
||||||
|
const httpResponse = new GenericResponse(null, response);
|
||||||
|
res.status(200).send(httpResponse);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Delete(':id')
|
@Delete(':id')
|
||||||
|
@ApiOperation({ summary: 'Delete an institute by ID' })
|
||||||
|
@ApiParam({ name: 'id', type: Number, description: 'Institute 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: 'Institute not found',
|
||||||
|
example: {
|
||||||
|
"notification": {
|
||||||
|
"exception": true,
|
||||||
|
"exceptionSeverity": "HIGH",
|
||||||
|
"exceptionMessage": "ERR.NOT_FOUND",
|
||||||
|
"stackTrace": "Institute not found"
|
||||||
|
},
|
||||||
|
"data": null
|
||||||
|
}
|
||||||
|
})
|
||||||
|
@ApiResponse({
|
||||||
|
status: 200,
|
||||||
|
description: 'Institute 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.instituteService.remove(id) || {};
|
const response = await this.instituteService.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: `Institute with ID ${id} not found`
|
||||||
|
}, null);
|
||||||
|
return res.status(404).send(errorResponse);
|
||||||
|
}
|
||||||
|
const httpResponse = new GenericResponse(null, response);
|
||||||
|
res.status(200).send(httpResponse);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,36 +1,41 @@
|
|||||||
import { Table, Column, Model, Default, DataType, HasMany, Unique } from 'sequelize-typescript';
|
import { Table, Column, Model, Default, DataType, Unique } from 'sequelize-typescript';
|
||||||
import InstituteAdditionalDetail from './institute-additional-details/institute-additional-details.entity';
|
import { ApiProperty } from '@nestjs/swagger';
|
||||||
|
|
||||||
@Table({ tableName: 'institute' , paranoid : true})
|
@Table({ tableName: 'institute', paranoid: true })
|
||||||
export default class Institute extends Model {
|
export default class Institute extends Model {
|
||||||
|
|
||||||
|
@ApiProperty({ type: String })
|
||||||
@Unique(true)
|
@Unique(true)
|
||||||
@Column({ type: DataType.TEXT })
|
@Column({ type: DataType.TEXT })
|
||||||
instituteCode: string;
|
instituteCode: string;
|
||||||
|
|
||||||
|
@ApiProperty({ type: String })
|
||||||
@Column({ type: DataType.TEXT })
|
@Column({ type: DataType.TEXT })
|
||||||
instituteName: string;
|
instituteName: string;
|
||||||
|
|
||||||
|
@ApiProperty({ type: String })
|
||||||
@Column({ type: DataType.TEXT })
|
@Column({ type: DataType.TEXT })
|
||||||
address: string;
|
address: string;
|
||||||
|
|
||||||
|
@ApiProperty({ type: Number })
|
||||||
@Column({ type: DataType.DECIMAL })
|
@Column({ type: DataType.DECIMAL })
|
||||||
lat: number;
|
lat: number;
|
||||||
|
|
||||||
|
@ApiProperty({ type: Number })
|
||||||
@Column({ type: DataType.DECIMAL })
|
@Column({ type: DataType.DECIMAL })
|
||||||
lng: number;
|
lng: number;
|
||||||
|
|
||||||
|
@ApiProperty({ type: String })
|
||||||
@Column({ type: DataType.TEXT })
|
@Column({ type: DataType.TEXT })
|
||||||
status: string;
|
status: 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;
|
||||||
|
|
||||||
// @HasMany(() => InstituteAdditionalDetail)
|
|
||||||
// additionalDetails: InstituteAdditionalDetail[];
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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,19 +7,19 @@ 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
|
||||||
|
|||||||
@ -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();
|
||||||
|
|||||||
@ -3,101 +3,335 @@ import { Response } from 'express';
|
|||||||
import { GenericResponse } from 'src/common/GenericResponse.model';
|
import { GenericResponse } from 'src/common/GenericResponse.model';
|
||||||
import { SubscriptionService } from './subscription.service';
|
import { SubscriptionService } from './subscription.service';
|
||||||
import Subscription from './subscription.entity';
|
import Subscription from './subscription.entity';
|
||||||
|
import { ApiTags, ApiOperation, ApiResponse, ApiParam, ApiBody } from '@nestjs/swagger';
|
||||||
|
|
||||||
|
@ApiTags('subscriptions')
|
||||||
@Controller('subscriptions')
|
@Controller('subscriptions')
|
||||||
export class SubscriptionController {
|
export class SubscriptionController {
|
||||||
constructor(private subscriptionsService: SubscriptionService) {}
|
constructor(private subscriptionsService: SubscriptionService) { }
|
||||||
|
|
||||||
@Get("/all")
|
@Get("/all")
|
||||||
|
@ApiOperation({ summary: 'Get all subscriptions' })
|
||||||
|
@ApiResponse({
|
||||||
|
status: 200,
|
||||||
|
description: 'Successfully retrieved all subscriptions',
|
||||||
|
})
|
||||||
|
@ApiResponse({
|
||||||
|
status: 404,
|
||||||
|
description: 'No subscriptions found',
|
||||||
|
example: {
|
||||||
|
"notification": {
|
||||||
|
"exception": true,
|
||||||
|
"exceptionSeverity": "HIGH",
|
||||||
|
"exceptionMessage": "ERR.NO_SUBSCRIPTIONS",
|
||||||
|
"stackTrace": "No subscriptions found"
|
||||||
|
},
|
||||||
|
"data": null
|
||||||
|
}
|
||||||
|
})
|
||||||
async getAll(@Res() res: Response) {
|
async getAll(@Res() res: Response) {
|
||||||
const response = await this.subscriptionsService.findAll() || [];
|
const response = await this.subscriptionsService.findAll() || [];
|
||||||
const httpResponse = new GenericResponse(null, response)
|
if (!response) {
|
||||||
res.send(httpResponse);
|
const errorResponse = new GenericResponse({
|
||||||
|
exception: true,
|
||||||
|
exceptionSeverity: 'HIGH',
|
||||||
|
exceptionMessage: 'ERR.NO_SUBSCRIPTIONS',
|
||||||
|
stackTrace: 'No subscriptions found'
|
||||||
|
}, null);
|
||||||
|
return res.status(404).send(errorResponse);
|
||||||
|
}
|
||||||
|
const httpResponse = new GenericResponse(null, response);
|
||||||
|
res.status(200).send(httpResponse);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get(':id')
|
@Get(':id')
|
||||||
|
@ApiOperation({ summary: 'Get a subscription by ID' })
|
||||||
|
@ApiParam({ name: 'id', type: Number, description: 'Subscription 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: 'Subscription not found',
|
||||||
|
example: {
|
||||||
|
"notification": {
|
||||||
|
"exception": true,
|
||||||
|
"exceptionSeverity": "HIGH",
|
||||||
|
"exceptionMessage": "ERR.NOT_FOUND",
|
||||||
|
"stackTrace": "Subscription not found"
|
||||||
|
},
|
||||||
|
"data": null
|
||||||
|
}
|
||||||
|
})
|
||||||
|
@ApiResponse({
|
||||||
|
status: 200,
|
||||||
|
description: 'Successfully retrieved subscription by ID',
|
||||||
|
})
|
||||||
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.subscriptionsService.findByPk(id) || {};
|
const response = await this.subscriptionsService.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: `Subscription 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')
|
@Post('/filter')
|
||||||
|
@ApiOperation({ summary: 'Filter subscriptions based on criteria' })
|
||||||
|
@ApiBody({ type: Subscription, description: 'Filter criteria for subscriptions' })
|
||||||
|
@ApiResponse({
|
||||||
|
status: 400,
|
||||||
|
description: 'Filter criteria required',
|
||||||
|
example: {
|
||||||
|
"notification": {
|
||||||
|
"exception": true,
|
||||||
|
"exceptionSeverity": "HIGH",
|
||||||
|
"exceptionMessage": "ERR.NO_REQ_BODY",
|
||||||
|
"stackTrace": "Request"
|
||||||
|
},
|
||||||
|
"data": null
|
||||||
|
}
|
||||||
|
})
|
||||||
|
@ApiResponse({
|
||||||
|
status: 404,
|
||||||
|
description: 'No subscriptions found matching criteria',
|
||||||
|
example: {
|
||||||
|
"notification": {
|
||||||
|
"exception": true,
|
||||||
|
"exceptionSeverity": "HIGH",
|
||||||
|
"exceptionMessage": "ERR.NOT_FOUND",
|
||||||
|
"stackTrace": "No subscriptions found matching criteria"
|
||||||
|
},
|
||||||
|
"data": null
|
||||||
|
}
|
||||||
|
})
|
||||||
|
@ApiResponse({
|
||||||
|
status: 200,
|
||||||
|
description: 'Successfully filtered subscriptions',
|
||||||
|
})
|
||||||
async filter(@Body() subscription: Subscription, @Res() res: Response) {
|
async filter(@Body() subscription: Subscription, @Res() res: Response) {
|
||||||
if(!subscription) {
|
if (!subscription) {
|
||||||
const response = new GenericResponse({
|
const response = new GenericResponse({
|
||||||
exception: true,
|
exception: true,
|
||||||
exceptionSeverity: 'HIGH',
|
exceptionSeverity: 'HIGH',
|
||||||
exceptionMessage: 'ERR.NO_ID_REQ',
|
exceptionMessage: 'ERR.NO_REQ_BODY',
|
||||||
stackTrace: 'Request'
|
stackTrace: 'Request'
|
||||||
}, null);
|
}, null);
|
||||||
res.send(response);
|
res.status(400).send(response);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const response = await this.subscriptionsService.filter(subscription) || {};
|
const response = await this.subscriptionsService.filter(subscription) || {};
|
||||||
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 subscriptions found matching criteria'
|
||||||
|
}, null);
|
||||||
|
return res.status(404).send(errorResponse);
|
||||||
|
}
|
||||||
|
const httpResponse = new GenericResponse(null, response);
|
||||||
|
res.status(200).send(httpResponse);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post()
|
@Post()
|
||||||
|
@ApiOperation({ summary: 'Insert a new subscription' })
|
||||||
|
@ApiBody({ type: Subscription, description: 'Subscription data to insert' })
|
||||||
|
@ApiResponse({
|
||||||
|
status: 400,
|
||||||
|
description: 'Invalid subscription data',
|
||||||
|
example: {
|
||||||
|
"notification": {
|
||||||
|
"exception": true,
|
||||||
|
"exceptionSeverity": "HIGH",
|
||||||
|
"exceptionMessage": "ERR.INVALID_DATA",
|
||||||
|
"stackTrace": "Request"
|
||||||
|
},
|
||||||
|
"data": null
|
||||||
|
}
|
||||||
|
})
|
||||||
|
@ApiResponse({
|
||||||
|
status: 404,
|
||||||
|
description: 'Invalid subscription data',
|
||||||
|
example: {
|
||||||
|
"notification": {
|
||||||
|
"exception": true,
|
||||||
|
"exceptionSeverity": "HIGH",
|
||||||
|
"exceptionMessage": "ERR.INVALID_DATA",
|
||||||
|
"stackTrace": "Subscription data invalid"
|
||||||
|
},
|
||||||
|
"data": null
|
||||||
|
}
|
||||||
|
})
|
||||||
|
@ApiResponse({
|
||||||
|
status: 201,
|
||||||
|
description: 'Subscription successfully created',
|
||||||
|
})
|
||||||
async insert(@Body() subscription: Subscription, @Res() res: Response) {
|
async insert(@Body() subscription: Subscription, @Res() res: Response) {
|
||||||
if(!subscription) {
|
if (!subscription) {
|
||||||
const response = new GenericResponse({
|
const response = new GenericResponse({
|
||||||
exception: true,
|
exception: true,
|
||||||
exceptionSeverity: 'HIGH',
|
exceptionSeverity: 'HIGH',
|
||||||
exceptionMessage: 'ERR.NO_ID_REQ',
|
exceptionMessage: 'ERR.NO_REQ_BODY',
|
||||||
stackTrace: 'Request'
|
stackTrace: 'Request'
|
||||||
}, null);
|
}, null);
|
||||||
res.send(response);
|
res.status(400).send(response);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
delete subscription.id;
|
delete subscription.id;
|
||||||
const response = await this.subscriptionsService.upsert(subscription, true);
|
const response = await this.subscriptionsService.upsert(subscription, true);
|
||||||
const httpResponse = new GenericResponse(null, response)
|
if (!response) {
|
||||||
res.send(httpResponse);
|
const errorResponse = new GenericResponse({
|
||||||
|
exception: true,
|
||||||
|
exceptionSeverity: 'HIGH',
|
||||||
|
exceptionMessage: 'ERR.INVALID_DATA',
|
||||||
|
stackTrace: 'Subscription data invalid'
|
||||||
|
}, null);
|
||||||
|
return res.status(400).send(errorResponse);
|
||||||
|
}
|
||||||
|
const httpResponse = new GenericResponse(null, response);
|
||||||
|
res.status(201).send(httpResponse);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Put()
|
@Put()
|
||||||
|
@ApiOperation({ summary: 'Update an existing subscription' })
|
||||||
|
@ApiBody({ type: Subscription, description: 'Subscription data to update' })
|
||||||
|
@ApiResponse({
|
||||||
|
status: 400,
|
||||||
|
description: 'Invalid subscription data or ID is missing',
|
||||||
|
example: {
|
||||||
|
"notification": {
|
||||||
|
"exception": true,
|
||||||
|
"exceptionSeverity": "HIGH",
|
||||||
|
"exceptionMessage": "ERR.INVALID_DATA",
|
||||||
|
"stackTrace": "Subscription data or ID missing"
|
||||||
|
},
|
||||||
|
"data": null
|
||||||
|
}
|
||||||
|
})
|
||||||
|
@ApiResponse({
|
||||||
|
status: 404,
|
||||||
|
description: 'Subscription not found',
|
||||||
|
example: {
|
||||||
|
"notification": {
|
||||||
|
"exception": true,
|
||||||
|
"exceptionSeverity": "HIGH",
|
||||||
|
"exceptionMessage": "ERR.NOT_FOUND",
|
||||||
|
"stackTrace": "Subscription not found"
|
||||||
|
},
|
||||||
|
"data": null
|
||||||
|
}
|
||||||
|
})
|
||||||
|
@ApiResponse({
|
||||||
|
status: 200,
|
||||||
|
description: 'Subscription successfully updated',
|
||||||
|
})
|
||||||
async update(@Body() subscription: Subscription, @Res() res: Response) {
|
async update(@Body() subscription: Subscription, @Res() res: Response) {
|
||||||
if(!subscription || !subscription.id) {
|
if (!subscription || !subscription.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.subscriptionsService.upsert(subscription, false);
|
const response = await this.subscriptionsService.upsert(subscription, 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: 'Subscription not found'
|
||||||
|
}, null);
|
||||||
|
return res.status(404).send(errorResponse);
|
||||||
|
}
|
||||||
|
const httpResponse = new GenericResponse(null, response);
|
||||||
|
res.status(200).send(httpResponse);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Delete(':id')
|
@Delete(':id')
|
||||||
|
@ApiOperation({ summary: 'Delete a subscription by ID' })
|
||||||
|
@ApiParam({ name: 'id', type: Number, description: 'Subscription 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: 'Subscription not found',
|
||||||
|
example: {
|
||||||
|
"notification": {
|
||||||
|
"exception": true,
|
||||||
|
"exceptionSeverity": "HIGH",
|
||||||
|
"exceptionMessage": "ERR.NOT_FOUND",
|
||||||
|
"stackTrace": "Subscription not found"
|
||||||
|
},
|
||||||
|
"data": null
|
||||||
|
}
|
||||||
|
})
|
||||||
|
@ApiResponse({
|
||||||
|
status: 200,
|
||||||
|
description: 'Subscription 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.subscriptionsService.remove(id) || {};
|
const response = await this.subscriptionsService.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: `Subscription with ID ${id} not found`
|
||||||
|
}, null);
|
||||||
|
return res.status(404).send(errorResponse);
|
||||||
|
}
|
||||||
|
const httpResponse = new GenericResponse(null, response);
|
||||||
|
res.status(200).send(httpResponse);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,55 +1,70 @@
|
|||||||
import { Table, Column, Model, Default, DataType, ForeignKey } from 'sequelize-typescript';
|
import { Table, Column, Model, Default, DataType, ForeignKey } from 'sequelize-typescript';
|
||||||
|
import { ApiProperty } from '@nestjs/swagger';
|
||||||
import { User } from 'src/user/user.entity';
|
import { User } from 'src/user/user.entity';
|
||||||
|
|
||||||
@Table({ tableName: 'subscription', timestamps: true , paranoid : true})
|
@Table({ tableName: 'subscription', timestamps: true, paranoid: true })
|
||||||
export default class Subscription extends Model {
|
export default class Subscription extends Model {
|
||||||
|
|
||||||
|
@ApiProperty({ type: Number })
|
||||||
@Column({ type: DataType.BIGINT, primaryKey: true, autoIncrement: true })
|
@Column({ type: DataType.BIGINT, primaryKey: true, autoIncrement: true })
|
||||||
id: number;
|
id: number;
|
||||||
|
|
||||||
|
@ApiProperty({ type: Number })
|
||||||
@ForeignKey(() => User)
|
@ForeignKey(() => User)
|
||||||
@Column({ type: DataType.BIGINT })
|
@Column({ type: DataType.BIGINT })
|
||||||
user_id: number;
|
user_id: number;
|
||||||
|
|
||||||
|
@ApiProperty({ type: String })
|
||||||
@Column({ type: DataType.TEXT })
|
@Column({ type: DataType.TEXT })
|
||||||
plan_type: string;
|
plan_type: string;
|
||||||
|
|
||||||
|
@ApiProperty({ type: Date })
|
||||||
@Column({ type: DataType.DATEONLY })
|
@Column({ type: DataType.DATEONLY })
|
||||||
start_date: Date;
|
start_date: Date;
|
||||||
|
|
||||||
|
@ApiProperty({ type: Date })
|
||||||
@Column({ type: DataType.DATEONLY })
|
@Column({ type: DataType.DATEONLY })
|
||||||
end_date: Date;
|
end_date: Date;
|
||||||
|
|
||||||
@Default(true)
|
@ApiProperty({ type: Boolean})
|
||||||
@Column({ type: DataType.BOOLEAN })
|
@Column({ type: DataType.BOOLEAN })
|
||||||
is_active: boolean;
|
is_active: boolean;
|
||||||
|
|
||||||
|
@ApiProperty({ type: String })
|
||||||
@Column({ type: DataType.TEXT })
|
@Column({ type: DataType.TEXT })
|
||||||
status: string;
|
status: 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: Date })
|
||||||
@Column({ type: DataType.DATE })
|
@Column({ type: DataType.DATE })
|
||||||
createdAt: Date;
|
createdAt: Date;
|
||||||
|
|
||||||
|
@ApiProperty({ type: Date })
|
||||||
@Column({ type: DataType.DATE })
|
@Column({ type: DataType.DATE })
|
||||||
updatedAt: Date;
|
updatedAt: 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;
|
||||||
|
|
||||||
|
@ApiProperty({ type: Date })
|
||||||
@Column({ type: DataType.DATE })
|
@Column({ type: DataType.DATE })
|
||||||
deletedAt: Date;
|
deletedAt: Date;
|
||||||
|
|
||||||
|
@ApiProperty({ type: Number })
|
||||||
@Column({ type: DataType.INTEGER })
|
@Column({ type: DataType.INTEGER })
|
||||||
version: number;
|
version: number;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,20 +3,81 @@ import { Response } from 'express';
|
|||||||
import { UserAdditionalDetailsService } from './user-additional-details.service';
|
import { UserAdditionalDetailsService } from './user-additional-details.service';
|
||||||
import { GenericResponse } from 'src/common/GenericResponse.model';
|
import { GenericResponse } from 'src/common/GenericResponse.model';
|
||||||
import UserAdditionalDetail from './user-additional-details.entity';
|
import UserAdditionalDetail from './user-additional-details.entity';
|
||||||
|
import { ApiTags, ApiOperation, ApiResponse, ApiParam, ApiBody } from '@nestjs/swagger';
|
||||||
|
|
||||||
|
@ApiTags('user-additional-details')
|
||||||
@Controller('users/addl/')
|
@Controller('users/addl/')
|
||||||
export class UserAdditionalDetailsController {
|
export class UserAdditionalDetailsController {
|
||||||
constructor(private userAdditionalDetailsService: UserAdditionalDetailsService) { }
|
constructor(private userAdditionalDetailsService: UserAdditionalDetailsService) { }
|
||||||
|
|
||||||
@Get("/all")
|
@Get("/all")
|
||||||
async userTypegetAll(@Res() res: Response) {
|
@ApiOperation({ summary: 'Get all user additional details' })
|
||||||
|
@ApiResponse({
|
||||||
|
status: 200,
|
||||||
|
description: 'Successfully retrieved all user additional details',
|
||||||
|
})
|
||||||
|
@ApiResponse({
|
||||||
|
status: 404,
|
||||||
|
description: 'No user additional details found',
|
||||||
|
example: {
|
||||||
|
"notification": {
|
||||||
|
"exception": true,
|
||||||
|
"exceptionSeverity": "HIGH",
|
||||||
|
"exceptionMessage": "ERR.NOT_FOUND",
|
||||||
|
"stackTrace": "No user additional details found"
|
||||||
|
},
|
||||||
|
"data": null
|
||||||
|
}
|
||||||
|
})
|
||||||
|
async userAdditionalDetailsgetAll(@Res() res: Response) {
|
||||||
const response = await this.userAdditionalDetailsService.findAll() || [];
|
const response = await this.userAdditionalDetailsService.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 user additional details found'
|
||||||
|
}, null);
|
||||||
|
return res.status(404).send(errorResponse);
|
||||||
|
}
|
||||||
|
const httpResponse = new GenericResponse(null, response);
|
||||||
|
res.status(200).send(httpResponse);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get(':id')
|
@Get(':id')
|
||||||
async userTypeFindById(@Param('id') id: number, @Res() res: Response) {
|
@ApiOperation({ summary: 'Get user additional details by ID' })
|
||||||
|
@ApiParam({ name: 'id', type: Number, description: 'User Additional Details 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: 'User additional details not found',
|
||||||
|
example: {
|
||||||
|
"notification": {
|
||||||
|
"exception": true,
|
||||||
|
"exceptionSeverity": "HIGH",
|
||||||
|
"exceptionMessage": "ERR.NOT_FOUND",
|
||||||
|
"stackTrace": "User additional details not found"
|
||||||
|
},
|
||||||
|
"data": null
|
||||||
|
}
|
||||||
|
})
|
||||||
|
@ApiResponse({
|
||||||
|
status: 200,
|
||||||
|
description: 'Successfully retrieved user additional details by ID',
|
||||||
|
})
|
||||||
|
async userAdditionalDetailsFindById(@Param('id') id: number, @Res() res: Response) {
|
||||||
if (!id) {
|
if (!id) {
|
||||||
const response = new GenericResponse({
|
const response = new GenericResponse({
|
||||||
exception: true,
|
exception: true,
|
||||||
@ -24,16 +85,58 @@ export class UserAdditionalDetailsController {
|
|||||||
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.userAdditionalDetailsService.findByPk(id) || {};
|
const response = await this.userAdditionalDetailsService.findByPk(id) || {};
|
||||||
const httpResponse = new GenericResponse(null, response)
|
if(!response) {
|
||||||
res.send(httpResponse);
|
const response = new GenericResponse({
|
||||||
|
exception: true,
|
||||||
|
exceptionSeverity: 'HIGH',
|
||||||
|
exceptionMessage: 'ERR.NOT_FOUND',
|
||||||
|
stackTrace: 'User additional details not found'
|
||||||
|
}, null);
|
||||||
|
res.status(404).send(response);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const httpResponse = new GenericResponse(null, response);
|
||||||
|
res.status(200).send(httpResponse);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post('/filter')
|
@Post('/filter')
|
||||||
async userTypeFilter(@Body() user: UserAdditionalDetail, @Res() res: Response) {
|
@ApiOperation({ summary: 'Filter user additional details based on criteria' })
|
||||||
|
@ApiBody({ type: UserAdditionalDetail, description: 'User additional detail filter criteria' })
|
||||||
|
@ApiResponse({
|
||||||
|
status: 400,
|
||||||
|
description: 'Request body is missing',
|
||||||
|
example: {
|
||||||
|
"notification": {
|
||||||
|
"exception": true,
|
||||||
|
"exceptionSeverity": "HIGH",
|
||||||
|
"exceptionMessage": "ERR.NO_REQ",
|
||||||
|
"stackTrace": "Request"
|
||||||
|
},
|
||||||
|
"data": null
|
||||||
|
}
|
||||||
|
})
|
||||||
|
@ApiResponse({
|
||||||
|
status: 404,
|
||||||
|
description: 'No user additional details found matching criteria',
|
||||||
|
example: {
|
||||||
|
"notification": {
|
||||||
|
"exception": true,
|
||||||
|
"exceptionSeverity": "HIGH",
|
||||||
|
"exceptionMessage": "ERR.NOT_FOUND",
|
||||||
|
"stackTrace": "No user additional details found matching criteria"
|
||||||
|
},
|
||||||
|
"data": null
|
||||||
|
}
|
||||||
|
})
|
||||||
|
@ApiResponse({
|
||||||
|
status: 200,
|
||||||
|
description: 'Successfully filtered user additional details',
|
||||||
|
})
|
||||||
|
async userAdditionalDetailsFilter(@Body() user: UserAdditionalDetail, @Res() res: Response) {
|
||||||
if (!user) {
|
if (!user) {
|
||||||
const response = new GenericResponse({
|
const response = new GenericResponse({
|
||||||
exception: true,
|
exception: true,
|
||||||
@ -41,16 +144,57 @@ export class UserAdditionalDetailsController {
|
|||||||
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.userAdditionalDetailsService.filter(user) || [];
|
const response = await this.userAdditionalDetailsService.filter(user) || [];
|
||||||
const httpResponse = new GenericResponse(null, response)
|
if (!response) {
|
||||||
res.send(httpResponse);
|
const response = new GenericResponse({
|
||||||
|
exception: true,
|
||||||
|
exceptionSeverity: 'HIGH',
|
||||||
|
exceptionMessage: 'ERR.NOT_FOUND',
|
||||||
|
stackTrace: 'No user additional details found matching criteria'
|
||||||
|
}, null);
|
||||||
|
res.status(404).send(response);
|
||||||
|
}
|
||||||
|
const httpResponse = new GenericResponse(null, response);
|
||||||
|
res.status(200).send(httpResponse);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post()
|
@Post()
|
||||||
async userTypeInsert(@Body() user: UserAdditionalDetail, @Res() res: Response) {
|
@ApiOperation({ summary: 'Insert a new user additional detail' })
|
||||||
|
@ApiBody({ type: UserAdditionalDetail, description: 'User additional detail data to insert' })
|
||||||
|
@ApiResponse({
|
||||||
|
status: 400,
|
||||||
|
description: 'Failed to insert user additional detail',
|
||||||
|
example: {
|
||||||
|
"notification": {
|
||||||
|
"exception": true,
|
||||||
|
"exceptionSeverity": "HIGH",
|
||||||
|
"exceptionMessage": "ERR.NOT_CREATED",
|
||||||
|
"stackTrace": "Request"
|
||||||
|
},
|
||||||
|
"data": null
|
||||||
|
}
|
||||||
|
})
|
||||||
|
@ApiResponse({
|
||||||
|
status: 404,
|
||||||
|
description: 'User additional detail not found',
|
||||||
|
example: {
|
||||||
|
"notification": {
|
||||||
|
"exception": true,
|
||||||
|
"exceptionSeverity": "HIGH",
|
||||||
|
"exceptionMessage": "ERR.NOT_FOUND",
|
||||||
|
"stackTrace": "User additional detail not found"
|
||||||
|
},
|
||||||
|
"data": null
|
||||||
|
}
|
||||||
|
})
|
||||||
|
@ApiResponse({
|
||||||
|
status: 201,
|
||||||
|
description: 'User additional detail successfully created',
|
||||||
|
})
|
||||||
|
async userAdditionalDetailsInsert(@Body() user: UserAdditionalDetail, @Res() res: Response) {
|
||||||
if (!user) {
|
if (!user) {
|
||||||
const response = new GenericResponse({
|
const response = new GenericResponse({
|
||||||
exception: true,
|
exception: true,
|
||||||
@ -58,17 +202,59 @@ export class UserAdditionalDetailsController {
|
|||||||
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 user.id;
|
||||||
const response = await this.userAdditionalDetailsService.upsert(user, true);
|
const response = await this.userAdditionalDetailsService.upsert(user, true);
|
||||||
const httpResponse = new GenericResponse(null, response)
|
if (!response) {
|
||||||
res.send(httpResponse);
|
const response = new GenericResponse({
|
||||||
|
exception: true,
|
||||||
|
exceptionSeverity: 'HIGH',
|
||||||
|
exceptionMessage: 'ERR.NOT_CREATED',
|
||||||
|
stackTrace: 'User additional detail not created'
|
||||||
|
}, null);
|
||||||
|
res.status(404).send(response);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const httpResponse = new GenericResponse(null, response);
|
||||||
|
res.status(201).send(httpResponse);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Put()
|
@Put()
|
||||||
async userTypeUpdate(@Body() user: UserAdditionalDetail, @Res() res: Response) {
|
@ApiOperation({ summary: 'Update an existing user additional detail' })
|
||||||
|
@ApiBody({ type: UserAdditionalDetail, description: 'User additional detail data to update' })
|
||||||
|
@ApiResponse({
|
||||||
|
status: 400,
|
||||||
|
description: 'Failed to update user additional detail',
|
||||||
|
example: {
|
||||||
|
"notification": {
|
||||||
|
"exception": true,
|
||||||
|
"exceptionSeverity": "HIGH",
|
||||||
|
"exceptionMessage": "ERR.NOT_UPDATED",
|
||||||
|
"stackTrace": "User additional detail not updated"
|
||||||
|
},
|
||||||
|
"data": null
|
||||||
|
}
|
||||||
|
})
|
||||||
|
@ApiResponse({
|
||||||
|
status: 404,
|
||||||
|
description: 'User additional detail not found',
|
||||||
|
example: {
|
||||||
|
"notification": {
|
||||||
|
"exception": true,
|
||||||
|
"exceptionSeverity": "HIGH",
|
||||||
|
"exceptionMessage": "ERR.NOT_FOUND",
|
||||||
|
"stackTrace": "User additional detail not found"
|
||||||
|
},
|
||||||
|
"data": null
|
||||||
|
}
|
||||||
|
})
|
||||||
|
@ApiResponse({
|
||||||
|
status: 200,
|
||||||
|
description: 'User additional detail successfully updated',
|
||||||
|
})
|
||||||
|
async userAdditionalDetailsUpdate(@Body() user: UserAdditionalDetail, @Res() res: Response) {
|
||||||
if (!user || !user.id) {
|
if (!user || !user.id) {
|
||||||
const response = new GenericResponse({
|
const response = new GenericResponse({
|
||||||
exception: true,
|
exception: true,
|
||||||
@ -76,28 +262,79 @@ export class UserAdditionalDetailsController {
|
|||||||
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.userAdditionalDetailsService.upsert(user, false);
|
const response = await this.userAdditionalDetailsService.upsert(user, 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: 'User additional detail not found'
|
||||||
|
}, null);
|
||||||
|
return res.status(404).send(errorResponse);
|
||||||
|
}
|
||||||
|
const httpResponse = new GenericResponse(null, response);
|
||||||
|
res.status(200).send(httpResponse);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Delete(':id')
|
@Delete(':id')
|
||||||
async userTypeDeleteById(@Param('id') id: number, @Res() res: Response) {
|
@ApiOperation({ summary: 'Delete user additional detail by ID' })
|
||||||
|
@ApiParam({ name: 'id', type: Number, description: 'User additional detail 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: 'User additional detail not found',
|
||||||
|
example: {
|
||||||
|
"notification": {
|
||||||
|
"exception": true,
|
||||||
|
"exceptionSeverity": "HIGH",
|
||||||
|
"exceptionMessage": "ERR.NOT_FOUND",
|
||||||
|
"stackTrace": "User additional detail not found"
|
||||||
|
},
|
||||||
|
"data": null
|
||||||
|
}
|
||||||
|
})
|
||||||
|
@ApiResponse({
|
||||||
|
status: 200,
|
||||||
|
description: 'User additional detail successfully deleted',
|
||||||
|
})
|
||||||
|
async userAdditionalDetailsDeleteById(@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.userAdditionalDetailsService.remove(id) || {};
|
const response = await this.userAdditionalDetailsService.remove(id) || {};
|
||||||
const httpResponse = new GenericResponse(null, response)
|
if (!response) {
|
||||||
res.send(httpResponse);
|
const response = new GenericResponse({
|
||||||
|
exception: true,
|
||||||
|
exceptionSeverity: 'HIGH',
|
||||||
|
exceptionMessage: 'ERR.NOT_FOUND',
|
||||||
|
stackTrace: 'User additional detail not found'
|
||||||
|
}, null);
|
||||||
|
res.status(404).send(response);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const httpResponse = new GenericResponse(null, response);
|
||||||
|
res.status(200).send(httpResponse);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,31 +1,38 @@
|
|||||||
import { Table, Column, Model, Default, DataType, ForeignKey, BelongsTo } from 'sequelize-typescript';
|
import { Table, Column, Model, Default, DataType, ForeignKey, BelongsTo } from 'sequelize-typescript';
|
||||||
|
import { ApiProperty } from '@nestjs/swagger';
|
||||||
import { User } from '../user.entity';
|
import { User } from '../user.entity';
|
||||||
|
|
||||||
@Table({tableName: 'user_additional_details', paranoid : true})
|
@Table({ tableName: 'user_additional_details', paranoid: true })
|
||||||
export default class UserAdditionalDetail extends Model {
|
export default class UserAdditionalDetail extends Model {
|
||||||
|
|
||||||
@Column({type: DataType.TEXT})
|
@ApiProperty({ type: String })
|
||||||
|
@Column({ type: DataType.TEXT })
|
||||||
addlDataType: string;
|
addlDataType: string;
|
||||||
|
|
||||||
@Column({type: DataType.NUMBER})
|
@ApiProperty({ type: Number })
|
||||||
@ForeignKey(() => User)
|
@ForeignKey(() => User)
|
||||||
|
@Column({ type: DataType.NUMBER })
|
||||||
userId: number;
|
userId: number;
|
||||||
|
|
||||||
@Column({type: DataType.TEXT})
|
@ApiProperty({ type: String })
|
||||||
|
@Column({ type: DataType.TEXT })
|
||||||
addlDataName: string;
|
addlDataName: 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;
|
||||||
|
|
||||||
@Column({type: DataType.TEXT})
|
@ApiProperty({ type: String })
|
||||||
|
@Column({ type: DataType.TEXT })
|
||||||
createBy: string;
|
createBy: string;
|
||||||
|
|
||||||
@Column({type: DataType.TEXT})
|
@ApiProperty({ type: String })
|
||||||
|
@Column({ type: DataType.TEXT })
|
||||||
modifiedBy: string;
|
modifiedBy: string;
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -1,108 +1,312 @@
|
|||||||
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 UserType from './user-type.entity';
|
import UserType from './user-type.entity';
|
||||||
import { UserTypesService } from './user-types.service';
|
import { UserTypesService } from './user-types.service';
|
||||||
|
import { ApiTags, ApiOperation, ApiResponse, ApiParam, ApiBody } from '@nestjs/swagger';
|
||||||
|
|
||||||
|
@ApiTags('user-types')
|
||||||
@Controller('users/types')
|
@Controller('users/types')
|
||||||
export class UserTypesController {
|
export class UserTypesController {
|
||||||
|
|
||||||
constructor(private userTypeService?: UserTypesService) {
|
constructor(private userTypeService: UserTypesService) { }
|
||||||
if(!userTypeService) {
|
|
||||||
userTypeService = new UserTypesService();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Get("/all")
|
@Get("/all")
|
||||||
|
@ApiOperation({ summary: 'Get all user types' })
|
||||||
|
@ApiResponse({
|
||||||
|
status: 200,
|
||||||
|
description: 'Successfully retrieved all user types',
|
||||||
|
})
|
||||||
|
@ApiResponse({
|
||||||
|
status: 404,
|
||||||
|
description: 'No user types found',
|
||||||
|
example: {
|
||||||
|
"notification": {
|
||||||
|
"exception": true,
|
||||||
|
"exceptionSeverity": "HIGH",
|
||||||
|
"exceptionMessage": "ERR.NOT_FOUND",
|
||||||
|
"stackTrace": "No user types found"
|
||||||
|
},
|
||||||
|
"data": null
|
||||||
|
}
|
||||||
|
})
|
||||||
async userTypegetAll(@Res() res: Response) {
|
async userTypegetAll(@Res() res: Response) {
|
||||||
const response = await this.userTypeService.findAll() || [];
|
const response = await this.userTypeService.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 user types found'
|
||||||
|
}, null);
|
||||||
|
return res.status(404).send(errorResponse);
|
||||||
|
}
|
||||||
|
const httpResponse = new GenericResponse(null, response);
|
||||||
|
res.status(200).send(httpResponse);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get(':id')
|
@Get(':id')
|
||||||
|
@ApiOperation({ summary: 'Get user type by ID' })
|
||||||
|
@ApiParam({ name: 'id', type: Number, description: 'User Type 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: 'User type not found',
|
||||||
|
example: {
|
||||||
|
"notification": {
|
||||||
|
"exception": true,
|
||||||
|
"exceptionSeverity": "HIGH",
|
||||||
|
"exceptionMessage": "ERR.NOT_FOUND",
|
||||||
|
"stackTrace": "User type not found"
|
||||||
|
},
|
||||||
|
"data": null
|
||||||
|
}
|
||||||
|
})
|
||||||
|
@ApiResponse({
|
||||||
|
status: 200,
|
||||||
|
description: 'Successfully retrieved user type by ID',
|
||||||
|
})
|
||||||
async userTypeFindById(@Param('id') id: number, @Res() res: Response) {
|
async userTypeFindById(@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.userTypeService.findByPk(id) || {};
|
const response = await this.userTypeService.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: 'User type not found'
|
||||||
|
}, null);
|
||||||
|
return res.status(404).send(errorResponse);
|
||||||
|
}
|
||||||
|
const httpResponse = new GenericResponse(null, response);
|
||||||
|
res.status(200).send(httpResponse);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post('/filter')
|
@Post('/filter')
|
||||||
|
@ApiOperation({ summary: 'Filter user types based on criteria' })
|
||||||
|
@ApiBody({ type: UserType, description: 'User type filter criteria' })
|
||||||
|
@ApiResponse({
|
||||||
|
status: 404,
|
||||||
|
description: 'No user types matching criteria found',
|
||||||
|
example: {
|
||||||
|
"notification": {
|
||||||
|
"exception": true,
|
||||||
|
"exceptionSeverity": "HIGH",
|
||||||
|
"exceptionMessage": "ERR.NOT_FOUND",
|
||||||
|
"stackTrace": "No user types found matching criteria"
|
||||||
|
},
|
||||||
|
"data": null
|
||||||
|
}
|
||||||
|
})
|
||||||
|
@ApiResponse({
|
||||||
|
status: 200,
|
||||||
|
description: 'Successfully filtered user types',
|
||||||
|
})
|
||||||
async userTypeFilter(@Body() user: UserType, @Res() res: Response) {
|
async userTypeFilter(@Body() user: UserType, @Res() res: Response) {
|
||||||
if(!user) {
|
if (!user) {
|
||||||
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.userTypeService.filter(user) || [];
|
const response = await this.userTypeService.filter(user) || [];
|
||||||
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 user types found matching criteria'
|
||||||
|
}, null);
|
||||||
|
return res.status(404).send(errorResponse);
|
||||||
|
}
|
||||||
|
const httpResponse = new GenericResponse(null, response);
|
||||||
|
res.status(200).send(httpResponse);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post()
|
@Post()
|
||||||
|
@ApiOperation({ summary: 'Insert a new user type' })
|
||||||
|
@ApiBody({ type: UserType, description: 'User type data to insert' })
|
||||||
|
@ApiResponse({
|
||||||
|
status: 400,
|
||||||
|
description: 'Failed to insert user type',
|
||||||
|
example: {
|
||||||
|
"notification": {
|
||||||
|
"exception": true,
|
||||||
|
"exceptionSeverity": "HIGH",
|
||||||
|
"exceptionMessage": "ERR.NOT_CREATED",
|
||||||
|
"stackTrace": "User type not created"
|
||||||
|
},
|
||||||
|
"data": null
|
||||||
|
}
|
||||||
|
})
|
||||||
|
@ApiResponse({
|
||||||
|
status: 201,
|
||||||
|
description: 'User type successfully created',
|
||||||
|
})
|
||||||
async userTypeInsert(@Body() user: UserType, @Res() res: Response) {
|
async userTypeInsert(@Body() user: UserType, @Res() res: Response) {
|
||||||
if(!user) {
|
if (!user) {
|
||||||
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 user.id;
|
||||||
const response = await this.userTypeService.upsert(user, true);
|
const response = await this.userTypeService.upsert(user, 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: 'User type not created'
|
||||||
|
}, null);
|
||||||
|
return res.status(404).send(errorResponse);
|
||||||
|
}
|
||||||
|
const httpResponse = new GenericResponse(null, response);
|
||||||
|
res.status(201).send(httpResponse);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Put()
|
@Put()
|
||||||
|
@ApiOperation({ summary: 'Update an existing user type' })
|
||||||
|
@ApiBody({ type: UserType, description: 'User type data to update' })
|
||||||
|
@ApiResponse({
|
||||||
|
status: 400,
|
||||||
|
description: 'Failed to update user type',
|
||||||
|
example: {
|
||||||
|
"notification": {
|
||||||
|
"exception": true,
|
||||||
|
"exceptionSeverity": "HIGH",
|
||||||
|
"exceptionMessage": "ERR.NOT_UPDATED",
|
||||||
|
"stackTrace": "User type not updated"
|
||||||
|
},
|
||||||
|
"data": null
|
||||||
|
}
|
||||||
|
})
|
||||||
|
@ApiResponse({
|
||||||
|
status: 404,
|
||||||
|
description: 'User type not found',
|
||||||
|
example: {
|
||||||
|
"notification": {
|
||||||
|
"exception": true,
|
||||||
|
"exceptionSeverity": "HIGH",
|
||||||
|
"exceptionMessage": "ERR.NOT_FOUND",
|
||||||
|
"stackTrace": "User type not found"
|
||||||
|
},
|
||||||
|
"data": null
|
||||||
|
}
|
||||||
|
})
|
||||||
|
@ApiResponse({
|
||||||
|
status: 200,
|
||||||
|
description: 'User type successfully updated',
|
||||||
|
})
|
||||||
async userTypeUpdate(@Body() user: UserType, @Res() res: Response) {
|
async userTypeUpdate(@Body() user: UserType, @Res() res: Response) {
|
||||||
if(!user || !user.id) {
|
if (!user || !user.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.userTypeService.upsert(user, false);
|
const response = await this.userTypeService.upsert(user, 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: 'User type not found'
|
||||||
|
}, null);
|
||||||
|
return res.status(404).send(errorResponse);
|
||||||
|
}
|
||||||
|
const httpResponse = new GenericResponse(null, response);
|
||||||
|
res.status(200).send(httpResponse);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Delete(':id')
|
@Delete(':id')
|
||||||
|
@ApiOperation({ summary: 'Delete a user type by ID' })
|
||||||
|
@ApiParam({ name: 'id', type: Number, description: 'User type 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: 'User type not found',
|
||||||
|
example: {
|
||||||
|
"notification": {
|
||||||
|
"exception": true,
|
||||||
|
"exceptionSeverity": "HIGH",
|
||||||
|
"exceptionMessage": "ERR.NOT_FOUND",
|
||||||
|
"stackTrace": "User type not found"
|
||||||
|
},
|
||||||
|
"data": null
|
||||||
|
}
|
||||||
|
})
|
||||||
|
@ApiResponse({
|
||||||
|
status: 200,
|
||||||
|
description: 'User type successfully deleted',
|
||||||
|
})
|
||||||
async userTypeDeleteById(@Param('id') id: number, @Res() res: Response) {
|
async userTypeDeleteById(@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.userTypeService.remove(id) || {};
|
const response = await this.userTypeService.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: 'User type not found'
|
||||||
|
}, null);
|
||||||
|
return res.status(404).send(errorResponse);
|
||||||
|
}
|
||||||
|
const httpResponse = new GenericResponse(null, response);
|
||||||
|
res.status(200).send(httpResponse);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1,44 +1,57 @@
|
|||||||
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: 'user_type' , paranoid : true})
|
@Table({ tableName: 'user_type', paranoid: true })
|
||||||
export default class UserType extends Model {
|
export default class UserType extends Model {
|
||||||
|
|
||||||
|
@ApiProperty({ type: String })
|
||||||
@Unique(true)
|
@Unique(true)
|
||||||
@Column({ type: DataType.TEXT })
|
@Column({ type: DataType.TEXT })
|
||||||
userTypeCode: string;
|
userTypeCode: string;
|
||||||
|
|
||||||
|
@ApiProperty({ type: String })
|
||||||
@Column({ type: DataType.TEXT })
|
@Column({ type: DataType.TEXT })
|
||||||
userTypeName: string;
|
userTypeName: string;
|
||||||
|
|
||||||
|
@ApiProperty({ type: String })
|
||||||
@Column({ type: DataType.TEXT })
|
@Column({ type: DataType.TEXT })
|
||||||
userTypeDesc: string;
|
userTypeDesc: string;
|
||||||
|
|
||||||
|
@ApiProperty({ type: String })
|
||||||
@Column({ type: DataType.TEXT })
|
@Column({ type: DataType.TEXT })
|
||||||
status: string;
|
status: 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;
|
||||||
|
|
||||||
|
@ApiProperty({ type: Date })
|
||||||
@Column({ type: DataType.DATE })
|
@Column({ type: DataType.DATE })
|
||||||
createdAt: Date;
|
createdAt: Date;
|
||||||
|
|
||||||
|
@ApiProperty({ type: Date })
|
||||||
@Column({ type: DataType.DATE })
|
@Column({ type: DataType.DATE })
|
||||||
updatedAt: Date;
|
updatedAt: Date;
|
||||||
|
|
||||||
|
@ApiProperty({ type: Date })
|
||||||
@Column({ type: DataType.DATE })
|
@Column({ type: DataType.DATE })
|
||||||
deletedAt: Date;
|
deletedAt: Date;
|
||||||
|
|
||||||
|
@ApiProperty({ type: Number })
|
||||||
@Column({ type: DataType.NUMBER })
|
@Column({ type: DataType.NUMBER })
|
||||||
version: number;
|
version: number;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,130 +3,324 @@ import { UserService } from './user.service';
|
|||||||
import { Response } from 'express';
|
import { Response } from 'express';
|
||||||
import { GenericResponse } from '../common/GenericResponse.model';
|
import { GenericResponse } from '../common/GenericResponse.model';
|
||||||
import { User } from './user.entity';
|
import { User } from './user.entity';
|
||||||
|
import { ApiTags, ApiOperation, ApiResponse, ApiParam, ApiBody } from '@nestjs/swagger';
|
||||||
|
|
||||||
|
@ApiTags('users')
|
||||||
@Controller('users')
|
@Controller('users')
|
||||||
export class UserController {
|
export class UserController {
|
||||||
constructor(private userService: UserService) {}
|
constructor(private userService: UserService) {}
|
||||||
|
|
||||||
@Get("/all")
|
@Get("/all")
|
||||||
|
@ApiOperation({ summary: 'Get all users' })
|
||||||
|
@ApiResponse({
|
||||||
|
status: 200,
|
||||||
|
description: 'Successfully retrieved all users',
|
||||||
|
})
|
||||||
|
@ApiResponse({
|
||||||
|
status: 404,
|
||||||
|
description: 'No users found',
|
||||||
|
example: {
|
||||||
|
"notification": {
|
||||||
|
"exception": true,
|
||||||
|
"exceptionSeverity": "HIGH",
|
||||||
|
"exceptionMessage": "ERR.NOT_FOUND",
|
||||||
|
"stackTrace": "No users found"
|
||||||
|
},
|
||||||
|
"data": null
|
||||||
|
}
|
||||||
|
})
|
||||||
async getAllUsers(@Res() res: Response) {
|
async getAllUsers(@Res() res: Response) {
|
||||||
const response = await this.userService.findAll() || [];
|
const response = await this.userService.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 users found'
|
||||||
|
}, null);
|
||||||
|
return res.status(404).send(errorResponse);
|
||||||
|
}
|
||||||
|
const httpResponse = new GenericResponse(null, response);
|
||||||
|
res.status(200).send(httpResponse);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get(':id')
|
@Get(':id')
|
||||||
|
@ApiOperation({ summary: 'Get a user by ID' })
|
||||||
|
@ApiParam({ name: 'id', type: Number, description: 'User 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: 'User not found',
|
||||||
|
example: {
|
||||||
|
"notification": {
|
||||||
|
"exception": true,
|
||||||
|
"exceptionSeverity": "HIGH",
|
||||||
|
"exceptionMessage": "ERR.NOT_FOUND",
|
||||||
|
"stackTrace": "User not found"
|
||||||
|
},
|
||||||
|
"data": null
|
||||||
|
}
|
||||||
|
})
|
||||||
|
@ApiResponse({
|
||||||
|
status: 200,
|
||||||
|
description: 'Successfully retrieved user by ID',
|
||||||
|
})
|
||||||
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);
|
return res.status(400).send(response);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
const response = await this.userService.findByPk(id) || {};
|
const response = await this.userService.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: `User 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')
|
@Post('/filter')
|
||||||
|
@ApiOperation({ summary: 'Filter users based on criteria' })
|
||||||
|
@ApiBody({ type: User, description: 'User filter criteria' })
|
||||||
|
@ApiResponse({
|
||||||
|
status: 400,
|
||||||
|
description: 'Failed to insert user',
|
||||||
|
example: {
|
||||||
|
"notification": {
|
||||||
|
"exception": true,
|
||||||
|
"exceptionSeverity": "HIGH",
|
||||||
|
"exceptionMessage": "ERR.NOT_CREATED",
|
||||||
|
"stackTrace": "Request"
|
||||||
|
},
|
||||||
|
"data": null
|
||||||
|
}
|
||||||
|
})
|
||||||
|
@ApiResponse({
|
||||||
|
status: 404,
|
||||||
|
description: 'No users matching criteria found',
|
||||||
|
example: {
|
||||||
|
"notification": {
|
||||||
|
"exception": true,
|
||||||
|
"exceptionSeverity": "HIGH",
|
||||||
|
"exceptionMessage": "ERR.NOT_FOUND",
|
||||||
|
"stackTrace": "No users found matching criteria"
|
||||||
|
},
|
||||||
|
"data": null
|
||||||
|
}
|
||||||
|
})
|
||||||
|
@ApiResponse({
|
||||||
|
status: 200,
|
||||||
|
description: 'Successfully filtered users',
|
||||||
|
})
|
||||||
async filter(@Body() user: User, @Res() res: Response) {
|
async filter(@Body() user: User, @Res() res: Response) {
|
||||||
if(!user) {
|
if (!user) {
|
||||||
const response = new GenericResponse({
|
const response = new GenericResponse({
|
||||||
exception: true,
|
exception: true,
|
||||||
exceptionSeverity: 'HIGH',
|
exceptionSeverity: 'HIGH',
|
||||||
exceptionMessage: 'ERR.NO_ID_REQ',
|
exceptionMessage: 'ERR.NO_REQ',
|
||||||
stackTrace: 'Request'
|
stackTrace: 'Request'
|
||||||
}, null);
|
}, null);
|
||||||
res.send(response);
|
return res.status(400).send(response);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
const response = await this.userService.filter(user) || [];
|
const response = await this.userService.filter(user);
|
||||||
const httpResponse = new GenericResponse(null, response)
|
if (!response) {
|
||||||
|
const errorResponse = new GenericResponse({
|
||||||
|
exception: true,
|
||||||
|
exceptionSeverity: 'HIGH',
|
||||||
|
exceptionMessage: 'ERR.NOT_FOUND',
|
||||||
|
stackTrace: 'No users found matching criteria'
|
||||||
|
}, null);
|
||||||
|
return res.status(404).send(errorResponse);
|
||||||
|
}
|
||||||
|
const httpResponse = new GenericResponse(null, response);
|
||||||
res.status(200).send(httpResponse);
|
res.status(200).send(httpResponse);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post()
|
@Post()
|
||||||
|
@ApiOperation({ summary: 'Insert a new user' })
|
||||||
|
@ApiBody({ type: User, description: 'User data to insert' })
|
||||||
|
@ApiResponse({
|
||||||
|
status: 400,
|
||||||
|
description: 'Failed to insert user',
|
||||||
|
example: {
|
||||||
|
"notification": {
|
||||||
|
"exception": true,
|
||||||
|
"exceptionSeverity": "HIGH",
|
||||||
|
"exceptionMessage": "ERR.NOT_CREATED",
|
||||||
|
"stackTrace": "User not created"
|
||||||
|
},
|
||||||
|
"data": null
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
@ApiResponse({
|
||||||
|
status: 201,
|
||||||
|
description: 'User successfully created',
|
||||||
|
})
|
||||||
async insert(@Body() user: User, @Res() res: Response) {
|
async insert(@Body() user: User, @Res() res: Response) {
|
||||||
if(!user) {
|
if (!user) {
|
||||||
const response = new GenericResponse({
|
const response = new GenericResponse({
|
||||||
exception: true,
|
exception: true,
|
||||||
exceptionSeverity: 'HIGH',
|
exceptionSeverity: 'HIGH',
|
||||||
exceptionMessage: 'ERR.NO_ID_REQ',
|
exceptionMessage: 'ERR.NO_REQ',
|
||||||
stackTrace: 'Request'
|
stackTrace: 'Request'
|
||||||
}, null);
|
}, null);
|
||||||
res.send(response);
|
return res.status(400).send(response);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
delete user.id;
|
delete user.id;
|
||||||
if(user.password) {
|
if (user.password) {
|
||||||
user.password = this.encryptPassword(user.password);
|
user.password = this.encryptPassword(user.password);
|
||||||
}
|
}
|
||||||
const response = await this.userService.upsert(user, true);
|
const response = await this.userService.upsert(user, 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: 'User not created'
|
||||||
|
}, null);
|
||||||
|
return res.status(404).send(errorResponse);
|
||||||
|
}
|
||||||
|
const httpResponse = new GenericResponse(null, response);
|
||||||
|
res.status(201).send(httpResponse);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Put()
|
@Put()
|
||||||
|
@ApiOperation({ summary: 'Update an existing user' })
|
||||||
|
@ApiBody({ type: User, description: 'User data to update' })
|
||||||
|
@ApiResponse({
|
||||||
|
status: 400,
|
||||||
|
description: 'Failed to update user',
|
||||||
|
example: {
|
||||||
|
"notification": {
|
||||||
|
"exception": true,
|
||||||
|
"exceptionSeverity": "HIGH",
|
||||||
|
"exceptionMessage": "ERR.NOT_UPDATED",
|
||||||
|
"stackTrace": "User not updated"
|
||||||
|
},
|
||||||
|
"data": null
|
||||||
|
}
|
||||||
|
})
|
||||||
|
@ApiResponse({
|
||||||
|
status: 404,
|
||||||
|
description: 'User not found',
|
||||||
|
example: {
|
||||||
|
"notification": {
|
||||||
|
"exception": true,
|
||||||
|
"exceptionSeverity": "HIGH",
|
||||||
|
"exceptionMessage": "ERR.NOT_FOUND",
|
||||||
|
"stackTrace": "User not found"
|
||||||
|
},
|
||||||
|
"data": null
|
||||||
|
}
|
||||||
|
})
|
||||||
|
@ApiResponse({
|
||||||
|
status: 200,
|
||||||
|
description: 'User successfully updated',
|
||||||
|
})
|
||||||
async update(@Body() user: User, @Res() res: Response) {
|
async update(@Body() user: User, @Res() res: Response) {
|
||||||
if(!user || !user.id) {
|
if (!user || !user.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);
|
return res.status(400).send(response);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
if(user.password) {
|
if (user.password) {
|
||||||
user.password = this.encryptPassword(user.password);
|
user.password = this.encryptPassword(user.password);
|
||||||
}
|
}
|
||||||
const response = await this.userService.upsert(user, false);
|
const response = await this.userService.upsert(user, 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: 'User not found'
|
||||||
|
}, null);
|
||||||
|
return res.status(404).send(errorResponse);
|
||||||
|
}
|
||||||
|
const httpResponse = new GenericResponse(null, response);
|
||||||
|
res.status(200).send(httpResponse);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Delete(':id')
|
@Delete(':id')
|
||||||
|
@ApiOperation({ summary: 'Delete a user by ID' })
|
||||||
|
@ApiParam({ name: 'id', type: Number, description: 'User ID to delete' })
|
||||||
|
@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: 'User not found',
|
||||||
|
example: {
|
||||||
|
"notification": {
|
||||||
|
"exception": true,
|
||||||
|
"exceptionSeverity": "HIGH",
|
||||||
|
"exceptionMessage": "ERR.NOT_FOUND",
|
||||||
|
"stackTrace": "User not found"
|
||||||
|
},
|
||||||
|
"data": null
|
||||||
|
}
|
||||||
|
})
|
||||||
|
@ApiResponse({
|
||||||
|
status: 200,
|
||||||
|
description: 'User 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);
|
return res.status(400).send(response);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
const response = await this.userService.remove(id) || {};
|
const response = await this.userService.remove(id);
|
||||||
const httpResponse = new GenericResponse(null, response)
|
if (!response) {
|
||||||
res.send(httpResponse);
|
const errorResponse = new GenericResponse({
|
||||||
}
|
|
||||||
|
|
||||||
@Post('/login')
|
|
||||||
async login(@Body() user: User, @Res() res: Response) {
|
|
||||||
if(!user || !user.email || !user.password) {
|
|
||||||
const response = new GenericResponse({
|
|
||||||
exception: true,
|
exception: true,
|
||||||
exceptionSeverity: 'HIGH',
|
exceptionSeverity: 'HIGH',
|
||||||
exceptionMessage: 'ERR.NO_ID_REQ',
|
exceptionMessage: 'ERR.NOT_FOUND',
|
||||||
stackTrace: 'Request'
|
stackTrace: `User with ID ${id} not found`
|
||||||
}, null);
|
}, null);
|
||||||
res.status(401).send(response);
|
return res.status(404).send(errorResponse);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
user.password = this.encryptPassword(user.password);
|
const httpResponse = new GenericResponse(null, response);
|
||||||
user.status = 'active';
|
|
||||||
const response = {user: {} as User, token: ''};
|
|
||||||
response.user = await this.userService.login(user) || {} as User;
|
|
||||||
if(response.user && response.user.id) {
|
|
||||||
response.token = await this.encryptPassword(response.user.email);
|
|
||||||
}
|
|
||||||
const httpResponse = new GenericResponse(null, response)
|
|
||||||
res.status(200).send(httpResponse);
|
res.status(200).send(httpResponse);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,59 +1,76 @@
|
|||||||
import { Table, Column, Model, Default, DataType, HasMany, Unique, ForeignKey } from 'sequelize-typescript';
|
import { Table, Column, Model, Default, DataType, HasMany, Unique, ForeignKey } from 'sequelize-typescript';
|
||||||
|
import { ApiProperty } from '@nestjs/swagger';
|
||||||
import UserAdditionalDetail from './user-additional-details/user-additional-details.entity';
|
import UserAdditionalDetail from './user-additional-details/user-additional-details.entity';
|
||||||
import UserType from './user-types/user-type.entity';
|
import UserType from './user-types/user-type.entity';
|
||||||
|
|
||||||
@Table({ tableName: 'users' })
|
@Table({ tableName: 'users' })
|
||||||
export class User extends Model {
|
export class User extends Model {
|
||||||
|
|
||||||
|
@ApiProperty({ type: String })
|
||||||
@Unique(true)
|
@Unique(true)
|
||||||
@Column({ type: DataType.TEXT })
|
@Column({ type: DataType.TEXT })
|
||||||
email: string;
|
email: string;
|
||||||
|
|
||||||
|
@ApiProperty({ type: String })
|
||||||
@Column({ type: DataType.TEXT })
|
@Column({ type: DataType.TEXT })
|
||||||
name: string;
|
name: string;
|
||||||
|
|
||||||
|
@ApiProperty({ type: String })
|
||||||
@Column({ type: DataType.TEXT })
|
@Column({ type: DataType.TEXT })
|
||||||
password: string;
|
password: string;
|
||||||
|
|
||||||
|
@ApiProperty({ type: String })
|
||||||
@ForeignKey(() => UserType)
|
@ForeignKey(() => UserType)
|
||||||
@Column({ type: DataType.TEXT })
|
@Column({ type: DataType.TEXT })
|
||||||
userTypeCode: string;
|
userTypeCode: string;
|
||||||
|
|
||||||
|
@ApiProperty({ type: String })
|
||||||
@Column({ type: DataType.TEXT })
|
@Column({ type: DataType.TEXT })
|
||||||
primaryRole: string;
|
primaryRole: string;
|
||||||
|
|
||||||
|
@ApiProperty({ type: String })
|
||||||
@Column({ type: DataType.TEXT })
|
@Column({ type: DataType.TEXT })
|
||||||
instituteCode: string;
|
instituteCode: string;
|
||||||
|
|
||||||
|
@ApiProperty({ type: String })
|
||||||
@Column({ type: DataType.TEXT })
|
@Column({ type: DataType.TEXT })
|
||||||
status: string;
|
status: 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;
|
||||||
|
|
||||||
|
@ApiProperty({ type: Date })
|
||||||
@Column({ type: DataType.DATE })
|
@Column({ type: DataType.DATE })
|
||||||
createdAt: Date;
|
createdAt: Date;
|
||||||
|
|
||||||
|
@ApiProperty({ type: Date })
|
||||||
@Column({ type: DataType.DATE })
|
@Column({ type: DataType.DATE })
|
||||||
updatedAt: Date;
|
updatedAt: Date;
|
||||||
|
|
||||||
|
@ApiProperty({ type: Date })
|
||||||
@Column({ type: DataType.DATE })
|
@Column({ type: DataType.DATE })
|
||||||
deletedAt: Date;
|
deletedAt: Date;
|
||||||
|
|
||||||
|
@ApiProperty({ type: Number })
|
||||||
@Column({ type: DataType.NUMBER })
|
@Column({ type: DataType.NUMBER })
|
||||||
version: number;
|
version: number;
|
||||||
|
|
||||||
|
@ApiProperty({ type: [UserAdditionalDetail] })
|
||||||
@HasMany(() => UserAdditionalDetail)
|
@HasMany(() => UserAdditionalDetail)
|
||||||
additionalDetails: UserAdditionalDetail[];
|
additionalDetails: UserAdditionalDetail[];
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user