swagger update

This commit is contained in:
harshithnrao 2025-03-03 22:43:03 +05:30
parent 1333957d58
commit ab2932c127
22 changed files with 3793 additions and 15704 deletions

17881
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -23,16 +23,15 @@
"test:e2e": "jest --config ./test/jest-e2e.json"
},
"dependencies": {
"@nestjs-modules/mailer": "^1.10.3",
"@nestjs/common": "^10.0.0",
"@nestjs/config": "^3.1.1",
"@nestjs/core": "^10.0.0",
"@nestjs/platform-express": "^10.0.0",
"@nestjs/swagger": "^8.1.1",
"@nestjs/typeorm": "^10.0.1",
"dotenv": "^16.3.1",
"handlebars": "^4.7.8",
"moment": "^2.30.1",
"nexe": "^4.0.0-rc.6",
"nodemailer": "^6.9.9",
"otp-generator": "^4.0.1",
"pg": "^8.11.3",

View File

@ -41,4 +41,8 @@ export class AppConfigService {
getMailConfig() {
return configMaster[this.defaultEnv].mailConfig;
}
getSwaggerConfig() {
return configMaster[this.defaultEnv].swaggerConfig;
}
}

View File

@ -29,6 +29,15 @@
"defaults": {
"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"
}
}
}
}

View File

@ -29,6 +29,15 @@
"defaults": {
"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"
}
}
}
}

View File

@ -17,10 +17,10 @@ import { InstituteModule } from './institute/institute.module';
UserModule,
InstituteModule,
DataModule,
MailModule,
// MailModule,
ItemsModule,
SubscriptionsModule,
MasterConfigModule,
// MasterConfigModule,
ConfigModule
],
controllers: [AppController, AppConfigController],

View File

@ -41,6 +41,10 @@ export class AppService {
const emailConfig = this.configService.getMailConfig();
this.commonService.mailConfig = emailConfig;
Utility.mailConfig = emailConfig;
const swaggerConfig = this.configService.getSwaggerConfig();
this.commonService.swaggerConfig = swaggerConfig;
Utility.swaggerConfig = swaggerConfig;
}
getModels() {

View File

@ -4,6 +4,7 @@ export class Utility {
static sequelize: Sequelize;
static appPort: number = 3000;
static models: any;
static swaggerConfig: any;
static fileConfig: any = {"storagePath": "./uploads"};
static mailConfig: any = {
"transport": {

View File

@ -7,6 +7,7 @@ export class CommonService {
models: any;
fileConfig: any;
mailConfig: any;
swaggerConfig: any;
constructor() {
}

View File

@ -1,21 +1,82 @@
import { Body, Controller, Delete, Get, Param, Post, Put, Res } from '@nestjs/common';
import { InstituteService } from './institute.service';
import { Response } from 'express';
import { GenericResponse } from 'src/common/GenericResponse.model';
import { InstituteService } from './institute.service';
import Institute from './institute.entity';
import { ApiTags, ApiOperation, ApiResponse, ApiParam, ApiBody } from '@nestjs/swagger';
@ApiTags('institute')
@Controller('institute')
export class InstituteController {
constructor(private instituteService: InstituteService) {}
@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) {
const response = await this.instituteService.findAll() || [];
const httpResponse = new GenericResponse(null, response)
res.send(httpResponse);
if (!response) {
const errorResponse = new GenericResponse({
exception: true,
exceptionSeverity: 'HIGH',
exceptionMessage: 'ERR.NOT_FOUND',
stackTrace: 'No institutes found'
}, null);
return res.status(404).send(errorResponse);
}
const httpResponse = new GenericResponse(null, response);
res.status(200).send(httpResponse);
}
@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) {
if (!id) {
const response = new GenericResponse({
@ -24,15 +85,56 @@ export class InstituteController {
exceptionMessage: 'ERR.NO_ID_REQ',
stackTrace: 'Request'
}, null);
res.send(response);
res.status(400).send(response);
return;
}
const response = await this.instituteService.findByPk(id) || {};
const httpResponse = new GenericResponse(null, response)
res.send(httpResponse);
if (!response) {
const errorResponse = new GenericResponse({
exception: true,
exceptionSeverity: 'HIGH',
exceptionMessage: 'ERR.NOT_FOUND',
stackTrace: `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')
@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) {
if (!institute) {
const response = new GenericResponse({
@ -41,15 +143,56 @@ export class InstituteController {
exceptionMessage: 'ERR.NO_ID_REQ',
stackTrace: 'Request'
}, null);
res.send(response);
res.status(400).send(response);
return;
}
const response = await this.instituteService.filter(institute) || {};
const httpResponse = new GenericResponse(null, response)
res.send(httpResponse);
if (!response) {
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()
@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) {
if (!institute) {
const response = new GenericResponse({
@ -58,33 +201,115 @@ export class InstituteController {
exceptionMessage: 'ERR.NO_ID_REQ',
stackTrace: 'Request'
}, null);
res.send(response);
res.status(400).send(response);
return;
}
delete institute.id;
const response = await this.instituteService.upsert(institute, true);
const httpResponse = new GenericResponse(null, response)
res.send(httpResponse);
if (!response) {
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()
@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) {
if(!Institute || !institute.id) {
if (!institute || !institute.id) {
const response = new GenericResponse({
exception: true,
exceptionSeverity: 'HIGH',
exceptionMessage: 'ERR.NO_ID_REQ',
stackTrace: 'Request'
}, null);
res.send(response);
res.status(400).send(response);
return;
}
const response = await this.instituteService.upsert(institute, false);
const httpResponse = new GenericResponse(null, response)
res.send(httpResponse);
if (!response) {
const errorResponse = new GenericResponse({
exception: true,
exceptionSeverity: 'HIGH',
exceptionMessage: 'ERR.NOT_FOUND',
stackTrace: `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')
@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) {
if (!id) {
const response = new GenericResponse({
@ -93,11 +318,20 @@ export class InstituteController {
exceptionMessage: 'ERR.NO_ID_REQ',
stackTrace: 'Request'
}, null);
res.send(response);
res.status(400).send(response);
return;
}
const response = await this.instituteService.remove(id) || {};
const httpResponse = new GenericResponse(null, response)
res.send(httpResponse);
if (!response) {
const errorResponse = new GenericResponse({
exception: true,
exceptionSeverity: 'HIGH',
exceptionMessage: 'ERR.NOT_FOUND',
stackTrace: `Institute with ID ${id} not found`
}, null);
return res.status(404).send(errorResponse);
}
const httpResponse = new GenericResponse(null, response);
res.status(200).send(httpResponse);
}
}

View File

@ -1,36 +1,41 @@
import { Table, Column, Model, Default, DataType, HasMany, Unique } from 'sequelize-typescript';
import InstituteAdditionalDetail from './institute-additional-details/institute-additional-details.entity';
import { Table, Column, Model, Default, DataType, Unique } from 'sequelize-typescript';
import { ApiProperty } from '@nestjs/swagger';
@Table({ tableName: 'institute', paranoid: true })
export default class Institute extends Model {
@ApiProperty({ type: String })
@Unique(true)
@Column({ type: DataType.TEXT })
instituteCode: string;
@ApiProperty({ type: String })
@Column({ type: DataType.TEXT })
instituteName: string;
@ApiProperty({ type: String })
@Column({ type: DataType.TEXT })
address: string;
@ApiProperty({ type: Number })
@Column({ type: DataType.DECIMAL })
lat: number;
@ApiProperty({ type: Number })
@Column({ type: DataType.DECIMAL })
lng: number;
@ApiProperty({ type: String })
@Column({ type: DataType.TEXT })
status: string;
@ApiProperty({ type: Date, default: new Date() })
@Default(new Date())
@Column({ type: DataType.DATEONLY })
validFrom: Date;
@ApiProperty({ type: Date, default: new Date("2070-12-31") })
@Default(new Date("2070-12-31"))
@Column({ type: DataType.DATEONLY })
validTill: Date;
// @HasMany(() => InstituteAdditionalDetail)
// additionalDetails: InstituteAdditionalDetail[];
}

View File

@ -1,5 +1,5 @@
import { MailerModule } from '@nestjs-modules/mailer';
import { HandlebarsAdapter } from '@nestjs-modules/mailer/dist/adapters/handlebars.adapter';
// import { MailerModule } from '@nestjs-modules/mailer';
// import { HandlebarsAdapter } from '@nestjs-modules/mailer/dist/adapters/handlebars.adapter';
import { Module } from '@nestjs/common';
import { MailService } from './mail.service';
import { join } from 'path';
@ -7,19 +7,19 @@ import { Utility } from 'src/common/Utility';
@Module({
imports: [
MailerModule.forRoot({
// transport: 'smtps://user@example.com:topsecret@smtp.example.com',
// or
transport: Utility.mailConfig.transport,
defaults: Utility.mailConfig.defaults,
template: {
dir: join(__dirname, 'templates'),
adapter: new HandlebarsAdapter(), // or new PugAdapter() or new EjsAdapter()
options: {
strict: true,
},
},
}),
// MailerModule.forRoot({
// // transport: 'smtps://user@example.com:topsecret@smtp.example.com',
// // or
// transport: Utility.mailConfig.transport,
// defaults: Utility.mailConfig.defaults,
// template: {
// dir: join(__dirname, 'templates'),
// adapter: new HandlebarsAdapter(), // or new PugAdapter() or new EjsAdapter()
// options: {
// strict: true,
// },
// },
// }),
],
providers: [MailService],
exports: [MailService], // 👈 export for DI

View File

@ -1,19 +1,19 @@
import { MailerService } from '@nestjs-modules/mailer';
// import { MailerService } from '@nestjs-modules/mailer';
import { Injectable } from '@nestjs/common';
@Injectable()
export class MailService {
constructor(private mailerService: MailerService) { }
// constructor(private mailerService: MailerService) { }
async sendEmail(templateName: string, subject: string, context: any, toEmail: string, ccEmails?: string[], bccEmails?: string[]) {
await this.mailerService.sendMail({
to: toEmail,
cc: ccEmails,
bcc: bccEmails,
subject: subject,
template: templateName, // `.hbs` extension is appended automatically
context,
})
// await this.mailerService.sendMail({
// to: toEmail,
// cc: ccEmails,
// bcc: bccEmails,
// subject: subject,
// template: templateName, // `.hbs` extension is appended automatically
// context,
// })
}
}

View File

@ -3,12 +3,25 @@ import { AppModule } from './app.module';
import * as bodyParser from 'body-parser';
import * as configMaster from './app-config/config.json';
import { Utility } from './common/Utility';
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
async function bootstrap() {
Utility.appPort = configMaster.local.appConfig.port;
Utility.mailConfig = configMaster.local.mailConfig;
Utility.fileConfig = configMaster.local.fileConfig;
Utility.swaggerConfig = configMaster.local.swaggerConfig;
const app = await NestFactory.create(AppModule, { cors: 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);

View File

@ -3,19 +3,80 @@ import { Response } from 'express';
import { GenericResponse } from 'src/common/GenericResponse.model';
import { SubscriptionService } from './subscription.service';
import Subscription from './subscription.entity';
import { ApiTags, ApiOperation, ApiResponse, ApiParam, ApiBody } from '@nestjs/swagger';
@ApiTags('subscriptions')
@Controller('subscriptions')
export class SubscriptionController {
constructor(private subscriptionsService: SubscriptionService) { }
@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) {
const response = await this.subscriptionsService.findAll() || [];
const httpResponse = new GenericResponse(null, response)
res.send(httpResponse);
if (!response) {
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')
@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) {
if (!id) {
const response = new GenericResponse({
@ -24,50 +85,173 @@ export class SubscriptionController {
exceptionMessage: 'ERR.NO_ID_REQ',
stackTrace: 'Request'
}, null);
res.send(response);
res.status(400).send(response);
return;
}
const response = await this.subscriptionsService.findByPk(id) || {};
const httpResponse = new GenericResponse(null, response)
res.send(httpResponse);
if (!response) {
const errorResponse = new GenericResponse({
exception: true,
exceptionSeverity: 'HIGH',
exceptionMessage: 'ERR.NOT_FOUND',
stackTrace: `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')
@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) {
if (!subscription) {
const response = new GenericResponse({
exception: true,
exceptionSeverity: 'HIGH',
exceptionMessage: 'ERR.NO_ID_REQ',
exceptionMessage: 'ERR.NO_REQ_BODY',
stackTrace: 'Request'
}, null);
res.send(response);
res.status(400).send(response);
return;
}
const response = await this.subscriptionsService.filter(subscription) || {};
const httpResponse = new GenericResponse(null, response)
res.send(httpResponse);
if (!response) {
const errorResponse = new GenericResponse({
exception: true,
exceptionSeverity: 'HIGH',
exceptionMessage: 'ERR.NOT_FOUND',
stackTrace: 'No subscriptions found matching criteria'
}, null);
return res.status(404).send(errorResponse);
}
const httpResponse = new GenericResponse(null, response);
res.status(200).send(httpResponse);
}
@Post()
@ApiOperation({ summary: 'Insert a new 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) {
if (!subscription) {
const response = new GenericResponse({
exception: true,
exceptionSeverity: 'HIGH',
exceptionMessage: 'ERR.NO_ID_REQ',
exceptionMessage: 'ERR.NO_REQ_BODY',
stackTrace: 'Request'
}, null);
res.send(response);
res.status(400).send(response);
return;
}
delete subscription.id;
const response = await this.subscriptionsService.upsert(subscription, true);
const httpResponse = new GenericResponse(null, response)
res.send(httpResponse);
if (!response) {
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()
@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) {
if (!subscription || !subscription.id) {
const response = new GenericResponse({
@ -76,15 +260,56 @@ export class SubscriptionController {
exceptionMessage: 'ERR.NO_ID_REQ',
stackTrace: 'Request'
}, null);
res.send(response);
res.status(400).send(response);
return;
}
const response = await this.subscriptionsService.upsert(subscription, false);
const httpResponse = new GenericResponse(null, response)
res.send(httpResponse);
if (!response) {
const errorResponse = new GenericResponse({
exception: true,
exceptionSeverity: 'HIGH',
exceptionMessage: 'ERR.NOT_FOUND',
stackTrace: 'Subscription not found'
}, null);
return res.status(404).send(errorResponse);
}
const httpResponse = new GenericResponse(null, response);
res.status(200).send(httpResponse);
}
@Delete(':id')
@ApiOperation({ summary: 'Delete a 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) {
if (!id) {
const response = new GenericResponse({
@ -93,11 +318,20 @@ export class SubscriptionController {
exceptionMessage: 'ERR.NO_ID_REQ',
stackTrace: 'Request'
}, null);
res.send(response);
res.status(400).send(response);
return;
}
const response = await this.subscriptionsService.remove(id) || {};
const httpResponse = new GenericResponse(null, response)
res.send(httpResponse);
if (!response) {
const errorResponse = new GenericResponse({
exception: true,
exceptionSeverity: 'HIGH',
exceptionMessage: 'ERR.NOT_FOUND',
stackTrace: `Subscription with ID ${id} not found`
}, null);
return res.status(404).send(errorResponse);
}
const httpResponse = new GenericResponse(null, response);
res.status(200).send(httpResponse);
}
}

View File

@ -1,55 +1,70 @@
import { Table, Column, Model, Default, DataType, ForeignKey } from 'sequelize-typescript';
import { ApiProperty } from '@nestjs/swagger';
import { User } from 'src/user/user.entity';
@Table({ tableName: 'subscription', timestamps: true, paranoid: true })
export default class Subscription extends Model {
@ApiProperty({ type: Number })
@Column({ type: DataType.BIGINT, primaryKey: true, autoIncrement: true })
id: number;
@ApiProperty({ type: Number })
@ForeignKey(() => User)
@Column({ type: DataType.BIGINT })
user_id: number;
@ApiProperty({ type: String })
@Column({ type: DataType.TEXT })
plan_type: string;
@ApiProperty({ type: Date })
@Column({ type: DataType.DATEONLY })
start_date: Date;
@ApiProperty({ type: Date })
@Column({ type: DataType.DATEONLY })
end_date: Date;
@Default(true)
@ApiProperty({ type: Boolean})
@Column({ type: DataType.BOOLEAN })
is_active: boolean;
@ApiProperty({ type: String })
@Column({ type: DataType.TEXT })
status: string;
@ApiProperty({ type: Date, default: new Date() })
@Default(new Date())
@Column({ type: DataType.DATEONLY })
validFrom: Date;
@ApiProperty({ type: Date, default: new Date("2070-12-31") })
@Default(new Date("2070-12-31"))
@Column({ type: DataType.DATEONLY })
validTill: Date;
@ApiProperty({ type: Date })
@Column({ type: DataType.DATE })
createdAt: Date;
@ApiProperty({ type: Date })
@Column({ type: DataType.DATE })
updatedAt: Date;
@ApiProperty({ type: String })
@Column({ type: DataType.TEXT })
createBy: string;
@ApiProperty({ type: String })
@Column({ type: DataType.TEXT })
modifiedBy: string;
@ApiProperty({ type: Date })
@Column({ type: DataType.DATE })
deletedAt: Date;
@ApiProperty({ type: Number })
@Column({ type: DataType.INTEGER })
version: number;
}

View File

@ -3,20 +3,81 @@ import { Response } from 'express';
import { UserAdditionalDetailsService } from './user-additional-details.service';
import { GenericResponse } from 'src/common/GenericResponse.model';
import UserAdditionalDetail from './user-additional-details.entity';
import { ApiTags, ApiOperation, ApiResponse, ApiParam, ApiBody } from '@nestjs/swagger';
@ApiTags('user-additional-details')
@Controller('users/addl/')
export class UserAdditionalDetailsController {
constructor(private userAdditionalDetailsService: UserAdditionalDetailsService) { }
@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 httpResponse = new GenericResponse(null, response)
res.send(httpResponse);
if (!response) {
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')
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) {
const response = new GenericResponse({
exception: true,
@ -24,16 +85,58 @@ export class UserAdditionalDetailsController {
exceptionMessage: 'ERR.NO_ID_IN_REQ',
stackTrace: 'Request'
}, null);
res.send(response);
res.status(400).send(response);
return;
}
const response = await this.userAdditionalDetailsService.findByPk(id) || {};
const httpResponse = new GenericResponse(null, response)
res.send(httpResponse);
if(!response) {
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')
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) {
const response = new GenericResponse({
exception: true,
@ -41,16 +144,57 @@ export class UserAdditionalDetailsController {
exceptionMessage: 'ERR.NO_REQ',
stackTrace: 'Request'
}, null);
res.send(response);
res.status(400).send(response);
return;
}
const response = await this.userAdditionalDetailsService.filter(user) || [];
const httpResponse = new GenericResponse(null, response)
res.send(httpResponse);
if (!response) {
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()
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) {
const response = new GenericResponse({
exception: true,
@ -58,17 +202,59 @@ export class UserAdditionalDetailsController {
exceptionMessage: 'ERR.NO_REQ',
stackTrace: 'Request'
}, null);
res.send(response);
res.status(400).send(response);
return;
}
delete user.id;
const response = await this.userAdditionalDetailsService.upsert(user, true);
const httpResponse = new GenericResponse(null, response)
res.send(httpResponse);
if (!response) {
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()
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) {
const response = new GenericResponse({
exception: true,
@ -76,28 +262,79 @@ export class UserAdditionalDetailsController {
exceptionMessage: 'ERR.NO_REQ',
stackTrace: 'Request'
}, null);
res.send(response);
res.status(400).send(response);
return;
}
const response = await this.userAdditionalDetailsService.upsert(user, false);
const httpResponse = new GenericResponse(null, response)
res.send(httpResponse);
if (!response) {
const errorResponse = new GenericResponse({
exception: true,
exceptionSeverity: 'HIGH',
exceptionMessage: 'ERR.NOT_FOUND',
stackTrace: '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')
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) {
const response = new GenericResponse({
exception: true,
exceptionSeverity: 'HIGH',
exceptionMessage: 'ERR.NO_REQ',
exceptionMessage: 'ERR.NO_ID_IN_REQ',
stackTrace: 'Request'
}, null);
res.send(response);
res.status(400).send(response);
return;
}
const response = await this.userAdditionalDetailsService.remove(id) || {};
const httpResponse = new GenericResponse(null, response)
res.send(httpResponse);
if (!response) {
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);
}
}

View File

@ -1,31 +1,38 @@
import { Table, Column, Model, Default, DataType, ForeignKey, BelongsTo } from 'sequelize-typescript';
import { ApiProperty } from '@nestjs/swagger';
import { User } from '../user.entity';
@Table({ tableName: 'user_additional_details', paranoid: true })
export default class UserAdditionalDetail extends Model {
@ApiProperty({ type: String })
@Column({ type: DataType.TEXT })
addlDataType: string;
@Column({type: DataType.NUMBER})
@ApiProperty({ type: Number })
@ForeignKey(() => User)
@Column({ type: DataType.NUMBER })
userId: number;
@ApiProperty({ type: String })
@Column({ type: DataType.TEXT })
addlDataName: string;
@ApiProperty({ type: Date, default: new Date() })
@Default(new Date())
@Column({ type: DataType.DATEONLY })
validFrom: Date;
@ApiProperty({ type: Date, default: new Date("2070-12-31") })
@Default(new Date("2070-12-31"))
@Column({ type: DataType.DATEONLY })
validTill: Date;
@ApiProperty({ type: String })
@Column({ type: DataType.TEXT })
createBy: string;
@ApiProperty({ type: String })
@Column({ type: DataType.TEXT })
modifiedBy: string;
}

View File

@ -3,24 +3,81 @@ import { Response } from 'express';
import { GenericResponse } from 'src/common/GenericResponse.model';
import UserType from './user-type.entity';
import { UserTypesService } from './user-types.service';
import { ApiTags, ApiOperation, ApiResponse, ApiParam, ApiBody } from '@nestjs/swagger';
@ApiTags('user-types')
@Controller('users/types')
export class UserTypesController {
constructor(private userTypeService?: UserTypesService) {
if(!userTypeService) {
userTypeService = new UserTypesService();
}
}
constructor(private userTypeService: UserTypesService) { }
@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) {
const response = await this.userTypeService.findAll() || [];
const httpResponse = new GenericResponse(null, response)
res.send(httpResponse);
if (!response) {
const errorResponse = new GenericResponse({
exception: true,
exceptionSeverity: 'HIGH',
exceptionMessage: 'ERR.NOT_FOUND',
stackTrace: 'No user types found'
}, null);
return res.status(404).send(errorResponse);
}
const httpResponse = new GenericResponse(null, response);
res.status(200).send(httpResponse);
}
@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) {
if (!id) {
const response = new GenericResponse({
@ -29,15 +86,43 @@ export class UserTypesController {
exceptionMessage: 'ERR.NO_ID_IN_REQ',
stackTrace: 'Request'
}, null);
res.send(response);
res.status(400).send(response);
return;
}
const response = await this.userTypeService.findByPk(id) || {};
const httpResponse = new GenericResponse(null, response)
res.send(httpResponse);
if (!response) {
const errorResponse = new GenericResponse({
exception: true,
exceptionSeverity: 'HIGH',
exceptionMessage: 'ERR.NOT_FOUND',
stackTrace: 'User type not found'
}, null);
return res.status(404).send(errorResponse);
}
const httpResponse = new GenericResponse(null, response);
res.status(200).send(httpResponse);
}
@Post('/filter')
@ApiOperation({ summary: 'Filter 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) {
if (!user) {
const response = new GenericResponse({
@ -46,15 +131,43 @@ export class UserTypesController {
exceptionMessage: 'ERR.NO_REQ',
stackTrace: 'Request'
}, null);
res.send(response);
res.status(400).send(response);
return;
}
const response = await this.userTypeService.filter(user) || [];
const httpResponse = new GenericResponse(null, response)
res.send(httpResponse);
if (!response) {
const errorResponse = new GenericResponse({
exception: true,
exceptionSeverity: 'HIGH',
exceptionMessage: 'ERR.NOT_FOUND',
stackTrace: 'No user types found matching criteria'
}, null);
return res.status(404).send(errorResponse);
}
const httpResponse = new GenericResponse(null, response);
res.status(200).send(httpResponse);
}
@Post()
@ApiOperation({ summary: 'Insert a new 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) {
if (!user) {
const response = new GenericResponse({
@ -63,16 +176,57 @@ export class UserTypesController {
exceptionMessage: 'ERR.NO_REQ',
stackTrace: 'Request'
}, null);
res.send(response);
res.status(400).send(response);
return;
}
delete user.id;
const response = await this.userTypeService.upsert(user, true);
const httpResponse = new GenericResponse(null, response)
res.send(httpResponse);
if (!response) {
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()
@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) {
if (!user || !user.id) {
const response = new GenericResponse({
@ -81,28 +235,78 @@ export class UserTypesController {
exceptionMessage: 'ERR.NO_REQ',
stackTrace: 'Request'
}, null);
res.send(response);
res.status(400).send(response);
return;
}
const response = await this.userTypeService.upsert(user, false);
const httpResponse = new GenericResponse(null, response)
res.send(httpResponse);
if (!response) {
const errorResponse = new GenericResponse({
exception: true,
exceptionSeverity: 'HIGH',
exceptionMessage: 'ERR.NOT_FOUND',
stackTrace: 'User type not found'
}, null);
return res.status(404).send(errorResponse);
}
const httpResponse = new GenericResponse(null, response);
res.status(200).send(httpResponse);
}
@Delete(':id')
@ApiOperation({ summary: 'Delete a 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) {
if (!id) {
const response = new GenericResponse({
exception: true,
exceptionSeverity: 'HIGH',
exceptionMessage: 'ERR.NO_REQ',
exceptionMessage: 'ERR.NO_ID_IN_REQ',
stackTrace: 'Request'
}, null);
res.send(response);
res.status(400).send(response);
return;
}
const response = await this.userTypeService.remove(id) || {};
const httpResponse = new GenericResponse(null, response)
res.send(httpResponse);
if(!response){
const errorResponse = new GenericResponse({
exception: true,
exceptionSeverity: 'HIGH',
exceptionMessage: 'ERR.NOT_FOUND',
stackTrace: 'User type not found'
}, null);
return res.status(404).send(errorResponse);
}
const httpResponse = new GenericResponse(null, response);
res.status(200).send(httpResponse);
}
}

View File

@ -1,44 +1,57 @@
import { Table, Column, Model, Default, DataType, Unique } from 'sequelize-typescript';
import { ApiProperty } from '@nestjs/swagger';
@Table({ tableName: 'user_type', paranoid: true })
export default class UserType extends Model {
@ApiProperty({ type: String })
@Unique(true)
@Column({ type: DataType.TEXT })
userTypeCode: string;
@ApiProperty({ type: String })
@Column({ type: DataType.TEXT })
userTypeName: string;
@ApiProperty({ type: String })
@Column({ type: DataType.TEXT })
userTypeDesc: string;
@ApiProperty({ type: String })
@Column({ type: DataType.TEXT })
status: string;
@ApiProperty({ type: Date, default: new Date() })
@Default(new Date())
@Column({ type: DataType.DATEONLY })
validFrom: Date;
@ApiProperty({ type: Date, default: new Date("2070-12-31") })
@Default(new Date("2070-12-31"))
@Column({ type: DataType.DATEONLY })
validTill: Date;
@ApiProperty({ type: String })
@Column({ type: DataType.TEXT })
createBy: string;
@ApiProperty({ type: String })
@Column({ type: DataType.TEXT })
modifiedBy: string;
@ApiProperty({ type: Date })
@Column({ type: DataType.DATE })
createdAt: Date;
@ApiProperty({ type: Date })
@Column({ type: DataType.DATE })
updatedAt: Date;
@ApiProperty({ type: Date })
@Column({ type: DataType.DATE })
deletedAt: Date;
@ApiProperty({ type: Number })
@Column({ type: DataType.NUMBER })
version: number;
}

View File

@ -3,19 +3,80 @@ import { UserService } from './user.service';
import { Response } from 'express';
import { GenericResponse } from '../common/GenericResponse.model';
import { User } from './user.entity';
import { ApiTags, ApiOperation, ApiResponse, ApiParam, ApiBody } from '@nestjs/swagger';
@ApiTags('users')
@Controller('users')
export class UserController {
constructor(private userService: UserService) {}
@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) {
const response = await this.userService.findAll() || [];
const httpResponse = new GenericResponse(null, response)
res.send(httpResponse);
const response = await this.userService.findAll();
if (!response) {
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')
@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) {
if (!id) {
const response = new GenericResponse({
@ -24,53 +85,161 @@ export class UserController {
exceptionMessage: 'ERR.NO_ID_REQ',
stackTrace: 'Request'
}, null);
res.send(response);
return;
return res.status(400).send(response);
}
const response = await this.userService.findByPk(id) || {};
const httpResponse = new GenericResponse(null, response)
res.send(httpResponse);
const response = await this.userService.findByPk(id);
if (!response) {
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')
@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) {
if (!user) {
const response = new GenericResponse({
exception: true,
exceptionSeverity: 'HIGH',
exceptionMessage: 'ERR.NO_ID_REQ',
exceptionMessage: 'ERR.NO_REQ',
stackTrace: 'Request'
}, null);
res.send(response);
return;
return res.status(400).send(response);
}
const response = await this.userService.filter(user) || [];
const httpResponse = new GenericResponse(null, response)
const response = await this.userService.filter(user);
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);
}
@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) {
if (!user) {
const response = new GenericResponse({
exception: true,
exceptionSeverity: 'HIGH',
exceptionMessage: 'ERR.NO_ID_REQ',
exceptionMessage: 'ERR.NO_REQ',
stackTrace: 'Request'
}, null);
res.send(response);
return;
return res.status(400).send(response);
}
delete user.id;
if (user.password) {
user.password = this.encryptPassword(user.password);
}
const response = await this.userService.upsert(user, true);
const httpResponse = new GenericResponse(null, response)
res.send(httpResponse);
if (!response) {
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()
@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) {
if (!user || !user.id) {
const response = new GenericResponse({
@ -79,18 +248,58 @@ export class UserController {
exceptionMessage: 'ERR.NO_ID_REQ',
stackTrace: 'Request'
}, null);
res.send(response);
return;
return res.status(400).send(response);
}
if (user.password) {
user.password = this.encryptPassword(user.password);
}
const response = await this.userService.upsert(user, false);
const httpResponse = new GenericResponse(null, response)
res.send(httpResponse);
if (!response) {
const errorResponse = new GenericResponse({
exception: true,
exceptionSeverity: 'HIGH',
exceptionMessage: 'ERR.NOT_FOUND',
stackTrace: 'User not found'
}, null);
return res.status(404).send(errorResponse);
}
const httpResponse = new GenericResponse(null, response);
res.status(200).send(httpResponse);
}
@Delete(':id')
@ApiOperation({ summary: 'Delete a 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) {
if (!id) {
const response = new GenericResponse({
@ -99,34 +308,19 @@ export class UserController {
exceptionMessage: 'ERR.NO_ID_REQ',
stackTrace: 'Request'
}, null);
res.send(response);
return;
return res.status(400).send(response);
}
const response = await this.userService.remove(id) || {};
const httpResponse = new GenericResponse(null, response)
res.send(httpResponse);
}
@Post('/login')
async login(@Body() user: User, @Res() res: Response) {
if(!user || !user.email || !user.password) {
const response = new GenericResponse({
const response = await this.userService.remove(id);
if (!response) {
const errorResponse = new GenericResponse({
exception: true,
exceptionSeverity: 'HIGH',
exceptionMessage: 'ERR.NO_ID_REQ',
stackTrace: 'Request'
exceptionMessage: 'ERR.NOT_FOUND',
stackTrace: `User with ID ${id} not found`
}, null);
res.status(401).send(response);
return;
return res.status(404).send(errorResponse);
}
user.password = this.encryptPassword(user.password);
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)
const httpResponse = new GenericResponse(null, response);
res.status(200).send(httpResponse);
}

View File

@ -1,59 +1,76 @@
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 UserType from './user-types/user-type.entity';
@Table({ tableName: 'users' })
export class User extends Model {
@ApiProperty({ type: String })
@Unique(true)
@Column({ type: DataType.TEXT })
email: string;
@ApiProperty({ type: String })
@Column({ type: DataType.TEXT })
name: string;
@ApiProperty({ type: String })
@Column({ type: DataType.TEXT })
password: string;
@ApiProperty({ type: String })
@ForeignKey(() => UserType)
@Column({ type: DataType.TEXT })
userTypeCode: string;
@ApiProperty({ type: String })
@Column({ type: DataType.TEXT })
primaryRole: string;
@ApiProperty({ type: String })
@Column({ type: DataType.TEXT })
instituteCode: string;
@ApiProperty({ type: String })
@Column({ type: DataType.TEXT })
status: string;
@ApiProperty({ type: Date, default: new Date() })
@Default(new Date())
@Column({ type: DataType.DATEONLY })
validFrom: Date;
@ApiProperty({ type: Date, default: new Date("2070-12-31") })
@Default(new Date("2070-12-31"))
@Column({ type: DataType.DATEONLY })
validTill: Date;
@ApiProperty({ type: String })
@Column({ type: DataType.TEXT })
createBy: string;
@ApiProperty({ type: String })
@Column({ type: DataType.TEXT })
modifiedBy: string;
@ApiProperty({ type: Date })
@Column({ type: DataType.DATE })
createdAt: Date;
@ApiProperty({ type: Date })
@Column({ type: DataType.DATE })
updatedAt: Date;
@ApiProperty({ type: Date })
@Column({ type: DataType.DATE })
deletedAt: Date;
@ApiProperty({ type: Number })
@Column({ type: DataType.NUMBER })
version: number;
@ApiProperty({ type: [UserAdditionalDetail] })
@HasMany(() => UserAdditionalDetail)
additionalDetails: UserAdditionalDetail[];
}