added validationPipes

This commit is contained in:
harshithnrao 2025-04-11 13:14:06 +05:30
parent 90f378a877
commit 0fceef8c44
51 changed files with 394 additions and 301 deletions

View File

@ -1,4 +1,4 @@
import { Body, Controller, Delete, Get, Param, Post, Put, Res } from '@nestjs/common';
import { Body, Controller, Delete, Get, Param, Post, Put, Res, UsePipes, ValidationPipe } from '@nestjs/common';
import { ActionsService } from './actions.service';
import { Response } from 'express';
import { GenericResponse } from '../common/GenericResponse.model';
@ -50,6 +50,7 @@ export class ActionsController {
}
@Post()
@UsePipes(new ValidationPipe({ whitelist: true}))
async insert(@Body() actions: Actions, @Res() res: Response) {
if(!actions) {
const response = new GenericResponse({

View File

@ -25,7 +25,7 @@ export class ActionsService {
return Actions.destroy({ where: { id: id } });
}
async upsert(actions: Actions, insertIfNotFound: boolean): Promise<Actions | [affectedCount: number]> {
async upsert(actions: any, insertIfNotFound: boolean): Promise<Actions | [affectedCount: number]> {
if (actions.id) {
const existingActions = await this.findByPk(actions.id);
if (existingActions) {

View File

@ -13,7 +13,7 @@ export class AuthService {
constructor(private userService: UserService, private jwtService: JwtService) { }
private signToken(payload: any, type: 'accessToken' | 'refreshToken') {
private signToken(payload: any, type: 'accessToken' | 'refreshToken') {
const config = Utility.jwtConfig[type];
return this.jwtService.sign(payload, {
secret: config.secretOrKey,
@ -28,17 +28,17 @@ export class AuthService {
secret: config.secretOrKey,
});
} catch (error) {
// console.log(`${type} token is invalid`, error);
return null;
}
}
async validateUser(payload: JwtPayload) {
async validateUser(payload: any) {
return this.userService.findByEmail(payload.email);
}
async login(user: any) {
const payload: JwtPayload = { email: user.email, password: user.password };
const { password, ...rest } = user;
const payload = { rest };
const accessToken = this.signToken(payload, 'accessToken');
const refreshToken = this.signToken(payload, 'refreshToken');
await RefreshToken.create({ email: user.email, token: refreshToken, type: 'jwt' });
@ -49,7 +49,8 @@ export class AuthService {
}
async signup(user: any) {
const payload: JwtPayload = { email: user.email, password: user.password };
const { password, ...rest } = user;
const payload = { rest };
const accessToken = this.signToken(payload, 'accessToken');
const refreshToken = this.signToken(payload, 'refreshToken');
await RefreshToken.create({ email: user.email, token: refreshToken, type: 'jwt' });
@ -64,34 +65,23 @@ export class AuthService {
if (!payload) {
throw new Error('Invalid refresh token');
}
// console.log(refreshToken);
// console.log(payload);
const user = await this.userService.findByEmail(payload.email);
if (!user) {
throw new Error('User not found');
}
// console.log(user)
const accessToken = this.signToken({
email: payload.email
}, 'accessToken');
// console.log(accessToken)
const { password, ...rest } = user;
const newPayload = { rest };
const accessToken = this.signToken({ newPayload }, 'accessToken');
return { access_token: accessToken };
}
async verifyRefreshToken(refreshToken: string) {
const payload = this.verifyToken(refreshToken, 'refreshToken');
if (payload) {
console.log("Refresh token is valid", payload);
}
return payload;
}
async verifyAccessToken(accessToken: string) {
const payload = this.verifyToken(accessToken, 'accessToken');
if (payload) {
console.log("Access token is valid", payload);
}
return payload;
}
@ -122,8 +112,9 @@ export class AuthService {
}
const payload = existingUser.get();
const accessToken = await this.signToken(payload, 'accessToken');
const refreshToken = await this.signToken(payload, 'refreshToken');
const { password, ...rest } = payload
const accessToken = this.signToken(rest, 'accessToken');
const refreshToken = this.signToken(rest, 'refreshToken');
await RefreshToken.create({ email: payload.email, token: refreshToken, type: 'jwt' });
return {
statusCode: 200,

View File

@ -1,14 +1,15 @@
import { Body, Controller, Delete, Get, Param, Post, Put, Res } from '@nestjs/common';
import { CastService } from './cast.service';
import { Body, Controller, Delete, Get, Param, Post, Put, Res, UsePipes, ValidationPipe } from '@nestjs/common';
import { CastService } from './cast.service';
import { Response } from 'express';
import { GenericResponse } from '../common/GenericResponse.model';
import Cast from './cast.entity';
import Cast from './cast.entity';
import { ApiTags, ApiOperation, ApiResponse, ApiParam, ApiBody } from '@nestjs/swagger';
import { CastDTO, CastUpdateDTO } from './cast.dto';
@ApiTags('cast')
@Controller('cast')
export class CastController {
constructor(private castService: CastService) {}
constructor(private castService: CastService) { }
@Get("/all")
@ApiOperation({ summary: 'Get all casts' })
@ -160,7 +161,7 @@ export class CastController {
@Post()
@ApiOperation({ summary: 'Insert a new cast' })
@ApiBody({ type: Cast, description: 'Cast data to insert' })
@ApiBody({ type: CastDTO, description: 'Cast data to insert' })
@ApiResponse({
status: 400,
description: 'Invalid cast data',
@ -178,7 +179,8 @@ export class CastController {
status: 201,
description: 'Successfully created a cast',
})
async insert(@Body() cast: Cast, @Res() res: Response) {
@UsePipes(new ValidationPipe({ whitelist: true}))
async insert(@Body() cast: CastDTO, @Res() res: Response) {
if (!cast) {
const response = new GenericResponse({
exception: true,
@ -188,7 +190,6 @@ export class CastController {
}, null);
return res.status(400).send(response);
}
delete cast.id; // Ensure no ID is passed in the creation
const response = await this.castService.upsert(cast, true);
const httpResponse = new GenericResponse(null, response);
res.status(201).send(httpResponse);
@ -196,7 +197,7 @@ export class CastController {
@Put()
@ApiOperation({ summary: 'Update an existing cast' })
@ApiBody({ type: Cast, description: 'Cast data to update' })
@ApiBody({ type: CastUpdateDTO, description: 'Cast data to update' })
@ApiResponse({
status: 400,
description: 'Invalid cast data or ID missing',
@ -227,7 +228,8 @@ export class CastController {
status: 200,
description: 'Successfully updated cast',
})
async update(@Body() cast: Cast, @Res() res: Response) {
@UsePipes(new ValidationPipe({ whitelist: true, skipMissingProperties: true }))
async update(@Body() cast: CastUpdateDTO, @Res() res: Response) {
if (!cast || !cast.id) {
const response = new GenericResponse({
exception: true,

View File

@ -2,7 +2,7 @@ import { IsString, IsNumber, IsDate, IsOptional, IsNotEmpty } from 'class-valida
import { ApiProperty } from '@nestjs/swagger';
import { Transform } from 'class-transformer';
export class CastMemberDTO {
export class CastDTO {
@ApiProperty({ type: Number })
@IsNumber()
@ -69,3 +69,11 @@ export class CastMemberDTO {
@IsNotEmpty()
version: number;
}
export class CastUpdateDTO extends CastDTO {
@ApiProperty({ type: Number })
@IsNumber()
@IsNotEmpty()
id: number;
}

View File

@ -27,7 +27,7 @@ export class CastService {
return Cast.destroy({ where: { id: id } });
}
async upsert(cast: Cast, insertIfNotFound: boolean): Promise<Cast | [affectedCount: number]> {
async upsert(cast: any, insertIfNotFound: boolean): Promise<Cast | [affectedCount: number]> {
if (cast.id) {
const existingCast = await this.findByPk(cast.id);
if (existingCast) {

View File

@ -1,9 +1,10 @@
import { Body, Controller, Delete, Get, Param, Post, Put, Res } from '@nestjs/common';
import { Body, Controller, Delete, Get, Param, Post, Put, Res, UsePipes, ValidationPipe } from '@nestjs/common';
import { EventAnalyticsService } from './event-analytics.service';
import { Response } from 'express';
import { GenericResponse } from '../common/GenericResponse.model';
import EventAnalytics from './event-analytics.entity';
import { ApiTags, ApiOperation, ApiResponse, ApiParam, ApiBody } from '@nestjs/swagger';
import { EventAnalyticsDTO, EventAnalyticsUpdateDTO } from './event-analytics.dto';
@ApiTags('event-analytics')
@Controller('event-analytics')
@ -148,7 +149,7 @@ export class EventAnalyticsController {
@Post()
@ApiOperation({ summary: 'Insert a new event analytics record' })
@ApiBody({ type: EventAnalytics, description: 'Event analytics data to insert' })
@ApiBody({ type: EventAnalyticsDTO, description: 'Event analytics data to insert' })
@ApiResponse({
status: 400,
description: 'Invalid event analytics data',
@ -163,7 +164,8 @@ export class EventAnalyticsController {
}
})
@ApiResponse({ status: 201, description: 'Successfully created event analytics record' })
async insert(@Body() analytics: EventAnalytics, @Res() res: Response) {
@UsePipes(new ValidationPipe({ whitelist: true}))
async insert(@Body() analytics: EventAnalyticsDTO, @Res() res: Response) {
if (!analytics) {
return res.status(400).send(new GenericResponse({
exception: true,
@ -172,15 +174,13 @@ export class EventAnalyticsController {
stackTrace: 'Request'
}, null));
}
delete analytics.id;
const response = await this.eventAnalyticsService.upsert(analytics, true);
res.status(201).send(new GenericResponse(null, response));
}
@Put()
@ApiOperation({ summary: 'Update an existing event analytics record' })
@ApiBody({ type: EventAnalytics, description: 'Event analytics data to update' })
@ApiBody({ type: EventAnalyticsUpdateDTO, description: 'Event analytics data to update' })
@ApiResponse({
status: 400,
description: 'Invalid event analytics data or ID missing',
@ -208,7 +208,8 @@ export class EventAnalyticsController {
}
})
@ApiResponse({ status: 200, description: 'Successfully updated event analytics record' })
async update(@Body() analytics: EventAnalytics, @Res() res: Response) {
@UsePipes(new ValidationPipe({ whitelist: true, skipMissingProperties: true }))
async update(@Body() analytics: EventAnalyticsUpdateDTO, @Res() res: Response) {
if (!analytics || !analytics.id) {
return res.status(400).send(new GenericResponse({
exception: true,

View File

@ -27,7 +27,7 @@ export class EventAnalyticsService {
return EventAnalytics.destroy({ where: { id: id } });
}
async upsert(eventAnalytics: EventAnalytics, insertIfNotFound: boolean): Promise<EventAnalytics | [affectedCount: number]> {
async upsert(eventAnalytics: any, insertIfNotFound: boolean): Promise<EventAnalytics | [affectedCount: number]> {
if (eventAnalytics.id) {
const existing = await this.findByPk(eventAnalytics.id);
if (existing) {

View File

@ -1,9 +1,10 @@
import { Body, Controller, Delete, Get, Param, Post, Put, Res } from '@nestjs/common';
import { Body, Controller, Delete, Get, Param, Post, Put, Res, UsePipes, ValidationPipe } from '@nestjs/common';
import { EventCategoryService } from './event-category.service';
import { Response } from 'express';
import { GenericResponse } from '../common/GenericResponse.model';
import EventCategory from './event-category.entity';
import { ApiTags, ApiOperation, ApiResponse, ApiParam, ApiBody } from '@nestjs/swagger';
import { EventCategoryDTO, EventCategoryUpdateDTO } from './event-category.dto';
@ApiTags('eventCategory')
@Controller('eventCategory')
@ -151,7 +152,7 @@ export class EventCategoryController {
@Post()
@ApiOperation({ summary: 'Insert a new event category' })
@ApiBody({ type: EventCategory, description: 'Event category data to insert' })
@ApiBody({ type: EventCategoryDTO, description: 'Event category data to insert' })
@ApiResponse({ status: 201, description: 'Successfully created an event category' })
@ApiResponse({
status: 400,
@ -166,7 +167,8 @@ export class EventCategoryController {
data: null
}
})
async insert(@Body() category: EventCategory, @Res() res: Response) {
@UsePipes(new ValidationPipe({ whitelist: true}))
async insert(@Body() category: EventCategoryDTO, @Res() res: Response) {
if (!category) {
return res.status(400).send(new GenericResponse({
exception: true,
@ -175,15 +177,13 @@ export class EventCategoryController {
stackTrace: 'Request'
}, null));
}
delete category.id;
const response = await this.eventCategoryService.upsert(category, true);
res.status(201).send(new GenericResponse(null, response));
}
@Put()
@ApiOperation({ summary: 'Update an existing event category' })
@ApiBody({ type: EventCategory, description: 'Event category data to update' })
@ApiBody({ type: EventCategoryUpdateDTO, description: 'Event category data to update' })
@ApiResponse({ status: 200, description: 'Successfully updated event category' })
@ApiResponse({
status: 400,
@ -211,7 +211,8 @@ export class EventCategoryController {
data: null
}
})
async update(@Body() category: EventCategory, @Res() res: Response) {
@UsePipes(new ValidationPipe({ whitelist: true, skipMissingProperties: true }))
async update(@Body() category: EventCategoryUpdateDTO, @Res() res: Response) {
if (!category || !category.id) {
return res.status(400).send(new GenericResponse({
exception: true,

View File

@ -26,7 +26,7 @@ export class EventCategoryService {
return EventCategory.destroy({ where: { id } });
}
async upsert(category: EventCategory, insertIfNotFound: boolean): Promise<EventCategory | [affectedCount: number]> {
async upsert(category: any, insertIfNotFound: boolean): Promise<EventCategory | [affectedCount: number]> {
if (category.id) {
const existingCategory = await this.findByPk(category.id);
if (existingCategory) {

View File

@ -1,9 +1,10 @@
import { Body, Controller, Delete, Get, Param, Post, Put, Res } from '@nestjs/common';
import { Body, Controller, Delete, Get, Param, Post, Put, Res, UsePipes, ValidationPipe } from '@nestjs/common';
import { EventEpisodeService } from './event-episodes.service';
import { Response } from 'express';
import { GenericResponse } from '../common/GenericResponse.model';
import EventEpisode from './event-episodes.entity';
import { ApiTags, ApiOperation, ApiResponse, ApiParam, ApiBody } from '@nestjs/swagger';
import { EventEpisodeDTO, EventEpisodeUpdateDTO } from './event-episodes.dto';
@ApiTags('event-episode')
@Controller('event-episode')
@ -160,7 +161,7 @@ export class EventEpisodeController {
@Post()
@ApiOperation({ summary: 'Insert a new event episode' })
@ApiBody({ type: EventEpisode, description: 'Event episode data to insert' })
@ApiBody({ type: EventEpisodeDTO, description: 'Event episode data to insert' })
@ApiResponse({
status: 400,
description: 'Invalid event episode data',
@ -178,7 +179,8 @@ export class EventEpisodeController {
status: 201,
description: 'Successfully created an event episode',
})
async insert(@Body() eventEpisode: EventEpisode, @Res() res: Response) {
@UsePipes(new ValidationPipe({ whitelist: true}))
async insert(@Body() eventEpisode: EventEpisodeDTO, @Res() res: Response) {
if (!eventEpisode) {
const response = new GenericResponse({
exception: true,
@ -188,7 +190,6 @@ export class EventEpisodeController {
}, null);
return res.status(400).send(response);
}
delete eventEpisode.id; // Ensure no ID is passed in the creation
const response = await this.eventEpisodeService.upsert(eventEpisode, true);
const httpResponse = new GenericResponse(null, response);
res.status(201).send(httpResponse);
@ -196,7 +197,7 @@ export class EventEpisodeController {
@Put()
@ApiOperation({ summary: 'Update an existing event episode' })
@ApiBody({ type: EventEpisode, description: 'Event episode data to update' })
@ApiBody({ type: EventEpisodeUpdateDTO, description: 'Event episode data to update' })
@ApiResponse({
status: 400,
description: 'Invalid event episode data or ID missing',
@ -227,7 +228,8 @@ export class EventEpisodeController {
status: 200,
description: 'Successfully updated event episode',
})
async update(@Body() eventEpisode: EventEpisode, @Res() res: Response) {
@UsePipes(new ValidationPipe({ whitelist: true, skipMissingProperties: true }))
async update(@Body() eventEpisode: EventEpisodeUpdateDTO, @Res() res: Response) {
if (!eventEpisode || !eventEpisode.id) {
const response = new GenericResponse({
exception: true,

View File

@ -91,3 +91,9 @@ export class EventEpisodeDTO {
@IsNotEmpty()
version: number;
}
export class EventEpisodeUpdateDTO extends EventEpisodeDTO {
@ApiProperty({ type: Number })
@IsNumber()
@IsNotEmpty()
id: number;
}

View File

@ -27,7 +27,7 @@ export class EventEpisodeService {
return EventEpisode.destroy({ where: { id: id } });
}
async upsert(eventEpisode: EventEpisode, insertIfNotFound: boolean): Promise<EventEpisode | [affectedCount: number]> {
async upsert(eventEpisode: any, insertIfNotFound: boolean): Promise<EventEpisode | [affectedCount: number]> {
if (eventEpisode.id) {
const existingEventEpisode = await this.findByPk(eventEpisode.id);
if (existingEventEpisode) {

View File

@ -1,4 +1,4 @@
import { Body, Controller, Delete, Get, Param, Post, Put, Res, UploadedFile, UploadedFiles, UseInterceptors } from '@nestjs/common';
import { Body, Controller, Delete, Get, Param, Post, Put, Res, UploadedFile, UploadedFiles, UseInterceptors, UsePipes, ValidationPipe } from '@nestjs/common';
import { EventService } from './event.service';
import { Response } from 'express';
import { GenericResponse } from '../common/GenericResponse.model';
@ -7,6 +7,7 @@ import { ApiTags, ApiOperation, ApiResponse, ApiParam, ApiBody } from '@nestjs/s
import { FileInterceptor, FilesInterceptor } from '@nestjs/platform-express';
import { diskStorage } from 'multer';
import path from 'path';
import { EventDTO, EventUpdateDTO } from './event.dto';
@ApiTags('event')
@Controller('event')
@ -191,23 +192,24 @@ export class EventController {
}
})
}))
async insert(@Body() body: any, @Res() res: Response, @UploadedFiles() files?: Express.Multer.File[]) {
const event = JSON.parse(body.event)
console.log(event);
if (!files) {
console.log("No files");
}
if (!event.orgEmail) {
@UsePipes(new ValidationPipe({ whitelist: true , skipMissingProperties: true }))
async insert(@Body() body: EventDTO, @Res() res: Response, @UploadedFiles() files?: Express.Multer.File[]) {
// const event = JSON.parse(body)
// console.log(body);
// if (!files) {
// console.log("No files");
// }
if (!body.organizer_id) {
const response = new GenericResponse({
exception: true,
exceptionSeverity: 'HIGH',
exceptionMessage: 'ERR.MISSING_ORG_EMAIL',
exceptionMessage: 'ERR.MISSING_ORGANIZER_ID',
stackTrace: 'Request'
}, null);
return res.status(400).send(response);
}
console.log(files);
if (!event || !files) {
// console.log(files);
if (!body || !files) {
const response = new GenericResponse({
exception: true,
exceptionSeverity: 'HIGH',
@ -218,12 +220,11 @@ export class EventController {
}
const imageFiles = files.filter(file => file.mimetype.startsWith('image/')).map(file => file.filename);
const videoFiles = files.filter(file => file.mimetype.startsWith('video/')).map(file => file.filename);
event.images = {
body.images = {
images: imageFiles,
videos: videoFiles,
};
delete event.id;
const response = await this.eventService.upsert(event, true);
const response = await this.eventService.upsert(body, true);
const httpResponse = new GenericResponse(null, response);
res.status(201).send(httpResponse);
}
@ -261,7 +262,8 @@ export class EventController {
status: 200,
description: 'Successfully updated event',
})
async update(@Body() event: Event, @Res() res: Response) {
@UsePipes(new ValidationPipe({ whitelist: true, skipMissingProperties: true }))
async update(@Body() event: EventUpdateDTO, @Res() res: Response) {
if (!event || !event.id) {
const response = new GenericResponse({
exception: true,

View File

@ -13,11 +13,7 @@ export class EventService {
}
async findByPk(id: number): Promise<Event> {
const event = Event.findByPk(id,)
// //const textbookExists = await this.checkTextbookExists((await event).textbookId);
return event
return Event.findByPk(id);
}
findOne(event: Event): Promise<Event> {
@ -32,16 +28,14 @@ export class EventService {
return Event.destroy({ where: { id: id } });
}
async upsert(event: Event, insertIfNotFound: boolean): Promise<Event | [affectedCount: number]> {
async upsert(event: any, insertIfNotFound: boolean): Promise<Event | [affectedCount: number]> {
if (event.id) {
const existingEvent = await this.findByPk(event.id);
if (existingEvent) {
return Event.update(event, { where: { id: event.id } });
}
}
if (insertIfNotFound) {
//const textbookExists = await this.checkTextbookExists(event.textbookId);
if (insertIfNotFound) {
return Event.create(event as any)
}
}

View File

@ -1,9 +1,10 @@
import { Body, Controller, Delete, Get, Param, Post, Put, Res } from '@nestjs/common';
import { Body, Controller, Delete, Get, Param, Post, Put, Res, UsePipes, ValidationPipe } from '@nestjs/common';
import { EventAdditionalDetailService } from './eventAdditionalDetail.service';
import { Response } from 'express';
import { GenericResponse } from '../../common/GenericResponse.model';
import EventAdditionalDetail from './eventAdditionalDetail.entity';
import { ApiTags, ApiOperation, ApiResponse, ApiParam, ApiBody } from '@nestjs/swagger';
import { EventAdditionalDetailDTO, EventAdditionalDetailUpdateDTO } from './eventAdditionalDetail.dto';
@ApiTags('event/addl')
@Controller('event/addl/')
@ -160,7 +161,7 @@ export class EventAdditionalDetailController {
@Post()
@ApiOperation({ summary: 'Insert a new eventAdditionalDetail' })
@ApiBody({ type: EventAdditionalDetail, description: 'EventAdditionalDetail data to insert' })
@ApiBody({ type: EventAdditionalDetailDTO, description: 'EventAdditionalDetail data to insert' })
@ApiResponse({
status: 400,
description: 'Invalid eventAdditionalDetail data',
@ -178,7 +179,8 @@ export class EventAdditionalDetailController {
status: 201,
description: 'Successfully created a eventAdditionalDetail',
})
async insert(@Body() eventAdditionalDetail: EventAdditionalDetail, @Res() res: Response) {
@UsePipes(new ValidationPipe({ whitelist: true}))
async insert(@Body() eventAdditionalDetail: EventAdditionalDetailDTO, @Res() res: Response) {
if (!eventAdditionalDetail) {
const response = new GenericResponse({
exception: true,
@ -188,7 +190,6 @@ export class EventAdditionalDetailController {
}, null);
return res.status(400).send(response);
}
delete eventAdditionalDetail.id;
const response = await this.eventAdditionalDetailService.upsert(eventAdditionalDetail, true);
const httpResponse = new GenericResponse(null, response);
res.status(201).send(httpResponse);
@ -196,7 +197,7 @@ export class EventAdditionalDetailController {
@Put()
@ApiOperation({ summary: 'Update an existing eventAdditionalDetail' })
@ApiBody({ type: EventAdditionalDetail, description: 'EventAdditionalDetail data to update' })
@ApiBody({ type: EventAdditionalDetailUpdateDTO, description: 'EventAdditionalDetail data to update' })
@ApiResponse({
status: 400,
description: 'Invalid eventAdditionalDetail data or ID missing',
@ -227,7 +228,8 @@ export class EventAdditionalDetailController {
status: 200,
description: 'Successfully updated eventAdditionalDetail',
})
async update(@Body() eventAdditionalDetail: EventAdditionalDetail, @Res() res: Response) {
@UsePipes(new ValidationPipe({ whitelist: true, skipMissingProperties: true }))
async update(@Body() eventAdditionalDetail: EventAdditionalDetailUpdateDTO, @Res() res: Response) {
if (!eventAdditionalDetail || !eventAdditionalDetail.id) {
const response = new GenericResponse({
exception: true,

View File

@ -14,9 +14,7 @@ export class EventAdditionalDetailService {
async findByPk(id: number): Promise<EventAdditionalDetail> {
const eventAdditionalDetail = EventAdditionalDetail.findByPk(id,)
// //const textbookExists = await this.checkTextbookExists((await eventAdditionalDetail).textbookId);
const eventAdditionalDetail = EventAdditionalDetail.findByPk(id,)
return eventAdditionalDetail
}
@ -32,16 +30,14 @@ export class EventAdditionalDetailService {
return EventAdditionalDetail.destroy({ where: { id: id } });
}
async upsert(eventAdditionalDetail: EventAdditionalDetail, insertIfNotFound: boolean): Promise<EventAdditionalDetail | [affectedCount: number]> {
async upsert(eventAdditionalDetail: any, insertIfNotFound: boolean): Promise<EventAdditionalDetail | [affectedCount: number]> {
if (eventAdditionalDetail.id) {
const existingEventAdditionalDetail = await this.findByPk(eventAdditionalDetail.id);
if (existingEventAdditionalDetail) {
return EventAdditionalDetail.update(eventAdditionalDetail, { where: { id: eventAdditionalDetail.id } });
}
}
if (insertIfNotFound) {
//const textbookExists = await this.checkTextbookExists(eventAdditionalDetail.textbookId);
if (insertIfNotFound) {
return EventAdditionalDetail.create(eventAdditionalDetail as any)
}
}

View File

@ -181,7 +181,6 @@ export class PayoutController {
})
@UsePipes(new ValidationPipe({ whitelist: true }))
async insert(@Body() payout: PayoutDTO, @Res() res: Response) {
console.log("Received payout:", payout);
if (!payout) {
const response = new GenericResponse({
exception: true,

View File

@ -14,11 +14,7 @@ export class PayoutService {
}
async findByPk(id: number): Promise<Payout> {
const payout = Payout.findByPk(id,)
// //const textbookExists = await this.checkTextbookExists((await payout).textbookId);
return payout
return Payout.findByPk(id);
}
findOne(payout: Payout): Promise<Payout> {
@ -40,7 +36,7 @@ export class PayoutService {
return Payout.update(payout, { where: { id: payout.id } });
}
}
if (insertIfNotFound) {
if (insertIfNotFound) {
return Payout.create(payout as any)
}
}

View File

@ -25,7 +25,7 @@ export class PolicyService {
return Policy.destroy({ where: { id: id } });
}
async upsert(policy: Policy, insertIfNotFound: boolean): Promise<Policy | [affectedCount: number]> {
async upsert(policy: any, insertIfNotFound: boolean): Promise<Policy | [affectedCount: number]> {
if (policy.id) {
const existingPolicy = await this.findByPk(policy.id);
if (existingPolicy) {

View File

@ -1,9 +1,10 @@
import { Body, Controller, Delete, Get, Param, Post, Put, Res } from '@nestjs/common';
import { Body, Controller, Delete, Get, Param, Post, Put, Res, UsePipes, ValidationPipe } from '@nestjs/common';
import { PromotionService } from './promotions.service'; // Updated service
import { Response } from 'express';
import { GenericResponse } from '../common/GenericResponse.model';
import Promotion from './promotions.entity'; // Updated entity
import { ApiTags, ApiOperation, ApiResponse, ApiParam, ApiBody } from '@nestjs/swagger';
import { PromotionDTO, PromotionUpdateDTO } from './promotions.dto';
@ApiTags('promotion')
@Controller('promotion')
@ -160,7 +161,7 @@ export class PromotionController {
@Post()
@ApiOperation({ summary: 'Insert a new promotion' })
@ApiBody({ type: Promotion, description: 'Promotion data to insert' })
@ApiBody({ type: PromotionDTO, description: 'Promotion data to insert' })
@ApiResponse({
status: 400,
description: 'Invalid promotion data',
@ -178,7 +179,8 @@ export class PromotionController {
status: 201,
description: 'Successfully created a promotion',
})
async insert(@Body() promotion: Promotion, @Res() res: Response) {
@UsePipes(new ValidationPipe({ whitelist: true}))
async insert(@Body() promotion: PromotionDTO, @Res() res: Response) {
if (!promotion) {
const response = new GenericResponse({
exception: true,
@ -188,7 +190,6 @@ export class PromotionController {
}, null);
return res.status(400).send(response);
}
delete promotion.id; // Ensure no ID is passed in the creation
const response = await this.promotionService.upsert(promotion, true);
const httpResponse = new GenericResponse(null, response);
res.status(201).send(httpResponse);
@ -196,7 +197,7 @@ export class PromotionController {
@Put()
@ApiOperation({ summary: 'Update an existing promotion' })
@ApiBody({ type: Promotion, description: 'Promotion data to update' })
@ApiBody({ type: PromotionUpdateDTO, description: 'Promotion data to update' })
@ApiResponse({
status: 400,
description: 'Invalid promotion data or ID missing',
@ -227,7 +228,8 @@ export class PromotionController {
status: 200,
description: 'Successfully updated promotion',
})
async update(@Body() promotion: Promotion, @Res() res: Response) {
@UsePipes(new ValidationPipe({ whitelist: true, skipMissingProperties: true }))
async update(@Body() promotion: PromotionUpdateDTO, @Res() res: Response) {
if (!promotion || !promotion.id) {
const response = new GenericResponse({
exception: true,

View File

@ -27,7 +27,7 @@ export class PromotionService {
return Promotion.destroy({ where: { id: id } });
}
async upsert(promotion: Promotion, insertIfNotFound: boolean): Promise<Promotion | [affectedCount: number]> {
async upsert(promotion: any, insertIfNotFound: boolean): Promise<Promotion | [affectedCount: number]> {
if (promotion.id) {
const existingPromotion = await this.findByPk(promotion.id);
if (existingPromotion) {

View File

@ -1,18 +0,0 @@
import { Test, TestingModule } from '@nestjs/testing';
import { PushSubscriptionController } from './push-subscription.controller';
describe('PushSubscriptionController', () => {
let controller: PushSubscriptionController;
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
controllers: [PushSubscriptionController],
}).compile();
controller = module.get<PushSubscriptionController>(PushSubscriptionController);
});
it('should be defined', () => {
expect(controller).toBeDefined();
});
});

View File

@ -1,9 +1,10 @@
import { Body, Controller, Delete, Get, Param, Post, Put, Res } from '@nestjs/common';
import { Body, Controller, Delete, Get, Param, Post, Put, Res, UsePipes, ValidationPipe } from '@nestjs/common';
import { RefundService } from './refund.service';
import { Response } from 'express';
import { GenericResponse } from '../common/GenericResponse.model';
import Refund from './refund.entity';
import { ApiTags, ApiOperation, ApiResponse, ApiParam, ApiBody } from '@nestjs/swagger';
import { RefundDTO, RefundUpdateDTO } from './refund.dto';
@ApiTags('refund')
@Controller('refund')
@ -160,7 +161,7 @@ export class RefundController {
@Post()
@ApiOperation({ summary: 'Insert a new refund' })
@ApiBody({ type: Refund, description: 'Refund data to insert' })
@ApiBody({ type: RefundDTO, description: 'Refund data to insert' })
@ApiResponse({
status: 400,
description: 'Invalid refund data',
@ -178,7 +179,8 @@ export class RefundController {
status: 201,
description: 'Successfully created a refund',
})
async insert(@Body() refund: Refund, @Res() res: Response) {
@UsePipes(new ValidationPipe({ whitelist: true}))
async insert(@Body() refund: RefundDTO, @Res() res: Response) {
if (!refund) {
const response = new GenericResponse({
exception: true,
@ -188,7 +190,6 @@ export class RefundController {
}, null);
return res.status(400).send(response);
}
delete refund.id;
const response = await this.refundService.upsert(refund, true);
const httpResponse = new GenericResponse(null, response);
res.status(201).send(httpResponse);
@ -196,7 +197,7 @@ export class RefundController {
@Put()
@ApiOperation({ summary: 'Update an existing refund' })
@ApiBody({ type: Refund, description: 'Refund data to update' })
@ApiBody({ type: RefundUpdateDTO, description: 'Refund data to update' })
@ApiResponse({
status: 400,
description: 'Invalid refund data or ID missing',
@ -227,7 +228,8 @@ export class RefundController {
status: 200,
description: 'Successfully updated refund',
})
async update(@Body() refund: Refund, @Res() res: Response) {
@UsePipes(new ValidationPipe({ whitelist: true, skipMissingProperties: true }))
async update(@Body() refund: RefundUpdateDTO, @Res() res: Response) {
if (!refund || !refund.id) {
const response = new GenericResponse({
exception: true,

View File

@ -13,11 +13,7 @@ export class RefundService {
}
async findByPk(id: number): Promise<Refund> {
const refund = Refund.findByPk(id,)
// //const textbookExists = await this.checkTextbookExists((await refund).textbookId);
return refund
return Refund.findByPk(id);
}
findOne(refund: Refund): Promise<Refund> {
@ -32,7 +28,7 @@ export class RefundService {
return Refund.destroy({ where: { id: id } });
}
async upsert(refund: Refund, insertIfNotFound: boolean): Promise<Refund | [affectedCount: number]> {
async upsert(refund: any, insertIfNotFound: boolean): Promise<Refund | [affectedCount: number]> {
if (refund.id) {
const existingRefund = await this.findByPk(refund.id);
if (existingRefund) {
@ -40,8 +36,6 @@ export class RefundService {
}
}
if (insertIfNotFound) {
//const textbookExists = await this.checkTextbookExists(refund.textbookId);
return Refund.create(refund as any)
}
}

View File

@ -25,7 +25,7 @@ export class ResourcesService {
return Resources.destroy({ where: { id: id } });
}
async upsert(resources: Resources, insertIfNotFound: boolean): Promise<Resources | [affectedCount: number]> {
async upsert(resources: any, insertIfNotFound: boolean): Promise<Resources | [affectedCount: number]> {
if (resources.id) {
const existingResources = await this.findByPk(resources.id);
if (existingResources) {

View File

@ -1,9 +1,10 @@
import { Body, Controller, Delete, Get, Param, Post, Put, Res } from '@nestjs/common';
import { Body, Controller, Delete, Get, Param, Post, Put, Res, UsePipes, ValidationPipe } from '@nestjs/common';
import { ReviewService } from './review.service';
import { Response } from 'express';
import { GenericResponse } from '../common/GenericResponse.model';
import Review from './review.entity';
import { ApiTags, ApiOperation, ApiResponse, ApiParam, ApiBody } from '@nestjs/swagger';
import { ReviewDTO, ReviewUpdateDTO } from './review.dto';
@ApiTags('review')
@Controller('review')
@ -160,7 +161,7 @@ export class ReviewController {
@Post()
@ApiOperation({ summary: 'Insert a new review' })
@ApiBody({ type: Review, description: 'Review data to insert' })
@ApiBody({ type: ReviewDTO, description: 'Review data to insert' })
@ApiResponse({
status: 400,
description: 'Invalid review data',
@ -178,7 +179,8 @@ export class ReviewController {
status: 201,
description: 'Successfully created a review',
})
async insert(@Body() review: Review, @Res() res: Response) {
@UsePipes(new ValidationPipe({ whitelist: true}))
async insert(@Body() review: ReviewDTO, @Res() res: Response) {
if (!review) {
const response = new GenericResponse({
exception: true,
@ -188,7 +190,6 @@ export class ReviewController {
}, null);
return res.status(400).send(response);
}
delete review.id;
const response = await this.reviewService.upsert(review, true);
const httpResponse = new GenericResponse(null, response);
res.status(201).send(httpResponse);
@ -196,7 +197,7 @@ export class ReviewController {
@Put()
@ApiOperation({ summary: 'Update an existing review' })
@ApiBody({ type: Review, description: 'Review data to update' })
@ApiBody({ type: ReviewUpdateDTO, description: 'Review data to update' })
@ApiResponse({
status: 400,
description: 'Invalid review data or ID missing',
@ -227,7 +228,8 @@ export class ReviewController {
status: 200,
description: 'Successfully updated review',
})
async update(@Body() review: Review, @Res() res: Response) {
@UsePipes(new ValidationPipe({ whitelist: true, skipMissingProperties: true }))
async update(@Body() review: ReviewUpdateDTO, @Res() res: Response) {
if (!review || !review.id) {
const response = new GenericResponse({
exception: true,

View File

@ -13,11 +13,7 @@ export class ReviewService {
}
async findByPk(id: number): Promise<Review> {
const review = Review.findByPk(id,)
// //const textbookExists = await this.checkTextbookExists((await review).textbookId);
return review
return Review.findByPk(id);
}
findOne(review: Review): Promise<Review> {
@ -32,16 +28,14 @@ export class ReviewService {
return Review.destroy({ where: { id: id } });
}
async upsert(review: Review, insertIfNotFound: boolean): Promise<Review | [affectedCount: number]> {
async upsert(review: any, insertIfNotFound: boolean): Promise<Review | [affectedCount: number]> {
if (review.id) {
const existingReview = await this.findByPk(review.id);
if (existingReview) {
return Review.update(review, { where: { id: review.id } });
}
}
if (insertIfNotFound) {
//const textbookExists = await this.checkTextbookExists(review.textbookId);
if (insertIfNotFound) {
return Review.create(review as any)
}
}

View File

@ -1,10 +1,11 @@
import { Body, Controller, Delete, Get, Param, Post, Put, Res } from '@nestjs/common';
import { Body, Controller, Delete, Get, Param, Post, Put, Res, UsePipes, ValidationPipe } from '@nestjs/common';
import { SeatService } from './seat.service';
import { Response } from 'express';
import { GenericResponse } from '../common/GenericResponse.model';
import Seat from './seat.entity';
import { ApiTags, ApiOperation, ApiResponse, ApiParam, ApiBody } from '@nestjs/swagger';
import { RedisService } from 'src/redis/redis.service';
import { SeatDTO, SeatUpdateDTO } from './seat.dto';
@ApiTags('seat')
@Controller('seat')
@ -166,7 +167,7 @@ export class SeatController {
@Post()
@ApiOperation({ summary: 'Insert a new seat' })
@ApiBody({ type: Seat, description: 'Seat data to insert' })
@ApiBody({ type: SeatDTO, description: 'Seat data to insert' })
@ApiResponse({
status: 400,
description: 'Invalid seat data',
@ -184,7 +185,8 @@ export class SeatController {
status: 201,
description: 'Successfully created a seat',
})
async insert(@Body() seat: Seat, @Res() res: Response) {
@UsePipes(new ValidationPipe({ whitelist: true}))
async insert(@Body() seat: SeatDTO, @Res() res: Response) {
if (!seat) {
const response = new GenericResponse({
exception: true,
@ -194,7 +196,6 @@ export class SeatController {
}, null);
return res.status(400).send(response);
}
delete seat.id;
const response = await this.seatService.upsert(seat, true);
const httpResponse = new GenericResponse(null, response);
res.status(201).send(httpResponse);
@ -202,7 +203,7 @@ export class SeatController {
@Put()
@ApiOperation({ summary: 'Update an existing seat' })
@ApiBody({ type: Seat, description: 'Seat data to update' })
@ApiBody({ type: SeatUpdateDTO, description: 'Seat data to update' })
@ApiResponse({
status: 400,
description: 'Invalid seat data or ID missing',
@ -233,7 +234,8 @@ export class SeatController {
status: 200,
description: 'Successfully updated seat',
})
async update(@Body() seat: Seat, @Res() res: Response) {
@UsePipes(new ValidationPipe({ whitelist: true, skipMissingProperties: true }))
async update(@Body() seat: SeatUpdateDTO, @Res() res: Response) {
if (!seat || !seat.id) {
const response = new GenericResponse({
exception: true,

View File

@ -13,9 +13,7 @@ export class SeatService {
}
async findByPk(id: number): Promise<Seat> {
const seat = Seat.findByPk(id,)
return seat
return Seat.findByPk(id);
}
findOne(seat: Seat): Promise<Seat> {
@ -34,14 +32,14 @@ export class SeatService {
return Seat.update({ available: 'booked' }, { where: { eventId: eventId, seatNumber: seatNumber } });
}
async upsert(seat: Seat, insertIfNotFound: boolean): Promise<Seat | [affectedCount: number]> {
async upsert(seat: any, insertIfNotFound: boolean): Promise<Seat | [affectedCount: number]> {
if (seat.id) {
const existingSeat = await this.findByPk(seat.id);
if (existingSeat) {
return Seat.update(seat, { where: { id: seat.id } });
}
}
if (insertIfNotFound) {
if (insertIfNotFound) {
return Seat.create(seat as any)
}
}

View File

@ -1,9 +1,10 @@
import { Body, Controller, Delete, Get, Param, Post, Put, Res } from '@nestjs/common';
import { Body, Controller, Delete, Get, Param, Post, Put, Res, UsePipes, ValidationPipe } from '@nestjs/common';
import { TheatreService } from './theatre.service';
import { Response } from 'express';
import { GenericResponse } from '../common/GenericResponse.model';
import Theatre from './theatre.entity';
import { ApiTags, ApiOperation, ApiResponse, ApiParam, ApiBody } from '@nestjs/swagger';
import { TheatreDTO, TheatreUpdateDTO } from './theatre.dto';
@ApiTags('theatre')
@Controller('theatre')
@ -160,7 +161,7 @@ export class TheatreController {
@Post()
@ApiOperation({ summary: 'Insert a new theatre' })
@ApiBody({ type: Theatre, description: 'Theatre data to insert' })
@ApiBody({ type: TheatreDTO, description: 'Theatre data to insert' })
@ApiResponse({
status: 400,
description: 'Invalid theatre data',
@ -178,7 +179,8 @@ export class TheatreController {
status: 201,
description: 'Successfully created a theatre',
})
async insert(@Body() theatre: Theatre, @Res() res: Response) {
@UsePipes(new ValidationPipe({ whitelist: true}))
async insert(@Body() theatre: TheatreDTO, @Res() res: Response) {
if (!theatre) {
const response = new GenericResponse({
exception: true,
@ -188,7 +190,6 @@ export class TheatreController {
}, null);
return res.status(400).send(response);
}
delete theatre.id;
const response = await this.theatreService.upsert(theatre, true);
const httpResponse = new GenericResponse(null, response);
res.status(201).send(httpResponse);
@ -196,7 +197,7 @@ export class TheatreController {
@Put()
@ApiOperation({ summary: 'Update an existing theatre' })
@ApiBody({ type: Theatre, description: 'Theatre data to update' })
@ApiBody({ type: TheatreUpdateDTO, description: 'Theatre data to update' })
@ApiResponse({
status: 400,
description: 'Invalid theatre data or ID missing',
@ -227,7 +228,8 @@ export class TheatreController {
status: 200,
description: 'Successfully updated theatre',
})
async update(@Body() theatre: Theatre, @Res() res: Response) {
@UsePipes(new ValidationPipe({ whitelist: true, skipMissingProperties: true }))
async update(@Body() theatre: TheatreUpdateDTO, @Res() res: Response) {
if (!theatre || !theatre.id) {
const response = new GenericResponse({
exception: true,

View File

@ -13,11 +13,7 @@ export class TheatreService {
}
async findByPk(id: number): Promise<Theatre> {
const theatre = Theatre.findByPk(id,)
// //const textbookExists = await this.checkTextbookExists((await theatre).textbookId);
return theatre
return Theatre.findByPk(id);
}
findOne(theatre: Theatre): Promise<Theatre> {
@ -32,7 +28,7 @@ export class TheatreService {
return Theatre.destroy({ where: { id: id } });
}
async upsert(theatre: Theatre, insertIfNotFound: boolean): Promise<Theatre | [affectedCount: number]> {
async upsert(theatre: any, insertIfNotFound: boolean): Promise<Theatre | [affectedCount: number]> {
if (theatre.id) {
const existingTheatre = await this.findByPk(theatre.id);
if (existingTheatre) {
@ -40,8 +36,6 @@ export class TheatreService {
}
}
if (insertIfNotFound) {
//const textbookExists = await this.checkTextbookExists(theatre.textbookId);
return Theatre.create(theatre as any)
}
}

View File

@ -1,9 +1,10 @@
import { Body, Controller, Delete, Get, Param, Post, Put, Res } from '@nestjs/common';
import { Body, Controller, Delete, Get, Param, Post, Put, Res, UsePipes, ValidationPipe } from '@nestjs/common';
import { TheatreAdditionalDetailsService } from './theatreAdditionalDetails.service';
import { Response } from 'express';
import { GenericResponse } from '../../common/GenericResponse.model';
import TheatreAdditionalDetails from './theatreAdditionalDetails.entity';
import { ApiTags, ApiOperation, ApiResponse, ApiParam, ApiBody } from '@nestjs/swagger';
import { TheatreAdditionalDetailsDTO, TheatreAdditionalDetailsUpdateDTO } from './theatreAdditionalDetails.dto';
@ApiTags('theatreAdditionalDetails')
@Controller('theatreAdditionalDetails')
@ -160,7 +161,7 @@ export class TheatreAdditionalDetailsController {
@Post()
@ApiOperation({ summary: 'Insert a new theatreAdditionalDetails' })
@ApiBody({ type: TheatreAdditionalDetails, description: 'TheatreAdditionalDetails data to insert' })
@ApiBody({ type: TheatreAdditionalDetailsDTO, description: 'TheatreAdditionalDetails data to insert' })
@ApiResponse({
status: 400,
description: 'Invalid theatreAdditionalDetails data',
@ -178,7 +179,8 @@ export class TheatreAdditionalDetailsController {
status: 201,
description: 'Successfully created a theatreAdditionalDetails',
})
async insert(@Body() theatreAdditionalDetails: TheatreAdditionalDetails, @Res() res: Response) {
@UsePipes(new ValidationPipe({ whitelist: true}))
async insert(@Body() theatreAdditionalDetails: TheatreAdditionalDetailsDTO, @Res() res: Response) {
if (!theatreAdditionalDetails) {
const response = new GenericResponse({
exception: true,
@ -188,7 +190,6 @@ export class TheatreAdditionalDetailsController {
}, null);
return res.status(400).send(response);
}
delete theatreAdditionalDetails.id;
const response = await this.theatreAdditionalDetailsService.upsert(theatreAdditionalDetails, true);
const httpResponse = new GenericResponse(null, response);
res.status(201).send(httpResponse);
@ -196,7 +197,7 @@ export class TheatreAdditionalDetailsController {
@Put()
@ApiOperation({ summary: 'Update an existing theatreAdditionalDetails' })
@ApiBody({ type: TheatreAdditionalDetails, description: 'TheatreAdditionalDetails data to update' })
@ApiBody({ type: TheatreAdditionalDetailsUpdateDTO, description: 'TheatreAdditionalDetails data to update' })
@ApiResponse({
status: 400,
description: 'Invalid theatreAdditionalDetails data or ID missing',
@ -227,7 +228,8 @@ export class TheatreAdditionalDetailsController {
status: 200,
description: 'Successfully updated theatreAdditionalDetails',
})
async update(@Body() theatreAdditionalDetails: TheatreAdditionalDetails, @Res() res: Response) {
@UsePipes(new ValidationPipe({ whitelist: true, skipMissingProperties: true }))
async update(@Body() theatreAdditionalDetails: TheatreAdditionalDetailsUpdateDTO, @Res() res: Response) {
if (!theatreAdditionalDetails || !theatreAdditionalDetails.id) {
const response = new GenericResponse({
exception: true,

View File

@ -13,11 +13,7 @@ export class TheatreAdditionalDetailsService {
}
async findByPk(id: number): Promise<TheatreAdditionalDetails> {
const theatreAdditionalDetails = TheatreAdditionalDetails.findByPk(id,)
// //const textbookExists = await this.checkTextbookExists((await theatreAdditionalDetails).textbookId);
return theatreAdditionalDetails
return TheatreAdditionalDetails.findByPk(id);
}
findOne(theatreAdditionalDetails: TheatreAdditionalDetails): Promise<TheatreAdditionalDetails> {
@ -32,7 +28,7 @@ export class TheatreAdditionalDetailsService {
return TheatreAdditionalDetails.destroy({ where: { id: id } });
}
async upsert(theatreAdditionalDetails: TheatreAdditionalDetails, insertIfNotFound: boolean): Promise<TheatreAdditionalDetails | [affectedCount: number]> {
async upsert(theatreAdditionalDetails: any, insertIfNotFound: boolean): Promise<TheatreAdditionalDetails | [affectedCount: number]> {
if (theatreAdditionalDetails.id) {
const existingTheatreAdditionalDetails = await this.findByPk(theatreAdditionalDetails.id);
if (existingTheatreAdditionalDetails) {
@ -40,8 +36,6 @@ export class TheatreAdditionalDetailsService {
}
}
if (insertIfNotFound) {
//const textbookExists = await this.checkTextbookExists(theatreAdditionalDetails.textbookId);
return TheatreAdditionalDetails.create(theatreAdditionalDetails as any)
}
}

View File

@ -1,9 +1,10 @@
import { Body, Controller, Delete, Get, Param, Post, Put, Res } from '@nestjs/common';
import { Body, Controller, Delete, Get, Param, Post, Put, Res, UsePipes, ValidationPipe } from '@nestjs/common';
import { TicketService } from './ticket.service';
import { Response } from 'express';
import { GenericResponse } from '../common/GenericResponse.model';
import Ticket from './ticket.entity';
import { ApiTags, ApiOperation, ApiResponse, ApiParam, ApiBody } from '@nestjs/swagger';
import { TicketDTO, TicketUpdateDTO } from './ticket.dto';
@ApiTags('ticket')
@Controller('ticket')
@ -160,7 +161,7 @@ export class TicketController {
@Post()
@ApiOperation({ summary: 'Insert a new ticket' })
@ApiBody({ type: Ticket, description: 'Ticket data to insert' })
@ApiBody({ type: TicketDTO, description: 'Ticket data to insert' })
@ApiResponse({
status: 400,
description: 'Invalid ticket data',
@ -178,7 +179,8 @@ export class TicketController {
status: 201,
description: 'Successfully created a ticket',
})
async insert(@Body() ticket: Ticket, @Res() res: Response) {
@UsePipes(new ValidationPipe({ whitelist: true}))
async insert(@Body() ticket: TicketDTO, @Res() res: Response) {
if (!ticket) {
const response = new GenericResponse({
exception: true,
@ -188,7 +190,6 @@ export class TicketController {
}, null);
return res.status(400).send(response);
}
delete ticket.id;
const response = await this.ticketService.upsert(ticket, true);
const httpResponse = new GenericResponse(null, response);
res.status(201).send(httpResponse);
@ -196,7 +197,7 @@ export class TicketController {
@Put()
@ApiOperation({ summary: 'Update an existing ticket' })
@ApiBody({ type: Ticket, description: 'Ticket data to update' })
@ApiBody({ type: TicketUpdateDTO, description: 'Ticket data to update' })
@ApiResponse({
status: 400,
description: 'Invalid ticket data or ID missing',
@ -227,7 +228,8 @@ export class TicketController {
status: 200,
description: 'Successfully updated ticket',
})
async update(@Body() ticket: Ticket, @Res() res: Response) {
@UsePipes(new ValidationPipe({ whitelist: true, skipMissingProperties: true }))
async update(@Body() ticket: TicketUpdateDTO, @Res() res: Response) {
if (!ticket || !ticket.id) {
const response = new GenericResponse({
exception: true,

View File

@ -13,11 +13,7 @@ export class TicketService {
}
async findByPk(id: number): Promise<Ticket> {
const ticket = Ticket.findByPk(id,)
// //const textbookExists = await this.checkTextbookExists((await ticket).textbookId);
return ticket
return Ticket.findByPk(id);
}
findOne(ticket: Ticket): Promise<Ticket> {
@ -32,7 +28,7 @@ export class TicketService {
return Ticket.destroy({ where: { id: id } });
}
async upsert(ticket: Ticket, insertIfNotFound: boolean): Promise<Ticket | [affectedCount: number]> {
async upsert(ticket: any, insertIfNotFound: boolean): Promise<Ticket | [affectedCount: number]> {
if (ticket.id) {
const existingTicket = await this.findByPk(ticket.id);
if (existingTicket) {
@ -40,14 +36,7 @@ export class TicketService {
}
}
if (insertIfNotFound) {
//const textbookExists = await this.checkTextbookExists(ticket.textbookId);
return Ticket.create(ticket as any)
}
}
// async assignTicketToUser(ticketId: number, userId: number): Promise<Ticket> {
// return Ticket.update({ userId: userId }, { where: { id: ticketId } });
// }
}

View File

@ -1,9 +1,10 @@
import { Body, Controller, Delete, Get, Param, Post, Put, Res } from '@nestjs/common';
import { Body, Controller, Delete, Get, Param, Post, Put, Res, UsePipes, ValidationPipe } from '@nestjs/common';
import { TicketPricingService } from './ticketPricing.service';
import { Response } from 'express';
import { GenericResponse } from '../common/GenericResponse.model';
import TicketPricing from './ticketPricing.entity';
import { ApiTags, ApiOperation, ApiResponse, ApiParam, ApiBody } from '@nestjs/swagger';
import { TicketPricingDTO, TicketPricingUpdateDTO } from './ticketPricing.dto';
@ApiTags('ticketPricing')
@Controller('ticketPricing')
@ -160,7 +161,7 @@ export class TicketPricingController {
@Post()
@ApiOperation({ summary: 'Insert a new ticketPricing' })
@ApiBody({ type: TicketPricing, description: 'TicketPricing data to insert' })
@ApiBody({ type: TicketPricingDTO, description: 'TicketPricing data to insert' })
@ApiResponse({
status: 400,
description: 'Invalid ticketPricing data',
@ -178,7 +179,8 @@ export class TicketPricingController {
status: 201,
description: 'Successfully created a ticketPricing',
})
async insert(@Body() ticketPricing: TicketPricing, @Res() res: Response) {
@UsePipes(new ValidationPipe({ whitelist: true}))
async insert(@Body() ticketPricing: TicketPricingDTO, @Res() res: Response) {
if (!ticketPricing) {
const response = new GenericResponse({
exception: true,
@ -188,7 +190,6 @@ export class TicketPricingController {
}, null);
return res.status(400).send(response);
}
delete ticketPricing.id;
const response = await this.ticketPricingService.upsert(ticketPricing, true);
const httpResponse = new GenericResponse(null, response);
res.status(201).send(httpResponse);
@ -196,7 +197,7 @@ export class TicketPricingController {
@Put()
@ApiOperation({ summary: 'Update an existing ticketPricing' })
@ApiBody({ type: TicketPricing, description: 'TicketPricing data to update' })
@ApiBody({ type: TicketPricingUpdateDTO, description: 'TicketPricing data to update' })
@ApiResponse({
status: 400,
description: 'Invalid ticketPricing data or ID missing',
@ -227,7 +228,8 @@ export class TicketPricingController {
status: 200,
description: 'Successfully updated ticketPricing',
})
async update(@Body() ticketPricing: TicketPricing, @Res() res: Response) {
@UsePipes(new ValidationPipe({ whitelist: true, skipMissingProperties: true }))
async update(@Body() ticketPricing: TicketPricingUpdateDTO, @Res() res: Response) {
if (!ticketPricing || !ticketPricing.id) {
const response = new GenericResponse({
exception: true,

View File

@ -2,64 +2,71 @@ import { IsString, IsNumber, IsDate, IsOptional, IsNotEmpty } from 'class-valida
import { ApiProperty } from '@nestjs/swagger';
import { Transform } from 'class-transformer';
export class TimeSlotDTO {
export class TicketPricingDTO {
@ApiProperty({ type: Number })
@IsNumber()
@IsNotEmpty()
eventId: number;
@ApiProperty({ type: Date })
@IsDate()
@IsNotEmpty()
@Transform(({ value }) => new Date(value))
startTime: Date;
@ApiProperty({ type: Date })
@IsDate()
@IsNotEmpty()
@Transform(({ value }) => new Date(value))
endTime: Date;
@ApiProperty({ type: Number })
@IsOptional()
@IsNumber()
timeSlotId: number;
@ApiProperty({ type: String })
@IsString()
@IsNotEmpty()
ticketType: string;
@ApiProperty({ type: Number })
@IsNumber()
@IsNotEmpty()
price: number;
@ApiProperty({ type: String })
@IsString()
@IsOptional()
status: string;
@ApiProperty({ type: Date })
@IsDate()
@IsNotEmpty()
@Transform(({ value }) => new Date(value))
@IsOptional()
@Transform(({ value }) => new Date(value))
validFrom: Date;
@ApiProperty({ type: Date })
@IsDate()
@IsNotEmpty()
@Transform(({ value }) => new Date(value))
@IsOptional()
@Transform(({ value }) => new Date(value))
validTill: Date;
@ApiProperty({ type: Date })
@IsDate()
@Transform(({ value }) => new Date(value))
@IsOptional()
@Transform(({ value }) => new Date(value))
createdAt: Date;
@ApiProperty({ type: Date })
@IsDate()
@Transform(({ value }) => new Date(value))
@IsOptional()
@Transform(({ value }) => new Date(value))
updatedAt: Date;
@ApiProperty({ type: String })
@IsString()
@IsOptional()
createdBy: string;
@ApiProperty({ type: String })
@IsString()
@IsOptional()
modifiedBy: string;
@ApiProperty({ type: Date })
@IsOptional()
@IsDate()
@Transform(({ value }) => value ? new Date(value) : null)
@Transform(({ value }) => value ? new Date(value) : null)
deletedAt: Date;
@ApiProperty({ type: Number })
@ -68,9 +75,9 @@ export class TimeSlotDTO {
version: number;
}
export class TimeSlotUpdateDTO extends TimeSlotDTO {
export class TicketPricingUpdateDTO extends TicketPricingDTO {
@ApiProperty({ type: Number })
@IsNumber()
@IsNotEmpty()
id: number
}
id: number;
}

View File

@ -13,11 +13,7 @@ export class TicketPricingService {
}
async findByPk(id: number): Promise<TicketPricing> {
const ticketPricing = TicketPricing.findByPk(id,)
// //const textbookExists = await this.checkTextbookExists((await ticketPricing).textbookId);
return ticketPricing
return TicketPricing.findByPk(id);
}
findOne(ticketPricing: TicketPricing): Promise<TicketPricing> {
@ -32,7 +28,7 @@ export class TicketPricingService {
return TicketPricing.destroy({ where: { id: id } });
}
async upsert(ticketPricing: TicketPricing, insertIfNotFound: boolean): Promise<TicketPricing | [affectedCount: number]> {
async upsert(ticketPricing: any, insertIfNotFound: boolean): Promise<TicketPricing | [affectedCount: number]> {
if (ticketPricing.id) {
const existingTicketPricing = await this.findByPk(ticketPricing.id);
if (existingTicketPricing) {
@ -40,8 +36,6 @@ export class TicketPricingService {
}
}
if (insertIfNotFound) {
//const textbookExists = await this.checkTextbookExists(ticketPricing.textbookId);
return TicketPricing.create(ticketPricing as any)
}
}

View File

@ -1,14 +1,15 @@
import { Body, Controller, Delete, Get, Param, Post, Put, Res } from '@nestjs/common';
import { Body, Controller, Delete, Get, Param, Post, Put, Res, UsePipes, ValidationPipe } from '@nestjs/common';
import { TimeSlotService } from './timeSlot.service';
import { Response } from 'express';
import { GenericResponse } from '../common/GenericResponse.model';
import TimeSlot from './timeSlot.entity';
import { ApiTags, ApiOperation, ApiResponse, ApiParam, ApiBody } from '@nestjs/swagger';
import { TimeSlotDTO, TimeSlotUpdateDTO } from './timeSlot.dto';
@ApiTags('timeSlot')
@Controller('timeSlot')
export class TimeSlotController {
constructor(private timeSlotService: TimeSlotService) {}
constructor(private timeSlotService: TimeSlotService) { }
@Get("/all")
@ApiOperation({ summary: 'Get all timeSlots' })
@ -31,7 +32,7 @@ export class TimeSlotController {
})
async getAllTimeSlots(@Res() res: Response) {
const response = await this.timeSlotService.findAll() || [];
if(!response) {
if (!response) {
const errorResponse = new GenericResponse({
exception: true,
exceptionSeverity: 'HIGH',
@ -160,7 +161,7 @@ export class TimeSlotController {
@Post()
@ApiOperation({ summary: 'Insert a new timeSlot' })
@ApiBody({ type: TimeSlot, description: 'TimeSlot data to insert' })
@ApiBody({ type: TimeSlotDTO, description: 'TimeSlot data to insert' })
@ApiResponse({
status: 400,
description: 'Invalid timeSlot data',
@ -178,7 +179,8 @@ export class TimeSlotController {
status: 201,
description: 'Successfully created a timeSlot',
})
async insert(@Body() timeSlot: TimeSlot, @Res() res: Response) {
@UsePipes(new ValidationPipe({ whitelist: true }))
async insert(@Body() timeSlot: TimeSlotDTO, @Res() res: Response) {
if (!timeSlot) {
const response = new GenericResponse({
exception: true,
@ -188,7 +190,6 @@ export class TimeSlotController {
}, null);
return res.status(400).send(response);
}
delete timeSlot.id;
const response = await this.timeSlotService.upsert(timeSlot, true);
const httpResponse = new GenericResponse(null, response);
res.status(201).send(httpResponse);
@ -196,7 +197,7 @@ export class TimeSlotController {
@Put()
@ApiOperation({ summary: 'Update an existing timeSlot' })
@ApiBody({ type: TimeSlot, description: 'TimeSlot data to update' })
@ApiBody({ type: TimeSlotUpdateDTO, description: 'TimeSlot data to update' })
@ApiResponse({
status: 400,
description: 'Invalid timeSlot data or ID missing',
@ -227,7 +228,8 @@ export class TimeSlotController {
status: 200,
description: 'Successfully updated timeSlot',
})
async update(@Body() timeSlot: TimeSlot, @Res() res: Response) {
@UsePipes(new ValidationPipe({ whitelist: true, skipMissingProperties: true }))
async update(@Body() timeSlot: TimeSlotUpdateDTO, @Res() res: Response) {
if (!timeSlot || !timeSlot.id) {
const response = new GenericResponse({
exception: true,

View File

@ -13,10 +13,7 @@ export class TimeSlotService {
}
async findByPk(id: number): Promise<TimeSlot> {
const timeSlot = TimeSlot.findByPk(id,)
return timeSlot
return TimeSlot.findByPk(id);
}
findOne(timeSlot: TimeSlot): Promise<TimeSlot> {
@ -31,7 +28,7 @@ export class TimeSlotService {
return TimeSlot.destroy({ where: { id: id } });
}
async upsert(timeSlot: TimeSlot, insertIfNotFound: boolean): Promise<TimeSlot | [affectedCount: number]> {
async upsert(timeSlot: any, insertIfNotFound: boolean): Promise<TimeSlot | [affectedCount: number]> {
if (timeSlot.id) {
const existingTimeSlot = await this.findByPk(timeSlot.id);
if (existingTimeSlot) {
@ -39,7 +36,6 @@ export class TimeSlotService {
}
}
if (insertIfNotFound) {
return TimeSlot.create(timeSlot as any)
}
}

View File

@ -1,14 +1,15 @@
import { Body, Controller, Delete, Get, Param, Post, Put, Res } from '@nestjs/common';
import { UserWatchlistService } from './user-watchlist.service';
import { Body, Controller, Delete, Get, Param, Post, Put, Res, UsePipes, ValidationPipe } from '@nestjs/common';
import { UserWatchlistService } from './user-watchlist.service';
import { Response } from 'express';
import { GenericResponse } from '../common/GenericResponse.model';
import UserWatchlist from './user-watchlist.entity';
import UserWatchlist from './user-watchlist.entity';
import { ApiTags, ApiOperation, ApiResponse, ApiParam, ApiBody } from '@nestjs/swagger';
import { UserWatchlistDTO, UserWatchlistUpdateDTO } from './user-watchlist.dto';
@ApiTags('user-watchlist')
@Controller('user-watchlist')
export class UserWatchlistController {
constructor(private userWatchlistService: UserWatchlistService) {}
constructor(private userWatchlistService: UserWatchlistService) { }
@Get("/all")
@ApiOperation({ summary: 'Get all user watchlists' })
@ -160,7 +161,7 @@ export class UserWatchlistController {
@Post()
@ApiOperation({ summary: 'Insert a new user watchlist' })
@ApiBody({ type: UserWatchlist, description: 'User watchlist data to insert' })
@ApiBody({ type: UserWatchlistDTO, description: 'User watchlist data to insert' })
@ApiResponse({
status: 400,
description: 'Invalid user watchlist data',
@ -178,7 +179,8 @@ export class UserWatchlistController {
status: 201,
description: 'Successfully created a user watchlist',
})
async insert(@Body() userWatchlist: UserWatchlist, @Res() res: Response) {
@UsePipes(new ValidationPipe({ whitelist: true, skipMissingProperties: true }))
async insert(@Body() userWatchlist: UserWatchlistDTO, @Res() res: Response) {
if (!userWatchlist) {
const response = new GenericResponse({
exception: true,
@ -188,7 +190,6 @@ export class UserWatchlistController {
}, null);
return res.status(400).send(response);
}
delete userWatchlist.id; // Ensure no ID is passed in the creation
const response = await this.userWatchlistService.upsert(userWatchlist, true);
const httpResponse = new GenericResponse(null, response);
res.status(201).send(httpResponse);
@ -196,7 +197,7 @@ export class UserWatchlistController {
@Put()
@ApiOperation({ summary: 'Update an existing user watchlist' })
@ApiBody({ type: UserWatchlist, description: 'User watchlist data to update' })
@ApiBody({ type: UserWatchlistUpdateDTO, description: 'User watchlist data to update' })
@ApiResponse({
status: 400,
description: 'Invalid user watchlist data or ID missing',
@ -227,7 +228,8 @@ export class UserWatchlistController {
status: 200,
description: 'Successfully updated user watchlist',
})
async update(@Body() userWatchlist: UserWatchlist, @Res() res: Response) {
@UsePipes(new ValidationPipe({ whitelist: true, skipMissingProperties: true }))
async update(@Body() userWatchlist: UserWatchlistUpdateDTO, @Res() res: Response) {
if (!userWatchlist || !userWatchlist.id) {
const response = new GenericResponse({
exception: true,

View File

@ -27,7 +27,7 @@ export class UserWatchlistService {
return UserWatchlist.destroy({ where: { id: id } });
}
async upsert(userWatchlist: UserWatchlist, insertIfNotFound: boolean): Promise<UserWatchlist | [affectedCount: number]> {
async upsert(userWatchlist: any, insertIfNotFound: boolean): Promise<UserWatchlist | [affectedCount: number]> {
if (userWatchlist.id) {
const existingUserWatchlist = await this.findByPk(userWatchlist.id);
if (existingUserWatchlist) {

View File

@ -1,9 +1,10 @@
import { Body, Controller, Delete, Get, Param, Post, Put, Res } from '@nestjs/common';
import { Body, Controller, Delete, Get, Param, Post, Put, Res, UsePipes, ValidationPipe } from '@nestjs/common';
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';
import { UserAdditionalDetailDTO, UserAdditionalDetailUpdateDTO } from './user-additional-details.dto';
@ApiTags('user-additional-details')
@Controller('users/addl/')
@ -163,7 +164,7 @@ export class UserAdditionalDetailsController {
@Post()
@ApiOperation({ summary: 'Insert a new user additional detail' })
@ApiBody({ type: UserAdditionalDetail, description: 'User additional detail data to insert' })
@ApiBody({ type: UserAdditionalDetailDTO, description: 'User additional detail data to insert' })
@ApiResponse({
status: 400,
description: 'Failed to insert user additional detail',
@ -194,7 +195,8 @@ export class UserAdditionalDetailsController {
status: 201,
description: 'User additional detail successfully created',
})
async userAdditionalDetailsInsert(@Body() user: UserAdditionalDetail, @Res() res: Response) {
@UsePipes(new ValidationPipe({ whitelist: true }))
async userAdditionalDetailsInsert(@Body() user: UserAdditionalDetailDTO, @Res() res: Response) {
if (!user) {
const response = new GenericResponse({
exception: true,
@ -205,7 +207,6 @@ export class UserAdditionalDetailsController {
res.status(400).send(response);
return;
}
delete user.id;
const response = await this.userAdditionalDetailsService.upsert(user, true);
if (!response) {
const response = new GenericResponse({
@ -223,7 +224,7 @@ export class UserAdditionalDetailsController {
@Put()
@ApiOperation({ summary: 'Update an existing user additional detail' })
@ApiBody({ type: UserAdditionalDetail, description: 'User additional detail data to update' })
@ApiBody({ type: UserAdditionalDetailUpdateDTO, description: 'User additional detail data to update' })
@ApiResponse({
status: 400,
description: 'Failed to update user additional detail',
@ -254,7 +255,8 @@ export class UserAdditionalDetailsController {
status: 200,
description: 'User additional detail successfully updated',
})
async userAdditionalDetailsUpdate(@Body() user: UserAdditionalDetail, @Res() res: Response) {
@UsePipes(new ValidationPipe({ whitelist: true, skipMissingProperties: true }))
async userAdditionalDetailsUpdate(@Body() user: UserAdditionalDetailUpdateDTO, @Res() res: Response) {
if (!user || !user.id) {
const response = new GenericResponse({
exception: true,

View File

@ -0,0 +1,50 @@
import { IsString, IsNumber, IsDate, IsOptional, IsNotEmpty } from 'class-validator';
import { ApiProperty } from '@nestjs/swagger';
import { Transform } from 'class-transformer';
export class UserAdditionalDetailDTO {
@ApiProperty({ type: String })
@IsString()
@IsNotEmpty()
addlDataType: string;
@ApiProperty({ type: Number })
@IsNumber()
@IsNotEmpty()
userId: number;
@ApiProperty({ type: String })
@IsString()
@IsNotEmpty()
addlDataName: string;
@ApiProperty({ type: Date, default: new Date() })
@IsDate()
@IsOptional()
@Transform(({ value }) => value ? new Date(value) : new Date())
validFrom: Date;
@ApiProperty({ type: Date, default: new Date("2070-12-31") })
@IsDate()
@IsOptional()
@Transform(({ value }) => value ? new Date(value) : new Date("2070-12-31"))
validTill: Date;
@ApiProperty({ type: String })
@IsString()
@IsOptional()
createdBy: string;
@ApiProperty({ type: String })
@IsString()
@IsOptional()
modifiedBy: string;
}
export class UserAdditionalDetailUpdateDTO extends UserAdditionalDetailDTO {
@ApiProperty({ type: Number })
@IsNumber()
@IsNotEmpty()
id: number;
}

View File

@ -23,7 +23,7 @@ export class UserAdditionalDetailsService {
return UserAdditionalDetail.destroy({where: {id: id}});
}
async upsert(userDetail: UserAdditionalDetail, insertIfNotFound: boolean): Promise<UserAdditionalDetail | [affectedCount: number]> {
async upsert(userDetail: any, insertIfNotFound: boolean): Promise<UserAdditionalDetail | [affectedCount: number]> {
if(userDetail.id) {
const existingUser = await this.findByPk(userDetail.id);
if(existingUser) {

View File

@ -1,9 +1,10 @@
import { Body, Controller, Delete, Get, Param, Post, Put, Res } from '@nestjs/common';
import { Body, Controller, Delete, Get, Param, Post, Put, Res, UsePipes, ValidationPipe } from '@nestjs/common';
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';
import { UserTypeDTO, UserTypeUpdateDTO } from './user-type.dto';
@ApiTags('user-types')
@Controller('users/types')
@ -150,7 +151,7 @@ export class UserTypesController {
@Post()
@ApiOperation({ summary: 'Insert a new user type' })
@ApiBody({ type: UserType, description: 'User type data to insert' })
@ApiBody({ type: UserTypeDTO, description: 'User type data to insert' })
@ApiResponse({
status: 400,
description: 'Failed to insert user type',
@ -168,7 +169,8 @@ export class UserTypesController {
status: 201,
description: 'User type successfully created',
})
async userTypeInsert(@Body() user: UserType, @Res() res: Response) {
@UsePipes(new ValidationPipe({ whitelist: true }))
async userTypeInsert(@Body() user: UserTypeDTO, @Res() res: Response) {
if (!user) {
const response = new GenericResponse({
exception: true,
@ -179,7 +181,6 @@ export class UserTypesController {
res.status(400).send(response);
return;
}
delete user.id;
const response = await this.userTypeService.upsert(user, true);
if (!response) {
const errorResponse = new GenericResponse({
@ -196,7 +197,7 @@ export class UserTypesController {
@Put()
@ApiOperation({ summary: 'Update an existing user type' })
@ApiBody({ type: UserType, description: 'User type data to update' })
@ApiBody({ type: UserTypeUpdateDTO, description: 'User type data to update' })
@ApiResponse({
status: 400,
description: 'Failed to update user type',
@ -227,7 +228,8 @@ export class UserTypesController {
status: 200,
description: 'User type successfully updated',
})
async userTypeUpdate(@Body() user: UserType, @Res() res: Response) {
@UsePipes(new ValidationPipe({ whitelist: true, skipMissingProperties: true }))
async userTypeUpdate(@Body() user: UserTypeUpdateDTO, @Res() res: Response) {
if (!user || !user.id) {
const response = new GenericResponse({
exception: true,
@ -297,7 +299,7 @@ export class UserTypesController {
return;
}
const response = await this.userTypeService.remove(id) || {};
if(!response){
if (!response) {
const errorResponse = new GenericResponse({
exception: true,
exceptionSeverity: 'HIGH',

View File

@ -0,0 +1,78 @@
import { IsString, IsNumber, IsDate, IsOptional, IsNotEmpty } from 'class-validator';
import { ApiProperty } from '@nestjs/swagger';
import { Transform } from 'class-transformer';
export class UserTypeDTO {
@ApiProperty({ type: String })
@IsString()
@IsNotEmpty()
userTypeCode: string;
@ApiProperty({ type: String })
@IsString()
@IsNotEmpty()
userTypeName: string;
@ApiProperty({ type: String })
@IsString()
@IsOptional()
userTypeDesc: string;
@ApiProperty({ type: String })
@IsString()
@IsOptional()
status: string;
@ApiProperty({ type: Date, default: new Date() })
@IsDate()
@IsOptional()
@Transform(({ value }) => value ? new Date(value) : new Date())
validFrom: Date;
@ApiProperty({ type: Date, default: new Date("2070-12-31") })
@IsDate()
@IsOptional()
@Transform(({ value }) => value ? new Date(value) : new Date("2070-12-31"))
validTill: Date;
@ApiProperty({ type: String })
@IsString()
@IsOptional()
createdBy: string;
@ApiProperty({ type: String })
@IsString()
@IsOptional()
modifiedBy: string;
@ApiProperty({ type: Date })
@IsDate()
@IsOptional()
@Transform(({ value }) => new Date(value))
createdAt: Date;
@ApiProperty({ type: Date })
@IsDate()
@IsOptional()
@Transform(({ value }) => new Date(value))
updatedAt: Date;
@ApiProperty({ type: Date })
@IsDate()
@IsOptional()
@Transform(({ value }) => value ? new Date(value) : null)
deletedAt: Date;
@ApiProperty({ type: Number })
@IsNumber()
@IsNotEmpty()
version: number;
}
export class UserTypeUpdateDTO extends UserTypeDTO {
@ApiProperty({ type: Number })
@IsNumber()
@IsNotEmpty()
id: number;
}

View File

@ -25,7 +25,7 @@ export class UserTypesService {
return UserType.destroy({where: {id: id}});
}
async upsert(userDetail: UserType, insertIfNotFound: boolean): Promise<UserType | [affectedCount: number]> {
async upsert(userDetail: any, insertIfNotFound: boolean): Promise<UserType | [affectedCount: number]> {
if(userDetail.id) {
const existingUser = await this.findByPk(userDetail.id);
if(existingUser) {

View File

@ -1,9 +1,10 @@
import { Body, Controller, Delete, Get, Param, Post, Put, Res } from '@nestjs/common';
import { Body, Controller, Delete, Get, Param, Post, Put, Res, UsePipes, ValidationPipe } from '@nestjs/common';
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';
import { UserDTO, UserUpdateDTO } from './user.dto';
@ApiTags('users')
@Controller('users')
@ -160,7 +161,7 @@ export class UserController {
@Post()
@ApiOperation({ summary: 'Insert a new user' })
@ApiBody({ type: User, description: 'User data to insert' })
@ApiBody({ type: UserDTO, description: 'User data to insert' })
@ApiResponse({
status: 400,
description: 'Failed to insert user',
@ -179,7 +180,8 @@ export class UserController {
status: 201,
description: 'User successfully created',
})
async insert(@Body() user: User, @Res() res: Response) {
@UsePipes(new ValidationPipe({ whitelist: true}))
async insert(@Body() user: UserDTO, @Res() res: Response) {
if (!user) {
const response = new GenericResponse({
exception: true,
@ -189,7 +191,6 @@ export class UserController {
}, null);
return res.status(400).send(response);
}
delete user.id;
if (user.password) {
user.password = this.encryptPassword(user.password);
}
@ -209,7 +210,7 @@ export class UserController {
@Put()
@ApiOperation({ summary: 'Update an existing user' })
@ApiBody({ type: User, description: 'User data to update' })
@ApiBody({ type: UserUpdateDTO, description: 'User data to update' })
@ApiResponse({
status: 400,
description: 'Failed to update user',
@ -240,7 +241,8 @@ export class UserController {
status: 200,
description: 'User successfully updated',
})
async update(@Body() user: User, @Res() res: Response) {
@UsePipes(new ValidationPipe({ whitelist: true, skipMissingProperties: true }))
async update(@Body() user: UserUpdateDTO, @Res() res: Response) {
if (!user || !user.id) {
const response = new GenericResponse({
exception: true,

View File

@ -30,7 +30,7 @@ export class UserService {
return User.destroy({where: {id: id}});
}
async upsert(userDetail: User, insertIfNotFound: boolean): Promise<User | [affectedCount: number]> {
async upsert(userDetail: any, insertIfNotFound: boolean): Promise<User | [affectedCount: number]> {
if(userDetail.id) {
const existingUser = await this.findByPk(userDetail.id);
if(existingUser) {
@ -41,8 +41,4 @@ export class UserService {
return User.create(userDetail as any)
}
}
async login(user: User): Promise<User> {
return User.findOne({where: user as any, include: UserAdditionalDetail})
}
}