integrating swagger and swagger in config
This commit is contained in:
parent
d0a88b7769
commit
d3f1a8451c
6740
package-lock.json
generated
6740
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -23,11 +23,11 @@
|
||||
"test:e2e": "jest --config ./test/jest-e2e.json"
|
||||
},
|
||||
"dependencies": {
|
||||
"@nestjs-modules/mailer": "^1.10.3",
|
||||
"@nestjs/common": "^10.0.0",
|
||||
"@nestjs/config": "^3.1.1",
|
||||
"@nestjs/core": "^10.0.0",
|
||||
"@nestjs/platform-express": "^10.0.0",
|
||||
"@nestjs/swagger": "^8.1.1",
|
||||
"@nestjs/typeorm": "^10.0.1",
|
||||
"dotenv": "^16.3.1",
|
||||
"handlebars": "^4.7.8",
|
||||
|
||||
@ -41,4 +41,8 @@ export class AppConfigService {
|
||||
getMailConfig() {
|
||||
return configMaster[this.defaultEnv].mailConfig;
|
||||
}
|
||||
|
||||
getSwaggerConfig() {
|
||||
return configMaster[this.defaultEnv].swaggerConfig;
|
||||
}
|
||||
}
|
||||
|
||||
@ -29,6 +29,14 @@
|
||||
"defaults": {
|
||||
"from": "\"No Reply\" <admin@wct.co.in>"
|
||||
}
|
||||
},
|
||||
"swaggerConfig": {
|
||||
"swagger": {
|
||||
"title": "Remedify Content API",
|
||||
"description": "Remedify Content API",
|
||||
"version": "1.0.0",
|
||||
"tag": "Remedify Content API"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -29,6 +29,14 @@
|
||||
"defaults": {
|
||||
"from": "\"No Reply\" <admin@wct.co.in>"
|
||||
}
|
||||
},
|
||||
"swaggerConfig": {
|
||||
"swagger": {
|
||||
"title": "Remedify Content API",
|
||||
"description": "Remedify Content API",
|
||||
"version": "1.0.0",
|
||||
"tag": "Remedify Content API"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -4,26 +4,26 @@ import { AppService } from './app.service';
|
||||
import { CommonService } from './common/common.service';
|
||||
import { AppConfigService } from './app-config/app-config.service';
|
||||
import { DataModule } from './data/data.module';
|
||||
import { MailModule } from './mail/mail.module';
|
||||
// import { MailModule } from './mail/mail.module';
|
||||
import { AppConfigController } from './app-config/app-config.controller';
|
||||
import { MasterConfigModule } from './master-config/master-config.module';
|
||||
import { ConfigModule } from './config/config.module';
|
||||
import { TopicsModule } from './topics/topics.module';
|
||||
import { ChapterModule } from './chapter/chapter.module';
|
||||
import { TextbookModule } from './textbook/textbook.module';
|
||||
import { TextbookTagssModule } from './textbook-tags/textbook-tags.module';
|
||||
import { TextbookTagsModule } from './textbook-tags/textbook-tags.module';
|
||||
import { SectionModule } from './section/section.module';
|
||||
@Module({
|
||||
imports: [
|
||||
DataModule,
|
||||
MailModule,
|
||||
// MailModule,
|
||||
ChapterModule,
|
||||
TextbookModule,
|
||||
TextbookTagssModule,
|
||||
TextbookTagsModule,
|
||||
TopicsModule,
|
||||
SectionModule,
|
||||
MasterConfigModule,
|
||||
ConfigModule,
|
||||
// MasterConfigModule,
|
||||
// ConfigModule,
|
||||
TopicsModule
|
||||
],
|
||||
controllers: [AppController, AppConfigController],
|
||||
|
||||
@ -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() {
|
||||
|
||||
@ -1,106 +1,310 @@
|
||||
import { Body, Controller, Delete, Get, Param, Post, Put, Res } from '@nestjs/common';
|
||||
import { ChapterService } from './chapter.service';
|
||||
import { Response } from 'express';
|
||||
import { GenericResponse } from '../common/GenericResponse.model';
|
||||
import Chapter from './chapter.entity';
|
||||
import { ChapterService } from './chapter.service';
|
||||
import Chapter from './chapter.entity';
|
||||
import { ApiTags, ApiOperation, ApiResponse, ApiParam, ApiBody } from '@nestjs/swagger';
|
||||
|
||||
@ApiTags('chapters')
|
||||
@Controller('chapter')
|
||||
export class ChapterController {
|
||||
constructor(private chapterService: ChapterService) {}
|
||||
|
||||
@Get("/all")
|
||||
@ApiOperation({ summary: 'Get all chapters' })
|
||||
@ApiResponse({
|
||||
status: 200,
|
||||
description: 'Successfully retrieved all chapters',
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 404,
|
||||
description: 'No chapters found',
|
||||
example: {
|
||||
"notification": {
|
||||
"exception": true,
|
||||
"exceptionSeverity": "HIGH",
|
||||
"exceptionMessage": "ERR.NOT_FOUND",
|
||||
"stackTrace": "No chapters found"
|
||||
},
|
||||
"data": null
|
||||
}
|
||||
})
|
||||
async getAllChapters(@Res() res: Response) {
|
||||
const response = await this.chapterService.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 chapters found'
|
||||
}, null);
|
||||
return res.status(404).send(errorResponse);
|
||||
}
|
||||
const httpResponse = new GenericResponse(null, response);
|
||||
res.status(200).send(httpResponse);
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
@ApiOperation({ summary: 'Get chapter by ID' })
|
||||
@ApiParam({ name: 'id', type: Number, description: 'Chapter 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: 'Chapter not found',
|
||||
example: {
|
||||
"notification": {
|
||||
"exception": true,
|
||||
"exceptionSeverity": "HIGH",
|
||||
"exceptionMessage": "ERR.NOT_FOUND",
|
||||
"stackTrace": "Chapter not found"
|
||||
},
|
||||
"data": null
|
||||
}
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 200,
|
||||
description: 'Successfully retrieved chapter by ID',
|
||||
})
|
||||
async findById(@Param('id') id: number, @Res() res: Response) {
|
||||
if(!id) {
|
||||
if (!id) {
|
||||
const response = new GenericResponse({
|
||||
exception: true,
|
||||
exceptionSeverity: 'HIGH',
|
||||
exceptionMessage: 'ERR.NO_ID_REQ',
|
||||
stackTrace: 'Request'
|
||||
}, null);
|
||||
res.send(response);
|
||||
return;
|
||||
return res.status(400).send(response);
|
||||
}
|
||||
const response = await this.chapterService.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: `Chapter 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 chapters based on criteria' })
|
||||
@ApiBody({ type: Chapter, description: 'Filter criteria for chapters' })
|
||||
@ApiResponse({
|
||||
status: 400,
|
||||
description: 'Invalid filter criteria',
|
||||
example: {
|
||||
"notification": {
|
||||
"exception": true,
|
||||
"exceptionSeverity": "HIGH",
|
||||
"exceptionMessage": "ERR.INVALID_CRITERIA",
|
||||
"stackTrace": "Request"
|
||||
},
|
||||
"data": null
|
||||
}
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 404,
|
||||
description: 'No chapters found based on filter criteria',
|
||||
example: {
|
||||
"notification": {
|
||||
"exception": true,
|
||||
"exceptionSeverity": "HIGH",
|
||||
"exceptionMessage": "ERR.NOT_FOUND",
|
||||
"stackTrace": "No chapters found based on the filter criteria"
|
||||
},
|
||||
"data": null
|
||||
}
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 200,
|
||||
description: 'Successfully filtered chapters',
|
||||
})
|
||||
async filter(@Body() chapter: Chapter, @Res() res: Response) {
|
||||
if(!chapter) {
|
||||
if (!chapter) {
|
||||
const response = new GenericResponse({
|
||||
exception: true,
|
||||
exceptionSeverity: 'HIGH',
|
||||
exceptionMessage: 'ERR.NO_ID_REQ',
|
||||
exceptionMessage: 'ERR.INVALID_CRITERIA',
|
||||
stackTrace: 'Request'
|
||||
}, null);
|
||||
res.send(response);
|
||||
return;
|
||||
return res.status(400).send(response);
|
||||
}
|
||||
const response = await this.chapterService.filter(chapter) || [];
|
||||
const httpResponse = new GenericResponse(null, response)
|
||||
if (!response) {
|
||||
const errorResponse = new GenericResponse({
|
||||
exception: true,
|
||||
exceptionSeverity: 'HIGH',
|
||||
exceptionMessage: 'ERR.NOT_FOUND',
|
||||
stackTrace: 'No chapters found based on the filter criteria'
|
||||
}, null);
|
||||
return res.status(404).send(errorResponse);
|
||||
}
|
||||
const httpResponse = new GenericResponse(null, response);
|
||||
res.status(200).send(httpResponse);
|
||||
}
|
||||
|
||||
@Post()
|
||||
@ApiOperation({ summary: 'Insert a new chapter' })
|
||||
@ApiBody({ type: Chapter, description: 'Chapter data to insert' })
|
||||
@ApiResponse({
|
||||
status: 400,
|
||||
description: 'Invalid chapter data',
|
||||
example: {
|
||||
"notification": {
|
||||
"exception": true,
|
||||
"exceptionSeverity": "HIGH",
|
||||
"exceptionMessage": "ERR.INVALID_DATA",
|
||||
"stackTrace": "Request"
|
||||
},
|
||||
"data": null
|
||||
}
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 201,
|
||||
description: 'Chapter successfully created',
|
||||
})
|
||||
async insert(@Body() chapter: Chapter, @Res() res: Response) {
|
||||
if(!chapter) {
|
||||
if (!chapter) {
|
||||
const response = new GenericResponse({
|
||||
exception: true,
|
||||
exceptionSeverity: 'HIGH',
|
||||
exceptionMessage: 'ERR.NO_ID_REQ',
|
||||
stackTrace: 'Request'
|
||||
}, null);
|
||||
res.send(response);
|
||||
return;
|
||||
return res.status(400).send(response);
|
||||
}
|
||||
delete chapter.id;
|
||||
|
||||
const response = await this.chapterService.upsert(chapter, true);
|
||||
const httpResponse = new GenericResponse(null, response)
|
||||
res.send(httpResponse);
|
||||
const httpResponse = new GenericResponse(null, response);
|
||||
res.status(201).send(httpResponse);
|
||||
}
|
||||
|
||||
@Put()
|
||||
@ApiOperation({ summary: 'Update an existing chapter' })
|
||||
@ApiBody({ type: Chapter, description: 'Chapter data to update' })
|
||||
@ApiResponse({
|
||||
status: 400,
|
||||
description: 'Invalid chapter data or ID missing',
|
||||
example: {
|
||||
"notification": {
|
||||
"exception": true,
|
||||
"exceptionSeverity": "HIGH",
|
||||
"exceptionMessage": "ERR.INVALID_DATA",
|
||||
"stackTrace": "Request"
|
||||
},
|
||||
"data": null
|
||||
}
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 404,
|
||||
description: 'Chapter not found',
|
||||
example: {
|
||||
"notification": {
|
||||
"exception": true,
|
||||
"exceptionSeverity": "HIGH",
|
||||
"exceptionMessage": "ERR.NOT_FOUND",
|
||||
"stackTrace": "Chapter not found"
|
||||
},
|
||||
"data": null
|
||||
}
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 200,
|
||||
description: 'Chapter successfully updated',
|
||||
})
|
||||
async update(@Body() chapter: Chapter, @Res() res: Response) {
|
||||
if(!chapter || !chapter.id) {
|
||||
if (!chapter || !chapter.id) {
|
||||
const response = new GenericResponse({
|
||||
exception: true,
|
||||
exceptionSeverity: 'HIGH',
|
||||
exceptionMessage: 'ERR.NO_ID_REQ',
|
||||
stackTrace: 'Request'
|
||||
}, null);
|
||||
res.send(response);
|
||||
return;
|
||||
return res.status(400).send(response);
|
||||
}
|
||||
|
||||
const response = await this.chapterService.upsert(chapter, 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: `Chapter with ID ${chapter.id} not found`
|
||||
}, null);
|
||||
return res.status(404).send(errorResponse);
|
||||
}
|
||||
const httpResponse = new GenericResponse(null, response);
|
||||
res.status(200).send(httpResponse);
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
@ApiOperation({ summary: 'Delete a chapter by ID' })
|
||||
@ApiParam({ name: 'id', type: Number, description: 'Chapter 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: 'Chapter not found',
|
||||
example: {
|
||||
"notification": {
|
||||
"exception": true,
|
||||
"exceptionSeverity": "HIGH",
|
||||
"exceptionMessage": "ERR.NOT_FOUND",
|
||||
"stackTrace": "Chapter not found"
|
||||
},
|
||||
"data": null
|
||||
}
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 200,
|
||||
description: 'Chapter successfully deleted',
|
||||
})
|
||||
async deleteById(@Param('id') id: number, @Res() res: Response) {
|
||||
if(!id) {
|
||||
if (!id) {
|
||||
const response = new GenericResponse({
|
||||
exception: true,
|
||||
exceptionSeverity: 'HIGH',
|
||||
exceptionMessage: 'ERR.NO_ID_REQ',
|
||||
stackTrace: 'Request'
|
||||
}, null);
|
||||
res.send(response);
|
||||
return;
|
||||
return res.status(400).send(response);
|
||||
}
|
||||
const response = await this.chapterService.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: `Chapter with ID ${id} not found`
|
||||
}, null);
|
||||
return res.status(404).send(errorResponse);
|
||||
}
|
||||
const httpResponse = new GenericResponse(null, response);
|
||||
res.status(200).send(httpResponse);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,52 +1,68 @@
|
||||
import { Table, Column, Model, Default, DataType } from 'sequelize-typescript';
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
|
||||
@Table({ tableName: 'chapter' , paranoid : true})
|
||||
@Table({ tableName: 'chapter', paranoid: true })
|
||||
export default class Chapter extends Model {
|
||||
|
||||
@ApiProperty({ type: Number })
|
||||
@Column(DataType.BIGINT)
|
||||
textbook_id: number;
|
||||
|
||||
@ApiProperty({ type: String })
|
||||
@Column(DataType.TEXT)
|
||||
title: string;
|
||||
|
||||
@ApiProperty({ type: Number })
|
||||
@Column(DataType.NUMBER)
|
||||
number: number;
|
||||
|
||||
@ApiProperty({ type: String })
|
||||
@Column(DataType.TEXT)
|
||||
description: string;
|
||||
|
||||
@ApiProperty({ type: Number })
|
||||
@Column(DataType.NUMBER)
|
||||
start_page: number;
|
||||
|
||||
@ApiProperty({ type: Number })
|
||||
@Column(DataType.NUMBER)
|
||||
end_page: number;
|
||||
|
||||
@ApiProperty({ type: Date, default: new Date() })
|
||||
@Default(new Date())
|
||||
@Column(DataType.DATEONLY)
|
||||
validFrom: Date;
|
||||
|
||||
@ApiProperty({ type: Date, default: new Date("2070-12-31") })
|
||||
@Default(new Date("2070-12-31"))
|
||||
@Column(DataType.DATEONLY)
|
||||
validTill: Date;
|
||||
|
||||
@ApiProperty({ type: Date })
|
||||
@Column(DataType.DATEONLY)
|
||||
createdAt: Date;
|
||||
|
||||
@ApiProperty({ type: Date })
|
||||
@Column(DataType.DATEONLY)
|
||||
updatedAt: Date;
|
||||
|
||||
@ApiProperty({ type: String })
|
||||
@Column(DataType.TEXT)
|
||||
createBy: string;
|
||||
|
||||
@ApiProperty({ type: String })
|
||||
@Column(DataType.TEXT)
|
||||
modifiedBy: string;
|
||||
|
||||
@ApiProperty({ type: Date })
|
||||
@Column(DataType.DATEONLY)
|
||||
deletedAt: Date;
|
||||
|
||||
@ApiProperty({ type: Number })
|
||||
@Column(DataType.NUMBER)
|
||||
version: number;
|
||||
|
||||
@ApiProperty({ type: String })
|
||||
@Column(DataType.TEXT)
|
||||
status: string;
|
||||
}
|
||||
|
||||
@ -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": {
|
||||
|
||||
@ -7,6 +7,7 @@ export class CommonService {
|
||||
models: any;
|
||||
fileConfig: any;
|
||||
mailConfig: any;
|
||||
swaggerConfig: any;
|
||||
|
||||
constructor() {
|
||||
}
|
||||
|
||||
@ -1,29 +1,36 @@
|
||||
import { Table, Column, Model, Default, DataType } from 'sequelize-typescript';
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
|
||||
@Table({tableName: 'crud_config_info', paranoid : true})
|
||||
@Table({ tableName: 'crud_config_info', paranoid: true })
|
||||
export default class DataModel extends Model {
|
||||
|
||||
@Column({type: DataType.NUMBER})
|
||||
@ApiProperty({ type: Number })
|
||||
@Column({ type: DataType.NUMBER })
|
||||
endPtNm: number;
|
||||
|
||||
@Column({type: DataType.TEXT})
|
||||
@ApiProperty({ type: String })
|
||||
@Column({ type: DataType.TEXT })
|
||||
sqlQueryText: string;
|
||||
|
||||
@Column({type: DataType.TEXT})
|
||||
@ApiProperty({ type: String })
|
||||
@Column({ type: DataType.TEXT })
|
||||
opsTypeName: string;
|
||||
|
||||
@ApiProperty({ type: Date, default: new Date() })
|
||||
@Default(new Date())
|
||||
@Column({type: DataType.DATEONLY})
|
||||
@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})
|
||||
@Column({ type: DataType.DATEONLY })
|
||||
validTill: Date;
|
||||
|
||||
@Column({type: DataType.TEXT})
|
||||
@ApiProperty({ type: String })
|
||||
@Column({ type: DataType.TEXT })
|
||||
createBy: string;
|
||||
|
||||
@Column({type: DataType.TEXT})
|
||||
@ApiProperty({ type: String })
|
||||
@Column({ type: DataType.TEXT })
|
||||
modifiedBy: string;
|
||||
|
||||
}
|
||||
@ -1,27 +0,0 @@
|
||||
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';
|
||||
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,
|
||||
},
|
||||
},
|
||||
}),
|
||||
],
|
||||
providers: [MailService],
|
||||
exports: [MailService], // 👈 export for DI
|
||||
})
|
||||
export class MailModule {}
|
||||
@ -1,18 +0,0 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { MailService } from './mail.service';
|
||||
|
||||
describe('MailService', () => {
|
||||
let service: MailService;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
providers: [MailService],
|
||||
}).compile();
|
||||
|
||||
service = module.get<MailService>(MailService);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(service).toBeDefined();
|
||||
});
|
||||
});
|
||||
@ -1,19 +0,0 @@
|
||||
import { MailerService } from '@nestjs-modules/mailer';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
|
||||
@Injectable()
|
||||
export class MailService {
|
||||
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,
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -1,82 +0,0 @@
|
||||
<head>
|
||||
<style>
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.gjs-row {
|
||||
display: flex;
|
||||
justify-content: flex-start;
|
||||
align-items: stretch;
|
||||
flex-wrap: nowrap;
|
||||
padding: 10px;
|
||||
}
|
||||
|
||||
.gjs-cell {
|
||||
min-height: 75px;
|
||||
flex-grow: 1;
|
||||
flex-basis: 100%;
|
||||
}
|
||||
|
||||
#im43 {
|
||||
background-repeat: repeat;
|
||||
background-position: left top;
|
||||
background-attachment: scroll;
|
||||
background-size: auto;
|
||||
background-image: linear-gradient(#39960c 0%, #39960c 100%);
|
||||
}
|
||||
|
||||
#ij93 {
|
||||
padding: 10px;
|
||||
}
|
||||
|
||||
#ilfj {
|
||||
color: #ffffff;
|
||||
text-align: left;
|
||||
font-weight: 900;
|
||||
font-size: 3rem;
|
||||
}
|
||||
|
||||
#ihfp {
|
||||
height: 577px;
|
||||
}
|
||||
|
||||
#i23r {
|
||||
padding: 10px;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.gjs-row {
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body id="iohk">
|
||||
<div class="gjs-row" id="iir1">
|
||||
<div class="gjs-cell" id="im43">
|
||||
<div id="ij93">
|
||||
<span id="ilfj">Waste Care Technologies</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="gjs-row" id="ihfp">
|
||||
<div class="gjs-cell">
|
||||
<div id="i23r">Dear {{ name }},
|
||||
<br />
|
||||
<br />Welcome to Waste Care Technologies.
|
||||
<br />
|
||||
<br />Use Password {{ password }} to login to your account.
|
||||
<br />
|
||||
<br />Contact our Support if you need any queries.
|
||||
<br />
|
||||
<br />Thank you for choosing us
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
@ -1,79 +0,0 @@
|
||||
<head>
|
||||
<style>
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.gjs-row {
|
||||
display: flex;
|
||||
justify-content: flex-start;
|
||||
align-items: stretch;
|
||||
flex-wrap: nowrap;
|
||||
padding: 10px;
|
||||
}
|
||||
|
||||
.gjs-cell {
|
||||
min-height: 75px;
|
||||
flex-grow: 1;
|
||||
flex-basis: 100%;
|
||||
}
|
||||
|
||||
#im43 {
|
||||
background-repeat: repeat;
|
||||
background-position: left top;
|
||||
background-attachment: scroll;
|
||||
background-size: auto;
|
||||
background-image: linear-gradient(#39960c 0%, #39960c 100%);
|
||||
}
|
||||
|
||||
#ij93 {
|
||||
padding: 10px;
|
||||
}
|
||||
|
||||
#ilfj {
|
||||
color: #ffffff;
|
||||
text-align: left;
|
||||
font-weight: 900;
|
||||
font-size: 3rem;
|
||||
}
|
||||
|
||||
#ihfp {
|
||||
height: 577px;
|
||||
}
|
||||
|
||||
#i23r {
|
||||
padding: 10px;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.gjs-row {
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body id="iohk">
|
||||
<div class="gjs-row" id="iir1">
|
||||
<div class="gjs-cell" id="im43">
|
||||
<div id="ij93">
|
||||
<span id="ilfj">Waste Care Technologies</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="gjs-row" id="ihfp">
|
||||
<div class="gjs-cell" id="ihbs">
|
||||
<div id="i23r">Dear {{ email }},
|
||||
<br/>
|
||||
<br/>A Quote with {{ quoteID }} is created by you.
|
||||
<br/>
|
||||
<br/>Current Quote is in {{ status }} status.
|
||||
<br/>
|
||||
<br/>Thank you for choosing us
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
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 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 });
|
||||
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);
|
||||
}
|
||||
bootstrap();
|
||||
|
||||
@ -1,103 +1,310 @@
|
||||
import { Body, Controller, Delete, Get, Param, Post, Put, Res } from '@nestjs/common';
|
||||
import { SectionService } from './section.service';
|
||||
import { Response } from 'express';
|
||||
import { GenericResponse } from 'src/common/GenericResponse.model';
|
||||
import { SectionService } from './section.service';
|
||||
import Section from './section.entity';
|
||||
import { ApiTags, ApiOperation, ApiResponse, ApiParam, ApiBody } from '@nestjs/swagger';
|
||||
|
||||
@ApiTags('sections')
|
||||
@Controller('section')
|
||||
export class SectionController {
|
||||
constructor(private sectionService: SectionService) {}
|
||||
|
||||
@Get("/all")
|
||||
@ApiOperation({ summary: 'Get all sections' })
|
||||
@ApiResponse({
|
||||
status: 200,
|
||||
description: 'Successfully retrieved all sections',
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 404,
|
||||
description: 'No sections found',
|
||||
example: {
|
||||
"notification": {
|
||||
"exception": true,
|
||||
"exceptionSeverity": "HIGH",
|
||||
"exceptionMessage": "ERR.NOT_FOUND",
|
||||
"stackTrace": "No sections found"
|
||||
},
|
||||
"data": null
|
||||
}
|
||||
})
|
||||
async getAllSections(@Res() res: Response) {
|
||||
const response = await this.sectionService.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 sections found'
|
||||
}, null);
|
||||
return res.status(404).send(errorResponse);
|
||||
}
|
||||
const httpResponse = new GenericResponse(null, response);
|
||||
res.status(200).send(httpResponse);
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
@ApiOperation({ summary: 'Get section by ID' })
|
||||
@ApiParam({ name: 'id', type: Number, description: 'Section 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: 'Section not found',
|
||||
example: {
|
||||
"notification": {
|
||||
"exception": true,
|
||||
"exceptionSeverity": "HIGH",
|
||||
"exceptionMessage": "ERR.NOT_FOUND",
|
||||
"stackTrace": "Section not found"
|
||||
},
|
||||
"data": null
|
||||
}
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 200,
|
||||
description: 'Successfully retrieved section by ID',
|
||||
})
|
||||
async findById(@Param('id') id: number, @Res() res: Response) {
|
||||
if(!id) {
|
||||
if (!id) {
|
||||
const response = new GenericResponse({
|
||||
exception: true,
|
||||
exceptionSeverity: 'HIGH',
|
||||
exceptionMessage: 'ERR.NO_ID_REQ',
|
||||
stackTrace: 'Request'
|
||||
}, null);
|
||||
res.send(response);
|
||||
return;
|
||||
return res.status(400).send(response);
|
||||
}
|
||||
const response = await this.sectionService.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: `Section 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 sections based on criteria' })
|
||||
@ApiBody({ type: Section, description: 'Filter criteria for sections' })
|
||||
@ApiResponse({
|
||||
status: 400,
|
||||
description: 'Invalid filter criteria',
|
||||
example: {
|
||||
"notification": {
|
||||
"exception": true,
|
||||
"exceptionSeverity": "HIGH",
|
||||
"exceptionMessage": "ERR.INVALID_CRITERIA",
|
||||
"stackTrace": "Request"
|
||||
},
|
||||
"data": null
|
||||
}
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 404,
|
||||
description: 'No sections found based on filter criteria',
|
||||
example: {
|
||||
"notification": {
|
||||
"exception": true,
|
||||
"exceptionSeverity": "HIGH",
|
||||
"exceptionMessage": "ERR.NOT_FOUND",
|
||||
"stackTrace": "No sections found based on the filter criteria"
|
||||
},
|
||||
"data": null
|
||||
}
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 200,
|
||||
description: 'Successfully filtered sections',
|
||||
})
|
||||
async filter(@Body() section: Section, @Res() res: Response) {
|
||||
if(!section) {
|
||||
if (!section) {
|
||||
const response = new GenericResponse({
|
||||
exception: true,
|
||||
exceptionSeverity: 'HIGH',
|
||||
exceptionMessage: 'ERR.NO_ID_REQ',
|
||||
exceptionMessage: 'ERR.INVALID_CRITERIA',
|
||||
stackTrace: 'Request'
|
||||
}, null);
|
||||
res.send(response);
|
||||
return;
|
||||
return res.status(400).send(response);
|
||||
}
|
||||
const response = await this.sectionService.filter(section) || {};
|
||||
const httpResponse = new GenericResponse(null, response)
|
||||
res.send(httpResponse);
|
||||
const response = await this.sectionService.filter(section) || [];
|
||||
if (!response) {
|
||||
const errorResponse = new GenericResponse({
|
||||
exception: true,
|
||||
exceptionSeverity: 'HIGH',
|
||||
exceptionMessage: 'ERR.NOT_FOUND',
|
||||
stackTrace: 'No sections found based on the filter criteria'
|
||||
}, null);
|
||||
return res.status(404).send(errorResponse);
|
||||
}
|
||||
const httpResponse = new GenericResponse(null, response);
|
||||
res.status(200).send(httpResponse);
|
||||
}
|
||||
|
||||
@Post()
|
||||
@ApiOperation({ summary: 'Insert a new section' })
|
||||
@ApiBody({ type: Section, description: 'Section data to insert' })
|
||||
@ApiResponse({
|
||||
status: 400,
|
||||
description: 'Invalid section data',
|
||||
example: {
|
||||
"notification": {
|
||||
"exception": true,
|
||||
"exceptionSeverity": "HIGH",
|
||||
"exceptionMessage": "ERR.INVALID_DATA",
|
||||
"stackTrace": "Request"
|
||||
},
|
||||
"data": null
|
||||
}
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 201,
|
||||
description: 'Section successfully created',
|
||||
})
|
||||
async insert(@Body() section: Section, @Res() res: Response) {
|
||||
if(!section) {
|
||||
if (!section) {
|
||||
const response = new GenericResponse({
|
||||
exception: true,
|
||||
exceptionSeverity: 'HIGH',
|
||||
exceptionMessage: 'ERR.NO_ID_REQ',
|
||||
stackTrace: 'Request'
|
||||
}, null);
|
||||
res.send(response);
|
||||
return;
|
||||
return res.status(400).send(response);
|
||||
}
|
||||
delete section.id;
|
||||
const response = await this.sectionService.upsert(section, true);
|
||||
const httpResponse = new GenericResponse(null, response)
|
||||
res.send(httpResponse);
|
||||
const httpResponse = new GenericResponse(null, response);
|
||||
res.status(201).send(httpResponse);
|
||||
}
|
||||
|
||||
@Put()
|
||||
@ApiOperation({ summary: 'Update an existing section' })
|
||||
@ApiBody({ type: Section, description: 'Section data to update' })
|
||||
@ApiResponse({
|
||||
status: 400,
|
||||
description: 'Invalid section data or ID missing',
|
||||
example: {
|
||||
"notification": {
|
||||
"exception": true,
|
||||
"exceptionSeverity": "HIGH",
|
||||
"exceptionMessage": "ERR.INVALID_DATA",
|
||||
"stackTrace": "Request"
|
||||
},
|
||||
"data": null
|
||||
}
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 404,
|
||||
description: 'Section not found',
|
||||
example: {
|
||||
"notification": {
|
||||
"exception": true,
|
||||
"exceptionSeverity": "HIGH",
|
||||
"exceptionMessage": "ERR.NOT_FOUND",
|
||||
"stackTrace": "Section not found"
|
||||
},
|
||||
"data": null
|
||||
}
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 200,
|
||||
description: 'Section successfully updated',
|
||||
})
|
||||
async update(@Body() section: Section, @Res() res: Response) {
|
||||
if(!Section || !section.id) {
|
||||
if (!section || !section.id) {
|
||||
const response = new GenericResponse({
|
||||
exception: true,
|
||||
exceptionSeverity: 'HIGH',
|
||||
exceptionMessage: 'ERR.NO_ID_REQ',
|
||||
stackTrace: 'Request'
|
||||
}, null);
|
||||
res.send(response);
|
||||
return;
|
||||
return res.status(400).send(response);
|
||||
}
|
||||
const response = await this.sectionService.upsert(section, 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: `Section with ID ${section.id} not found`
|
||||
}, null);
|
||||
return res.status(404).send(errorResponse);
|
||||
}
|
||||
const httpResponse = new GenericResponse(null, response);
|
||||
res.status(200).send(httpResponse);
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
@ApiOperation({ summary: 'Delete a section by ID' })
|
||||
@ApiParam({ name: 'id', type: Number, description: 'Section 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: 'Section not found',
|
||||
example: {
|
||||
"notification": {
|
||||
"exception": true,
|
||||
"exceptionSeverity": "HIGH",
|
||||
"exceptionMessage": "ERR.NOT_FOUND",
|
||||
"stackTrace": "Section not found"
|
||||
},
|
||||
"data": null
|
||||
}
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 200,
|
||||
description: 'Section successfully deleted',
|
||||
})
|
||||
async deleteById(@Param('id') id: number, @Res() res: Response) {
|
||||
if(!id) {
|
||||
if (!id) {
|
||||
const response = new GenericResponse({
|
||||
exception: true,
|
||||
exceptionSeverity: 'HIGH',
|
||||
exceptionMessage: 'ERR.NO_ID_REQ',
|
||||
stackTrace: 'Request'
|
||||
}, null);
|
||||
res.send(response);
|
||||
return;
|
||||
return res.status(400).send(response);
|
||||
}
|
||||
const response = await this.sectionService.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: `Section 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,72 @@
|
||||
import { Table, Column, Model, Default, DataType } from 'sequelize-typescript';
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
|
||||
@Table({ tableName: 'section' , paranoid : true})
|
||||
@Table({ tableName: 'section', paranoid: true })
|
||||
export default class Section extends Model {
|
||||
|
||||
@ApiProperty({ type: Number })
|
||||
@Column(DataType.BIGINT)
|
||||
chapter_id: number;
|
||||
|
||||
@ApiProperty({ type: String })
|
||||
@Column(DataType.TEXT)
|
||||
title: string;
|
||||
|
||||
@ApiProperty({ type: Number })
|
||||
@Column(DataType.NUMBER)
|
||||
number: number;
|
||||
|
||||
@ApiProperty({ type: String })
|
||||
@Column(DataType.TEXT)
|
||||
description: string;
|
||||
|
||||
@ApiProperty({ type: Number })
|
||||
@Column(DataType.NUMBER)
|
||||
start_page: number;
|
||||
|
||||
@ApiProperty({ type: Number })
|
||||
@Column(DataType.NUMBER)
|
||||
end_page: number;
|
||||
|
||||
@ApiProperty({ type: Number })
|
||||
@Column(DataType.BIGINT)
|
||||
parent_section: number;
|
||||
|
||||
@ApiProperty({ type: Date, default: new Date() })
|
||||
@Default(new Date())
|
||||
@Column(DataType.DATEONLY)
|
||||
validFrom: Date;
|
||||
|
||||
@ApiProperty({ type: Date, default: new Date("2070-12-31") })
|
||||
@Default(new Date("2070-12-31"))
|
||||
@Column(DataType.DATEONLY)
|
||||
validTill: Date;
|
||||
|
||||
@ApiProperty({ type: Date })
|
||||
@Column(DataType.DATEONLY)
|
||||
createdAt: Date;
|
||||
|
||||
@ApiProperty({ type: Date })
|
||||
@Column(DataType.DATEONLY)
|
||||
updatedAt: Date;
|
||||
|
||||
@ApiProperty({ type: String })
|
||||
@Column(DataType.TEXT)
|
||||
createBy: string;
|
||||
|
||||
@ApiProperty({ type: String })
|
||||
@Column(DataType.TEXT)
|
||||
modifiedBy: string;
|
||||
|
||||
@ApiProperty({ type: Date })
|
||||
@Column(DataType.DATEONLY)
|
||||
deletedAt: Date;
|
||||
|
||||
@ApiProperty({ type: Number })
|
||||
@Column(DataType.NUMBER)
|
||||
version: number;
|
||||
|
||||
@ApiProperty({ type: String })
|
||||
@Column(DataType.TEXT)
|
||||
status: string;
|
||||
}
|
||||
|
||||
@ -3,101 +3,330 @@ import { Response } from 'express';
|
||||
import { GenericResponse } from 'src/common/GenericResponse.model';
|
||||
import { TextbookTagsService } from './textbook-tags.service';
|
||||
import TextbookTags from './textbook-tags.entity';
|
||||
import { ApiTags, ApiOperation, ApiResponse, ApiParam, ApiBody } from '@nestjs/swagger';
|
||||
|
||||
@ApiTags('textbook-tags')
|
||||
@Controller('textbook-tags')
|
||||
export class TextbookTagsController {
|
||||
constructor(private textbookTagsService: TextbookTagsService) {}
|
||||
|
||||
@Get("/all")
|
||||
@ApiOperation({ summary: 'Get all textbook tags' })
|
||||
@ApiResponse({
|
||||
status: 200,
|
||||
description: 'Successfully retrieved all textbook tags',
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 404,
|
||||
description: 'No textbook tags found',
|
||||
example: {
|
||||
"notification": {
|
||||
"exception": true,
|
||||
"exceptionSeverity": "HIGH",
|
||||
"exceptionMessage": "ERR.NOT_FOUND",
|
||||
"stackTrace": "No textbook tags found"
|
||||
},
|
||||
"data": null
|
||||
}
|
||||
})
|
||||
async getAll(@Res() res: Response) {
|
||||
const response = await this.textbookTagsService.findAll() || [];
|
||||
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 textbook tags found'
|
||||
}, null);
|
||||
return res.status(404).send(response);
|
||||
}
|
||||
const httpResponse = new GenericResponse(null, response);
|
||||
res.status(200).send(httpResponse);
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
@ApiOperation({ summary: 'Get textbook tag by ID' })
|
||||
@ApiParam({ name: 'id', type: Number, description: 'Textbook tag 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: 'Textbook tag not found',
|
||||
example: {
|
||||
"notification": {
|
||||
"exception": true,
|
||||
"exceptionSeverity": "HIGH",
|
||||
"exceptionMessage": "ERR.NOT_FOUND",
|
||||
"stackTrace": "Textbook tag not found"
|
||||
},
|
||||
"data": null
|
||||
}
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 200,
|
||||
description: 'Successfully retrieved textbook tag by ID',
|
||||
})
|
||||
async findById(@Param('id') id: number, @Res() res: Response) {
|
||||
if(!id) {
|
||||
if (!id) {
|
||||
const response = new GenericResponse({
|
||||
exception: true,
|
||||
exceptionSeverity: 'HIGH',
|
||||
exceptionMessage: 'ERR.NO_ID_REQ',
|
||||
stackTrace: 'Request'
|
||||
}, null);
|
||||
res.send(response);
|
||||
return;
|
||||
return res.status(400).send(response);
|
||||
}
|
||||
const response = await this.textbookTagsService.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: 'Textbook tag not found'
|
||||
}, null);
|
||||
return res.status(404).send(response);
|
||||
}
|
||||
const httpResponse = new GenericResponse(null, response);
|
||||
res.status(200).send(httpResponse);
|
||||
}
|
||||
|
||||
@Post('/filter')
|
||||
@ApiOperation({ summary: 'Filter textbook tags based on criteria' })
|
||||
@ApiBody({ type: TextbookTags, description: 'Filter criteria for textbook tags' })
|
||||
@ApiResponse({
|
||||
status: 400,
|
||||
description: 'Invalid filter criteria',
|
||||
example: {
|
||||
"notification": {
|
||||
"exception": true,
|
||||
"exceptionSeverity": "HIGH",
|
||||
"exceptionMessage": "ERR.INVALID_CRITERIA",
|
||||
"stackTrace": "Request"
|
||||
},
|
||||
"data": null
|
||||
}
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 404,
|
||||
description: 'No textbook tags found based on filter criteria',
|
||||
example: {
|
||||
"notification": {
|
||||
"exception": true,
|
||||
"exceptionSeverity": "HIGH",
|
||||
"exceptionMessage": "ERR.NOT_FOUND",
|
||||
"stackTrace": "No textbook tags found based on the filter criteria"
|
||||
},
|
||||
"data": null
|
||||
}
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 200,
|
||||
description: 'Successfully filtered textbook tags',
|
||||
})
|
||||
async filter(@Body() textbookTags: TextbookTags, @Res() res: Response) {
|
||||
if(!textbookTags) {
|
||||
if (!textbookTags) {
|
||||
const response = new GenericResponse({
|
||||
exception: true,
|
||||
exceptionSeverity: 'HIGH',
|
||||
exceptionMessage: 'ERR.NO_ID_REQ',
|
||||
exceptionMessage: 'ERR.INVALID_CRITERIA',
|
||||
stackTrace: 'Request'
|
||||
}, null);
|
||||
res.send(response);
|
||||
return;
|
||||
return res.status(400).send(response);
|
||||
}
|
||||
const response = await this.textbookTagsService.filter(textbookTags) || {};
|
||||
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 textbook tags found based on the filter criteria'
|
||||
}, null);
|
||||
return res.status(404).send(response);
|
||||
}
|
||||
const httpResponse = new GenericResponse(null, response);
|
||||
res.status(200).send(httpResponse);
|
||||
}
|
||||
|
||||
@Post()
|
||||
@ApiOperation({ summary: 'Insert a new textbook tag' })
|
||||
@ApiBody({ type: TextbookTags, description: 'Textbook tag data to insert' })
|
||||
@ApiResponse({
|
||||
status: 400,
|
||||
description: 'Invalid textbook tag data',
|
||||
example: {
|
||||
"notification": {
|
||||
"exception": true,
|
||||
"exceptionSeverity": "HIGH",
|
||||
"exceptionMessage": "ERR.INVALID_DATA",
|
||||
"stackTrace": "Request"
|
||||
},
|
||||
"data": null
|
||||
}
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 404,
|
||||
description: 'Tag not created',
|
||||
example: {
|
||||
"notification": {
|
||||
"exception": true,
|
||||
"exceptionSeverity": "HIGH",
|
||||
"exceptionMessage": "ERR.INVALID_DATA",
|
||||
"stackTrace": "Tag not created"
|
||||
},
|
||||
"data": null
|
||||
}
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 201,
|
||||
description: 'Textbook tag successfully created',
|
||||
})
|
||||
async insert(@Body() textbookTags: TextbookTags, @Res() res: Response) {
|
||||
if(!textbookTags) {
|
||||
if (!textbookTags) {
|
||||
const response = new GenericResponse({
|
||||
exception: true,
|
||||
exceptionSeverity: 'HIGH',
|
||||
exceptionMessage: 'ERR.NO_ID_REQ',
|
||||
exceptionMessage: 'ERR.INVALID_DATA',
|
||||
stackTrace: 'Request'
|
||||
}, null);
|
||||
res.send(response);
|
||||
return;
|
||||
return res.status(400).send(response);
|
||||
}
|
||||
delete textbookTags.id;
|
||||
const response = await this.textbookTagsService.upsert(textbookTags, true);
|
||||
const httpResponse = new GenericResponse(null, response)
|
||||
res.send(httpResponse);
|
||||
if (!response) {
|
||||
const response = new GenericResponse({
|
||||
exception: true,
|
||||
exceptionSeverity: 'HIGH',
|
||||
exceptionMessage: 'ERR.INVALID_DATA',
|
||||
stackTrace: 'Tag not created'
|
||||
}, null);
|
||||
return res.status(404).send(response);
|
||||
}
|
||||
const httpResponse = new GenericResponse(null, response);
|
||||
res.status(201).send(httpResponse);
|
||||
}
|
||||
|
||||
@Put()
|
||||
@ApiOperation({ summary: 'Update an existing textbook tag' })
|
||||
@ApiBody({ type: TextbookTags, description: 'Textbook tag data to update' })
|
||||
@ApiResponse({
|
||||
status: 400,
|
||||
description: 'Invalid textbook tag data or ID missing',
|
||||
example: {
|
||||
"notification": {
|
||||
"exception": true,
|
||||
"exceptionSeverity": "HIGH",
|
||||
"exceptionMessage": "ERR.INVALID_DATA",
|
||||
"stackTrace": "Request"
|
||||
},
|
||||
"data": null
|
||||
}
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 404,
|
||||
description: 'Textbook tag not found',
|
||||
example: {
|
||||
"notification": {
|
||||
"exception": true,
|
||||
"exceptionSeverity": "HIGH",
|
||||
"exceptionMessage": "ERR.NOT_FOUND",
|
||||
"stackTrace": "Textbook tag not found"
|
||||
},
|
||||
"data": null
|
||||
}
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 200,
|
||||
description: 'Textbook tag successfully updated',
|
||||
})
|
||||
async update(@Body() textbookTags: TextbookTags, @Res() res: Response) {
|
||||
if(!textbookTags || !textbookTags.id) {
|
||||
if (!textbookTags || !textbookTags.id) {
|
||||
const response = new GenericResponse({
|
||||
exception: true,
|
||||
exceptionSeverity: 'HIGH',
|
||||
exceptionMessage: 'ERR.NO_ID_REQ',
|
||||
stackTrace: 'Request'
|
||||
}, null);
|
||||
res.send(response);
|
||||
return;
|
||||
return res.status(400).send(response);
|
||||
}
|
||||
const response = await this.textbookTagsService.upsert(textbookTags, false);
|
||||
const httpResponse = new GenericResponse(null, response)
|
||||
res.send(httpResponse);
|
||||
if (!response) {
|
||||
const response = new GenericResponse({
|
||||
exception: true,
|
||||
exceptionSeverity: 'HIGH',
|
||||
exceptionMessage: 'ERR.NOT_FOUND',
|
||||
stackTrace: 'Textbook tag not found'
|
||||
}, null);
|
||||
return res.status(404).send(response);
|
||||
}
|
||||
const httpResponse = new GenericResponse(null, response);
|
||||
res.status(200).send(httpResponse);
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
@ApiOperation({ summary: 'Delete a textbook tag by ID' })
|
||||
@ApiParam({ name: 'id', type: Number, description: 'Textbook tag 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: 'Textbook tag not found',
|
||||
example: {
|
||||
"notification": {
|
||||
"exception": true,
|
||||
"exceptionSeverity": "HIGH",
|
||||
"exceptionMessage": "ERR.NOT_FOUND",
|
||||
"stackTrace": "Textbook tag not found"
|
||||
},
|
||||
"data": null
|
||||
}
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 200,
|
||||
description: 'Textbook tag successfully deleted',
|
||||
})
|
||||
async deleteById(@Param('id') id: number, @Res() res: Response) {
|
||||
if(!id) {
|
||||
if (!id) {
|
||||
const response = new GenericResponse({
|
||||
exception: true,
|
||||
exceptionSeverity: 'HIGH',
|
||||
exceptionMessage: 'ERR.NO_ID_REQ',
|
||||
stackTrace: 'Request'
|
||||
}, null);
|
||||
res.send(response);
|
||||
return;
|
||||
return res.status(400).send(response);
|
||||
}
|
||||
const response = await this.textbookTagsService.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: 'Textbook tag not found'
|
||||
}, null);
|
||||
return res.status(404).send(response);
|
||||
}
|
||||
const httpResponse = new GenericResponse(null, response);
|
||||
res.status(200).send(httpResponse);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,40 +1,52 @@
|
||||
import { Table, Column, Model, Default, DataType } from 'sequelize-typescript';
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
|
||||
@Table({ tableName: 'textbook_tags' , paranoid : true})
|
||||
@Table({ tableName: 'textbook_tags', paranoid: true })
|
||||
export default class TextbookTag extends Model {
|
||||
|
||||
@ApiProperty({ type: Number })
|
||||
@Column(DataType.BIGINT)
|
||||
textbook_id: number;
|
||||
|
||||
@ApiProperty({ type: String })
|
||||
@Column(DataType.TEXT)
|
||||
tag_name: string;
|
||||
|
||||
@ApiProperty({ type: Date, default: new Date() })
|
||||
@Default(new Date())
|
||||
@Column(DataType.DATEONLY)
|
||||
validFrom: Date;
|
||||
|
||||
@ApiProperty({ type: Date, default: new Date("2070-12-31") })
|
||||
@Default(new Date("2070-12-31"))
|
||||
@Column(DataType.DATEONLY)
|
||||
validTill: Date;
|
||||
|
||||
@ApiProperty({ type: Date })
|
||||
@Column(DataType.DATEONLY)
|
||||
createdAt: Date;
|
||||
|
||||
@ApiProperty({ type: Date })
|
||||
@Column(DataType.DATEONLY)
|
||||
updatedAt: Date;
|
||||
|
||||
@ApiProperty({ type: String })
|
||||
@Column(DataType.TEXT)
|
||||
createBy: string;
|
||||
|
||||
@ApiProperty({ type: String })
|
||||
@Column(DataType.TEXT)
|
||||
modifiedBy: string;
|
||||
|
||||
@ApiProperty({ type: Date })
|
||||
@Column(DataType.DATEONLY)
|
||||
deletedAt: Date;
|
||||
|
||||
@ApiProperty({ type: Number })
|
||||
@Column(DataType.NUMBER)
|
||||
version: number;
|
||||
|
||||
@ApiProperty({ type: String })
|
||||
@Column(DataType.TEXT)
|
||||
status: string;
|
||||
}
|
||||
|
||||
@ -7,4 +7,4 @@ import { TextbookTagsController } from './textbook-tags.controller';
|
||||
providers: [TextbookTagsService, ],
|
||||
controllers: [TextbookTagsController, ]
|
||||
})
|
||||
export class TextbookTagssModule {}
|
||||
export class TextbookTagsModule {}
|
||||
|
||||
@ -1,107 +1,310 @@
|
||||
import { Body, Controller, Delete, Get, Param, Post, Put, Res } from '@nestjs/common';
|
||||
import { TextbookService } from './textbook.service';
|
||||
import { Response } from 'express';
|
||||
import { GenericResponse } from '../common/GenericResponse.model';
|
||||
import Textbook from './textbook.entity';
|
||||
import { TextbookService } from './textbook.service';
|
||||
import Textbook from './textbook.entity';
|
||||
import { ApiTags, ApiOperation, ApiResponse, ApiParam, ApiBody } from '@nestjs/swagger';
|
||||
|
||||
@ApiTags('textbooks')
|
||||
@Controller('textbooks')
|
||||
export class TextbookController {
|
||||
constructor(private textbookService: TextbookService) {}
|
||||
|
||||
@Get("/all")
|
||||
@ApiOperation({ summary: 'Get all textbooks' })
|
||||
@ApiResponse({
|
||||
status: 200,
|
||||
description: 'Successfully retrieved all textbooks',
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 404,
|
||||
description: 'No textbooks found',
|
||||
example: {
|
||||
"notification": {
|
||||
"exception": true,
|
||||
"exceptionSeverity": "HIGH",
|
||||
"exceptionMessage": "ERR.NOT_FOUND",
|
||||
"stackTrace": "No textbooks found"
|
||||
},
|
||||
"data": null
|
||||
}
|
||||
})
|
||||
async getAllTextbooks(@Res() res: Response) {
|
||||
const response = await this.textbookService.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 textbooks found'
|
||||
}, null);
|
||||
return res.status(404).send(errorResponse);
|
||||
}
|
||||
const httpResponse = new GenericResponse(null, response);
|
||||
res.status(200).send(httpResponse);
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
@ApiOperation({ summary: 'Get textbook by ID' })
|
||||
@ApiParam({ name: 'id', type: Number, description: 'Textbook 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: 'Textbook not found',
|
||||
example: {
|
||||
"notification": {
|
||||
"exception": true,
|
||||
"exceptionSeverity": "HIGH",
|
||||
"exceptionMessage": "ERR.NOT_FOUND",
|
||||
"stackTrace": "Textbook not found"
|
||||
},
|
||||
"data": null
|
||||
}
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 200,
|
||||
description: 'Successfully retrieved textbook by ID',
|
||||
})
|
||||
async findById(@Param('id') id: number, @Res() res: Response) {
|
||||
if(!id) {
|
||||
if (!id) {
|
||||
const response = new GenericResponse({
|
||||
exception: true,
|
||||
exceptionSeverity: 'HIGH',
|
||||
exceptionMessage: 'ERR.NO_ID_REQ',
|
||||
stackTrace: 'Request'
|
||||
}, null);
|
||||
res.send(response);
|
||||
return;
|
||||
return res.status(400).send(response);
|
||||
}
|
||||
const response = await this.textbookService.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: `Textbook 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 textbooks based on criteria' })
|
||||
@ApiBody({ type: Textbook, description: 'Filter criteria for textbooks' })
|
||||
@ApiResponse({
|
||||
status: 400,
|
||||
description: 'Invalid filter criteria',
|
||||
example: {
|
||||
"notification": {
|
||||
"exception": true,
|
||||
"exceptionSeverity": "HIGH",
|
||||
"exceptionMessage": "ERR.INVALID_CRITERIA",
|
||||
"stackTrace": "Request"
|
||||
},
|
||||
"data": null
|
||||
}
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 404,
|
||||
description: 'No textbooks found based on filter criteria',
|
||||
example: {
|
||||
"notification": {
|
||||
"exception": true,
|
||||
"exceptionSeverity": "HIGH",
|
||||
"exceptionMessage": "ERR.NOT_FOUND",
|
||||
"stackTrace": "No textbooks found based on the filter criteria"
|
||||
},
|
||||
"data": null
|
||||
}
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 200,
|
||||
description: 'Successfully filtered textbooks',
|
||||
})
|
||||
async filter(@Body() textbook: Textbook, @Res() res: Response) {
|
||||
if(!textbook) {
|
||||
if (!textbook) {
|
||||
const response = new GenericResponse({
|
||||
exception: true,
|
||||
exceptionSeverity: 'HIGH',
|
||||
exceptionMessage: 'ERR.NO_ID_REQ',
|
||||
exceptionMessage: 'ERR.INVALID_CRITERIA',
|
||||
stackTrace: 'Request'
|
||||
}, null);
|
||||
res.send(response);
|
||||
return;
|
||||
return res.status(400).send(response);
|
||||
}
|
||||
const response = await this.textbookService.filter(textbook) || [];
|
||||
const httpResponse = new GenericResponse(null, response)
|
||||
if (!response) {
|
||||
const errorResponse = new GenericResponse({
|
||||
exception: true,
|
||||
exceptionSeverity: 'HIGH',
|
||||
exceptionMessage: 'ERR.NOT_FOUND',
|
||||
stackTrace: 'No textbooks found based on the filter criteria'
|
||||
}, null);
|
||||
return res.status(404).send(errorResponse);
|
||||
}
|
||||
const httpResponse = new GenericResponse(null, response);
|
||||
res.status(200).send(httpResponse);
|
||||
}
|
||||
|
||||
@Post()
|
||||
@ApiOperation({ summary: 'Insert a new textbook' })
|
||||
@ApiBody({ type: Textbook, description: 'Textbook data to insert' })
|
||||
@ApiResponse({
|
||||
status: 400,
|
||||
description: 'Invalid textbook data',
|
||||
example: {
|
||||
"notification": {
|
||||
"exception": true,
|
||||
"exceptionSeverity": "HIGH",
|
||||
"exceptionMessage": "ERR.INVALID_DATA",
|
||||
"stackTrace": "Request"
|
||||
},
|
||||
"data": null
|
||||
}
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 201,
|
||||
description: 'Textbook successfully created',
|
||||
})
|
||||
async insert(@Body() textbook: Textbook, @Res() res: Response) {
|
||||
if(!textbook) {
|
||||
if (!textbook) {
|
||||
const response = new GenericResponse({
|
||||
exception: true,
|
||||
exceptionSeverity: 'HIGH',
|
||||
exceptionMessage: 'ERR.NO_ID_REQ',
|
||||
exceptionMessage: 'ERR.INVALID_DATA',
|
||||
stackTrace: 'Request'
|
||||
}, null);
|
||||
res.send(response);
|
||||
return;
|
||||
return res.status(400).send(response);
|
||||
}
|
||||
delete textbook.id;
|
||||
|
||||
const response = await this.textbookService.upsert(textbook, true);
|
||||
const httpResponse = new GenericResponse(null, response)
|
||||
res.send(httpResponse);
|
||||
const httpResponse = new GenericResponse(null, response);
|
||||
res.status(201).send(httpResponse);
|
||||
}
|
||||
|
||||
@Put()
|
||||
@ApiOperation({ summary: 'Update an existing textbook' })
|
||||
@ApiBody({ type: Textbook, description: 'Textbook data to update' })
|
||||
@ApiResponse({
|
||||
status: 400,
|
||||
description: 'Invalid textbook data or ID missing',
|
||||
example: {
|
||||
"notification": {
|
||||
"exception": true,
|
||||
"exceptionSeverity": "HIGH",
|
||||
"exceptionMessage": "ERR.INVALID_DATA",
|
||||
"stackTrace": "Request"
|
||||
},
|
||||
"data": null
|
||||
}
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 404,
|
||||
description: 'Textbook not found',
|
||||
example: {
|
||||
"notification": {
|
||||
"exception": true,
|
||||
"exceptionSeverity": "HIGH",
|
||||
"exceptionMessage": "ERR.NOT_FOUND",
|
||||
"stackTrace": "Textbook not found"
|
||||
},
|
||||
"data": null
|
||||
}
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 200,
|
||||
description: 'Textbook successfully updated',
|
||||
})
|
||||
async update(@Body() textbook: Textbook, @Res() res: Response) {
|
||||
if(!textbook || !textbook.id) {
|
||||
if (!textbook || !textbook.id) {
|
||||
const response = new GenericResponse({
|
||||
exception: true,
|
||||
exceptionSeverity: 'HIGH',
|
||||
exceptionMessage: 'ERR.NO_ID_REQ',
|
||||
stackTrace: 'Request'
|
||||
}, null);
|
||||
res.send(response);
|
||||
return;
|
||||
return res.status(400).send(response);
|
||||
}
|
||||
|
||||
const response = await this.textbookService.upsert(textbook, 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: `Textbook with ID ${textbook.id} not found`
|
||||
}, null);
|
||||
return res.status(404).send(errorResponse);
|
||||
}
|
||||
const httpResponse = new GenericResponse(null, response);
|
||||
res.status(200).send(httpResponse);
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
@ApiOperation({ summary: 'Delete a textbook by ID' })
|
||||
@ApiParam({ name: 'id', type: Number, description: 'Textbook 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: 'Textbook not found',
|
||||
example: {
|
||||
"notification": {
|
||||
"exception": true,
|
||||
"exceptionSeverity": "HIGH",
|
||||
"exceptionMessage": "ERR.NOT_FOUND",
|
||||
"stackTrace": "Textbook not found"
|
||||
},
|
||||
"data": null
|
||||
}
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 200,
|
||||
description: 'Textbook successfully deleted',
|
||||
})
|
||||
async deleteById(@Param('id') id: number, @Res() res: Response) {
|
||||
if(!id) {
|
||||
if (!id) {
|
||||
const response = new GenericResponse({
|
||||
exception: true,
|
||||
exceptionSeverity: 'HIGH',
|
||||
exceptionMessage: 'ERR.NO_ID_REQ',
|
||||
stackTrace: 'Request'
|
||||
}, null);
|
||||
res.send(response);
|
||||
return;
|
||||
return res.status(400).send(response);
|
||||
}
|
||||
const response = await this.textbookService.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: `Textbook with ID ${id} not found`
|
||||
}, null);
|
||||
return res.status(404).send(errorResponse);
|
||||
}
|
||||
const httpResponse = new GenericResponse(null, response);
|
||||
res.status(200).send(httpResponse);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -1,52 +1,68 @@
|
||||
import { Table, Column, Model, Default, DataType } from 'sequelize-typescript';
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
|
||||
@Table({ tableName: 'textbook' , paranoid : true})
|
||||
@Table({ tableName: 'textbook', paranoid: true })
|
||||
export default class Textbook extends Model {
|
||||
|
||||
@ApiProperty({ type: String })
|
||||
@Column(DataType.TEXT)
|
||||
title: string;
|
||||
|
||||
@ApiProperty({ type: String })
|
||||
@Column(DataType.TEXT)
|
||||
author: string;
|
||||
|
||||
@ApiProperty({ type: String })
|
||||
@Column(DataType.TEXT)
|
||||
publisher: string;
|
||||
|
||||
@ApiProperty({ type: String })
|
||||
@Column(DataType.TEXT)
|
||||
edition: string;
|
||||
|
||||
@ApiProperty({ type: String })
|
||||
@Column(DataType.TEXT)
|
||||
file_url: string;
|
||||
|
||||
@ApiProperty({ type: String })
|
||||
@Column(DataType.TEXT)
|
||||
file_type: string;
|
||||
|
||||
@ApiProperty({ type: Date, default: new Date() })
|
||||
@Default(new Date())
|
||||
@Column(DataType.DATEONLY)
|
||||
validFrom: Date;
|
||||
|
||||
@ApiProperty({ type: Date, default: new Date("2070-12-31") })
|
||||
@Default(new Date("2070-12-31"))
|
||||
@Column(DataType.DATEONLY)
|
||||
validTill: Date;
|
||||
|
||||
@ApiProperty({ type: Date })
|
||||
@Column(DataType.DATEONLY)
|
||||
createdAt: Date;
|
||||
|
||||
@ApiProperty({ type: Date })
|
||||
@Column(DataType.DATEONLY)
|
||||
updatedAt: Date;
|
||||
|
||||
@ApiProperty({ type: String })
|
||||
@Column(DataType.TEXT)
|
||||
createBy: string;
|
||||
|
||||
@ApiProperty({ type: String })
|
||||
@Column(DataType.TEXT)
|
||||
modifiedBy: string;
|
||||
|
||||
@ApiProperty({ type: Date })
|
||||
@Column(DataType.DATEONLY)
|
||||
deletedAt: Date;
|
||||
|
||||
@ApiProperty({ type: Number })
|
||||
@Column(DataType.NUMBER)
|
||||
version: number;
|
||||
|
||||
@ApiProperty({ type: String })
|
||||
@Column(DataType.TEXT)
|
||||
status: string;
|
||||
}
|
||||
|
||||
@ -1,108 +1,332 @@
|
||||
import { Body, Controller, Delete, Get, Param, Post, Put, Res } from '@nestjs/common';
|
||||
import { Response } from 'express';
|
||||
import { GenericResponse } from 'src/common/GenericResponse.model';
|
||||
import Topics from './topics.entity';
|
||||
import Topics from './topics.entity';
|
||||
import { TopicsService } from './topics.service';
|
||||
import { ApiTags, ApiOperation, ApiResponse, ApiParam, ApiBody } from '@nestjs/swagger';
|
||||
|
||||
@ApiTags('topics')
|
||||
@Controller('topics')
|
||||
export class TopicsController {
|
||||
|
||||
constructor(private userTypeService?: TopicsService) {
|
||||
if(!userTypeService) {
|
||||
userTypeService = new TopicsService();
|
||||
}
|
||||
}
|
||||
constructor(private topicsService: TopicsService) {}
|
||||
|
||||
@Get("/all")
|
||||
@ApiOperation({ summary: 'Get all topics' })
|
||||
@ApiResponse({
|
||||
status: 200,
|
||||
description: 'Successfully retrieved all topics',
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 404,
|
||||
description: 'No topics found',
|
||||
example: {
|
||||
"notification": {
|
||||
"exception": true,
|
||||
"exceptionSeverity": "HIGH",
|
||||
"exceptionMessage": "ERR.NOT_FOUND",
|
||||
"stackTrace": "No topics found"
|
||||
},
|
||||
"data": null
|
||||
}
|
||||
})
|
||||
async getAll(@Res() res: Response) {
|
||||
const response = await this.userTypeService.findAll() || [];
|
||||
const httpResponse = new GenericResponse(null, response)
|
||||
res.send(httpResponse);
|
||||
const response = await this.topicsService.findAll() || [];
|
||||
if(!response) {
|
||||
const response = new GenericResponse({
|
||||
exception: true,
|
||||
exceptionSeverity: 'HIGH',
|
||||
exceptionMessage: 'ERR.NOT_FOUND',
|
||||
stackTrace: 'No topics found'
|
||||
}, null);
|
||||
return res.status(404).send(response);
|
||||
}
|
||||
const httpResponse = new GenericResponse(null, response);
|
||||
res.status(200).send(httpResponse);
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
async FindById(@Param('id') id: number, @Res() res: Response) {
|
||||
if(!id) {
|
||||
@ApiOperation({ summary: 'Get a topic by ID' })
|
||||
@ApiParam({ name: 'id', type: Number, description: 'Topic ID' })
|
||||
@ApiResponse({
|
||||
status: 400,
|
||||
description: 'ID parameter is required',
|
||||
example: {
|
||||
"notification": {
|
||||
"exception": true,
|
||||
"exceptionSeverity": "HIGH",
|
||||
"exceptionMessage": "ERR.NO_ID_IN_REQ",
|
||||
"stackTrace": "Request"
|
||||
},
|
||||
"data": null
|
||||
}
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 404,
|
||||
description: 'Topic not found',
|
||||
example: {
|
||||
"notification": {
|
||||
"exception": true,
|
||||
"exceptionSeverity": "HIGH",
|
||||
"exceptionMessage": "ERR.NOT_FOUND",
|
||||
"stackTrace": "Topic not found"
|
||||
},
|
||||
"data": null
|
||||
}
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 200,
|
||||
description: 'Successfully retrieved topic by ID',
|
||||
})
|
||||
async findById(@Param('id') id: number, @Res() res: Response) {
|
||||
if (!id) {
|
||||
const response = new GenericResponse({
|
||||
exception: true,
|
||||
exceptionSeverity: 'HIGH',
|
||||
exceptionMessage: 'ERR.NO_ID_IN_REQ',
|
||||
stackTrace: 'Request'
|
||||
}, null);
|
||||
res.send(response);
|
||||
return;
|
||||
return res.status(400).send(response);
|
||||
}
|
||||
const response = await this.userTypeService.findByPk(id) || {};
|
||||
const httpResponse = new GenericResponse(null, response)
|
||||
res.send(httpResponse);
|
||||
const response = await this.topicsService.findByPk(id) || {};
|
||||
if (!response) {
|
||||
const response = new GenericResponse({
|
||||
exception: true,
|
||||
exceptionSeverity: 'HIGH',
|
||||
exceptionMessage: 'ERR.NOT_FOUND',
|
||||
stackTrace: 'Topic not found'
|
||||
}, null);
|
||||
return res.status(404).send(response);
|
||||
}
|
||||
const httpResponse = new GenericResponse(null, response);
|
||||
res.status(200).send(httpResponse);
|
||||
}
|
||||
|
||||
@Post('/filter')
|
||||
@ApiOperation({ summary: 'Filter topics based on criteria' })
|
||||
@ApiBody({ type: Topics, description: 'Filter criteria for topics' })
|
||||
@ApiResponse({
|
||||
status: 400,
|
||||
description: 'Invalid filter criteria',
|
||||
example: {
|
||||
"notification": {
|
||||
"exception": true,
|
||||
"exceptionSeverity": "HIGH",
|
||||
"exceptionMessage": "ERR.INVALID_CRITERIA",
|
||||
"stackTrace": "Request"
|
||||
},
|
||||
"data": null
|
||||
}
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 404,
|
||||
description: 'No topics found based on filter criteria',
|
||||
example: {
|
||||
"notification": {
|
||||
"exception": true,
|
||||
"exceptionSeverity": "HIGH",
|
||||
"exceptionMessage": "ERR.NOT_FOUND",
|
||||
"stackTrace": "No topics found based on the filter criteria"
|
||||
},
|
||||
"data": null
|
||||
}
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 200,
|
||||
description: 'Successfully filtered topics',
|
||||
})
|
||||
async filter(@Body() user: Topics, @Res() res: Response) {
|
||||
if(!user) {
|
||||
if (!user) {
|
||||
const response = new GenericResponse({
|
||||
exception: true,
|
||||
exceptionSeverity: 'HIGH',
|
||||
exceptionMessage: 'ERR.NO_REQ',
|
||||
stackTrace: 'Request'
|
||||
}, null);
|
||||
res.send(response);
|
||||
return;
|
||||
return res.status(400).send(response);
|
||||
}
|
||||
const response = await this.userTypeService.filter(user) || [];
|
||||
const httpResponse = new GenericResponse(null, response)
|
||||
res.send(httpResponse);
|
||||
const response = await this.topicsService.filter(user) || [];
|
||||
if (!response) {
|
||||
const response = new GenericResponse({
|
||||
exception: true,
|
||||
exceptionSeverity: 'HIGH',
|
||||
exceptionMessage: 'ERR.NOT_FOUND',
|
||||
stackTrace: 'No topics found based on the filter criteria'
|
||||
}, null);
|
||||
return res.status(404).send(response);
|
||||
}
|
||||
const httpResponse = new GenericResponse(null, response);
|
||||
res.status(200).send(httpResponse);
|
||||
}
|
||||
|
||||
@Post()
|
||||
@ApiOperation({ summary: 'Insert a new topic' })
|
||||
@ApiBody({ type: Topics, description: 'Topic data to insert' })
|
||||
@ApiResponse({
|
||||
status: 400,
|
||||
description: 'Invalid topic data',
|
||||
example: {
|
||||
"notification": {
|
||||
"exception": true,
|
||||
"exceptionSeverity": "HIGH",
|
||||
"exceptionMessage": "ERR.INVALID_DATA",
|
||||
"stackTrace": "Request"
|
||||
},
|
||||
"data": null
|
||||
}
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 404,
|
||||
description: 'Topic not created',
|
||||
example: {
|
||||
"notification": {
|
||||
"exception": true,
|
||||
"exceptionSeverity": "HIGH",
|
||||
"exceptionMessage": "ERR.NOT_CREATED",
|
||||
"stackTrace": "Topic not created"
|
||||
},
|
||||
"data": null
|
||||
}
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 201,
|
||||
description: 'Successfully created topic',
|
||||
})
|
||||
async insert(@Body() user: Topics, @Res() res: Response) {
|
||||
if(!user) {
|
||||
if (!user) {
|
||||
const response = new GenericResponse({
|
||||
exception: true,
|
||||
exceptionSeverity: 'HIGH',
|
||||
exceptionMessage: 'ERR.NO_REQ',
|
||||
stackTrace: 'Request'
|
||||
}, null);
|
||||
res.send(response);
|
||||
return;
|
||||
return res.status(400).send(response);
|
||||
}
|
||||
delete user.id;
|
||||
const response = await this.userTypeService.upsert(user, true);
|
||||
const httpResponse = new GenericResponse(null, response)
|
||||
res.send(httpResponse);
|
||||
const response = await this.topicsService.upsert(user, true);
|
||||
if (!response) {
|
||||
const response = new GenericResponse({
|
||||
exception: true,
|
||||
exceptionSeverity: 'HIGH',
|
||||
exceptionMessage: 'ERR.NOT_CREATED',
|
||||
stackTrace: 'Topic not created'
|
||||
}, null);
|
||||
return res.status(404).send(response);
|
||||
}
|
||||
const httpResponse = new GenericResponse(null, response);
|
||||
res.status(201).send(httpResponse);
|
||||
}
|
||||
|
||||
@Put()
|
||||
@ApiOperation({ summary: 'Update an existing topic' })
|
||||
@ApiBody({ type: Topics, description: 'Topic data to update' })
|
||||
@ApiResponse({
|
||||
status: 400,
|
||||
description: 'Invalid topic data or ID missing',
|
||||
example: {
|
||||
"notification": {
|
||||
"exception": true,
|
||||
"exceptionSeverity": "HIGH",
|
||||
"exceptionMessage": "ERR.NO_ID_IN_REQ",
|
||||
"stackTrace": "Request"
|
||||
},
|
||||
"data": null
|
||||
}
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 404,
|
||||
description: 'Topic not found',
|
||||
example: {
|
||||
"notification": {
|
||||
"exception": true,
|
||||
"exceptionSeverity": "HIGH",
|
||||
"exceptionMessage": "ERR.NOT_FOUND",
|
||||
"stackTrace": "Topic not found"
|
||||
},
|
||||
"data": null
|
||||
}
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 200,
|
||||
description: 'Topic successfully updated',
|
||||
})
|
||||
async update(@Body() user: Topics, @Res() res: Response) {
|
||||
if(!user || !user.id) {
|
||||
if (!user || !user.id) {
|
||||
const response = new GenericResponse({
|
||||
exception: true,
|
||||
exceptionSeverity: 'HIGH',
|
||||
exceptionMessage: 'ERR.NO_REQ',
|
||||
stackTrace: 'Request'
|
||||
}, null);
|
||||
res.send(response);
|
||||
return;
|
||||
return res.status(400).send(response);
|
||||
}
|
||||
const response = await this.userTypeService.upsert(user, false);
|
||||
const httpResponse = new GenericResponse(null, response)
|
||||
res.send(httpResponse);
|
||||
const response = await this.topicsService.upsert(user, false);
|
||||
if (!response) {
|
||||
const errorResponse = new GenericResponse({
|
||||
exception: true,
|
||||
exceptionSeverity: 'HIGH',
|
||||
exceptionMessage: 'ERR.NOT_FOUND',
|
||||
stackTrace: `Topic with ID ${user.id} not found`
|
||||
}, null);
|
||||
return res.status(404).send(errorResponse);
|
||||
}
|
||||
const httpResponse = new GenericResponse(null, response);
|
||||
res.status(200).send(httpResponse);
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
@ApiOperation({ summary: 'Delete a topic by ID' })
|
||||
@ApiParam({ name: 'id', type: Number, description: 'Topic ID to delete' })
|
||||
@ApiResponse({
|
||||
status: 400,
|
||||
description: 'ID parameter is required',
|
||||
example: {
|
||||
"notification": {
|
||||
"exception": true,
|
||||
"exceptionSeverity": "HIGH",
|
||||
"exceptionMessage": "ERR.NO_ID_IN_REQ",
|
||||
"stackTrace": "Request"
|
||||
},
|
||||
"data": null
|
||||
}
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 404,
|
||||
description: 'Topic not found',
|
||||
example: {
|
||||
"notification": {
|
||||
"exception": true,
|
||||
"exceptionSeverity": "HIGH",
|
||||
"exceptionMessage": "ERR.NOT_FOUND",
|
||||
"stackTrace": "Topic not found"
|
||||
},
|
||||
"data": null
|
||||
}
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 200,
|
||||
description: 'Topic successfully deleted',
|
||||
})
|
||||
async deleteById(@Param('id') id: number, @Res() res: Response) {
|
||||
if(!id) {
|
||||
if (!id) {
|
||||
const response = new GenericResponse({
|
||||
exception: true,
|
||||
exceptionSeverity: 'HIGH',
|
||||
exceptionMessage: 'ERR.NO_REQ',
|
||||
exceptionMessage: 'ERR.NO_ID_IN_REQ',
|
||||
stackTrace: 'Request'
|
||||
}, null);
|
||||
res.send(response);
|
||||
return;
|
||||
return res.status(400).send(response);
|
||||
}
|
||||
const response = await this.userTypeService.remove(id) || {};
|
||||
const httpResponse = new GenericResponse(null, response)
|
||||
res.send(httpResponse);
|
||||
const response = await this.topicsService.remove(id) || {};
|
||||
if(!response) {
|
||||
const response = new GenericResponse({
|
||||
exception: true,
|
||||
exceptionSeverity: 'HIGH',
|
||||
exceptionMessage: 'ERR.NOT_FOUND',
|
||||
stackTrace: 'Topic not found'
|
||||
},null);
|
||||
return res.status(404).send(response);
|
||||
}
|
||||
const httpResponse = new GenericResponse(null, response);
|
||||
res.status(200).send(httpResponse);
|
||||
}
|
||||
}
|
||||
@ -1,46 +1,60 @@
|
||||
import { Table, Column, Model, Default, DataType } from 'sequelize-typescript';
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
|
||||
@Table({ tableName: 'topics' , paranoid : true})
|
||||
@Table({ tableName: 'topics', paranoid: true })
|
||||
export default class Topics extends Model {
|
||||
|
||||
@ApiProperty({ type: Number })
|
||||
@Column(DataType.BIGINT)
|
||||
section_id: number;
|
||||
|
||||
@ApiProperty({ type: String })
|
||||
@Column(DataType.TEXT)
|
||||
title: string;
|
||||
|
||||
@ApiProperty({ type: String })
|
||||
@Column(DataType.TEXT)
|
||||
description: string;
|
||||
|
||||
@ApiProperty({ type: Number })
|
||||
@Column(DataType.NUMBER)
|
||||
page_number: number;
|
||||
|
||||
@ApiProperty({ type: Date, default: new Date() })
|
||||
@Default(new Date())
|
||||
@Column(DataType.DATEONLY)
|
||||
validFrom: Date;
|
||||
|
||||
@ApiProperty({ type: Date, default: new Date("2070-12-31") })
|
||||
@Default(new Date("2070-12-31"))
|
||||
@Column(DataType.DATEONLY)
|
||||
validTill: Date;
|
||||
|
||||
@ApiProperty({ type: Date })
|
||||
@Column(DataType.DATEONLY)
|
||||
createdAt: Date;
|
||||
|
||||
@ApiProperty({ type: Date })
|
||||
@Column(DataType.DATEONLY)
|
||||
updatedAt: Date;
|
||||
|
||||
@ApiProperty({ type: String })
|
||||
@Column(DataType.TEXT)
|
||||
createBy: string;
|
||||
|
||||
@ApiProperty({ type: String })
|
||||
@Column(DataType.TEXT)
|
||||
modifiedBy: string;
|
||||
|
||||
@ApiProperty({ type: Date })
|
||||
@Column(DataType.DATEONLY)
|
||||
deletedAt: Date;
|
||||
|
||||
@ApiProperty({ type: Number })
|
||||
@Column(DataType.NUMBER)
|
||||
version: number;
|
||||
|
||||
@ApiProperty({ type: String })
|
||||
@Column(DataType.TEXT)
|
||||
status: string;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user