added validationPipes
This commit is contained in:
parent
90f378a877
commit
0fceef8c44
@ -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 { ActionsService } from './actions.service';
|
||||||
import { Response } from 'express';
|
import { Response } from 'express';
|
||||||
import { GenericResponse } from '../common/GenericResponse.model';
|
import { GenericResponse } from '../common/GenericResponse.model';
|
||||||
@ -50,6 +50,7 @@ export class ActionsController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Post()
|
@Post()
|
||||||
|
@UsePipes(new ValidationPipe({ whitelist: true}))
|
||||||
async insert(@Body() actions: Actions, @Res() res: Response) {
|
async insert(@Body() actions: Actions, @Res() res: Response) {
|
||||||
if(!actions) {
|
if(!actions) {
|
||||||
const response = new GenericResponse({
|
const response = new GenericResponse({
|
||||||
|
|||||||
@ -25,7 +25,7 @@ export class ActionsService {
|
|||||||
return Actions.destroy({ where: { id: id } });
|
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) {
|
if (actions.id) {
|
||||||
const existingActions = await this.findByPk(actions.id);
|
const existingActions = await this.findByPk(actions.id);
|
||||||
if (existingActions) {
|
if (existingActions) {
|
||||||
|
|||||||
@ -13,7 +13,7 @@ export class AuthService {
|
|||||||
|
|
||||||
constructor(private userService: UserService, private jwtService: JwtService) { }
|
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];
|
const config = Utility.jwtConfig[type];
|
||||||
return this.jwtService.sign(payload, {
|
return this.jwtService.sign(payload, {
|
||||||
secret: config.secretOrKey,
|
secret: config.secretOrKey,
|
||||||
@ -28,17 +28,17 @@ export class AuthService {
|
|||||||
secret: config.secretOrKey,
|
secret: config.secretOrKey,
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// console.log(`${type} token is invalid`, error);
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async validateUser(payload: JwtPayload) {
|
async validateUser(payload: any) {
|
||||||
return this.userService.findByEmail(payload.email);
|
return this.userService.findByEmail(payload.email);
|
||||||
}
|
}
|
||||||
|
|
||||||
async login(user: any) {
|
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 accessToken = this.signToken(payload, 'accessToken');
|
||||||
const refreshToken = this.signToken(payload, 'refreshToken');
|
const refreshToken = this.signToken(payload, 'refreshToken');
|
||||||
await RefreshToken.create({ email: user.email, token: refreshToken, type: 'jwt' });
|
await RefreshToken.create({ email: user.email, token: refreshToken, type: 'jwt' });
|
||||||
@ -49,7 +49,8 @@ export class AuthService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async signup(user: any) {
|
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 accessToken = this.signToken(payload, 'accessToken');
|
||||||
const refreshToken = this.signToken(payload, 'refreshToken');
|
const refreshToken = this.signToken(payload, 'refreshToken');
|
||||||
await RefreshToken.create({ email: user.email, token: refreshToken, type: 'jwt' });
|
await RefreshToken.create({ email: user.email, token: refreshToken, type: 'jwt' });
|
||||||
@ -64,34 +65,23 @@ export class AuthService {
|
|||||||
if (!payload) {
|
if (!payload) {
|
||||||
throw new Error('Invalid refresh token');
|
throw new Error('Invalid refresh token');
|
||||||
}
|
}
|
||||||
|
|
||||||
// console.log(refreshToken);
|
|
||||||
// console.log(payload);
|
|
||||||
const user = await this.userService.findByEmail(payload.email);
|
const user = await this.userService.findByEmail(payload.email);
|
||||||
if (!user) {
|
if (!user) {
|
||||||
throw new Error('User not found');
|
throw new Error('User not found');
|
||||||
}
|
}
|
||||||
// console.log(user)
|
const { password, ...rest } = user;
|
||||||
const accessToken = this.signToken({
|
const newPayload = { rest };
|
||||||
email: payload.email
|
const accessToken = this.signToken({ newPayload }, 'accessToken');
|
||||||
}, 'accessToken');
|
|
||||||
// console.log(accessToken)
|
|
||||||
return { access_token: accessToken };
|
return { access_token: accessToken };
|
||||||
}
|
}
|
||||||
|
|
||||||
async verifyRefreshToken(refreshToken: string) {
|
async verifyRefreshToken(refreshToken: string) {
|
||||||
const payload = this.verifyToken(refreshToken, 'refreshToken');
|
const payload = this.verifyToken(refreshToken, 'refreshToken');
|
||||||
if (payload) {
|
|
||||||
console.log("Refresh token is valid", payload);
|
|
||||||
}
|
|
||||||
return payload;
|
return payload;
|
||||||
}
|
}
|
||||||
|
|
||||||
async verifyAccessToken(accessToken: string) {
|
async verifyAccessToken(accessToken: string) {
|
||||||
const payload = this.verifyToken(accessToken, 'accessToken');
|
const payload = this.verifyToken(accessToken, 'accessToken');
|
||||||
if (payload) {
|
|
||||||
console.log("Access token is valid", payload);
|
|
||||||
}
|
|
||||||
return payload;
|
return payload;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -122,8 +112,9 @@ export class AuthService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const payload = existingUser.get();
|
const payload = existingUser.get();
|
||||||
const accessToken = await this.signToken(payload, 'accessToken');
|
const { password, ...rest } = payload
|
||||||
const refreshToken = await this.signToken(payload, 'refreshToken');
|
const accessToken = this.signToken(rest, 'accessToken');
|
||||||
|
const refreshToken = this.signToken(rest, 'refreshToken');
|
||||||
await RefreshToken.create({ email: payload.email, token: refreshToken, type: 'jwt' });
|
await RefreshToken.create({ email: payload.email, token: refreshToken, type: 'jwt' });
|
||||||
return {
|
return {
|
||||||
statusCode: 200,
|
statusCode: 200,
|
||||||
|
|||||||
@ -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 { CastService } from './cast.service';
|
import { CastService } from './cast.service';
|
||||||
import { Response } from 'express';
|
import { Response } from 'express';
|
||||||
import { GenericResponse } from '../common/GenericResponse.model';
|
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 { ApiTags, ApiOperation, ApiResponse, ApiParam, ApiBody } from '@nestjs/swagger';
|
||||||
|
import { CastDTO, CastUpdateDTO } from './cast.dto';
|
||||||
|
|
||||||
@ApiTags('cast')
|
@ApiTags('cast')
|
||||||
@Controller('cast')
|
@Controller('cast')
|
||||||
export class CastController {
|
export class CastController {
|
||||||
constructor(private castService: CastService) {}
|
constructor(private castService: CastService) { }
|
||||||
|
|
||||||
@Get("/all")
|
@Get("/all")
|
||||||
@ApiOperation({ summary: 'Get all casts' })
|
@ApiOperation({ summary: 'Get all casts' })
|
||||||
@ -160,7 +161,7 @@ export class CastController {
|
|||||||
|
|
||||||
@Post()
|
@Post()
|
||||||
@ApiOperation({ summary: 'Insert a new cast' })
|
@ApiOperation({ summary: 'Insert a new cast' })
|
||||||
@ApiBody({ type: Cast, description: 'Cast data to insert' })
|
@ApiBody({ type: CastDTO, description: 'Cast data to insert' })
|
||||||
@ApiResponse({
|
@ApiResponse({
|
||||||
status: 400,
|
status: 400,
|
||||||
description: 'Invalid cast data',
|
description: 'Invalid cast data',
|
||||||
@ -178,7 +179,8 @@ export class CastController {
|
|||||||
status: 201,
|
status: 201,
|
||||||
description: 'Successfully created a cast',
|
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) {
|
if (!cast) {
|
||||||
const response = new GenericResponse({
|
const response = new GenericResponse({
|
||||||
exception: true,
|
exception: true,
|
||||||
@ -188,7 +190,6 @@ export class CastController {
|
|||||||
}, null);
|
}, null);
|
||||||
return res.status(400).send(response);
|
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 response = await this.castService.upsert(cast, true);
|
||||||
const httpResponse = new GenericResponse(null, response);
|
const httpResponse = new GenericResponse(null, response);
|
||||||
res.status(201).send(httpResponse);
|
res.status(201).send(httpResponse);
|
||||||
@ -196,7 +197,7 @@ export class CastController {
|
|||||||
|
|
||||||
@Put()
|
@Put()
|
||||||
@ApiOperation({ summary: 'Update an existing cast' })
|
@ApiOperation({ summary: 'Update an existing cast' })
|
||||||
@ApiBody({ type: Cast, description: 'Cast data to update' })
|
@ApiBody({ type: CastUpdateDTO, description: 'Cast data to update' })
|
||||||
@ApiResponse({
|
@ApiResponse({
|
||||||
status: 400,
|
status: 400,
|
||||||
description: 'Invalid cast data or ID missing',
|
description: 'Invalid cast data or ID missing',
|
||||||
@ -227,7 +228,8 @@ export class CastController {
|
|||||||
status: 200,
|
status: 200,
|
||||||
description: 'Successfully updated cast',
|
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) {
|
if (!cast || !cast.id) {
|
||||||
const response = new GenericResponse({
|
const response = new GenericResponse({
|
||||||
exception: true,
|
exception: true,
|
||||||
|
|||||||
@ -2,7 +2,7 @@ import { IsString, IsNumber, IsDate, IsOptional, IsNotEmpty } from 'class-valida
|
|||||||
import { ApiProperty } from '@nestjs/swagger';
|
import { ApiProperty } from '@nestjs/swagger';
|
||||||
import { Transform } from 'class-transformer';
|
import { Transform } from 'class-transformer';
|
||||||
|
|
||||||
export class CastMemberDTO {
|
export class CastDTO {
|
||||||
|
|
||||||
@ApiProperty({ type: Number })
|
@ApiProperty({ type: Number })
|
||||||
@IsNumber()
|
@IsNumber()
|
||||||
@ -69,3 +69,11 @@ export class CastMemberDTO {
|
|||||||
@IsNotEmpty()
|
@IsNotEmpty()
|
||||||
version: number;
|
version: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export class CastUpdateDTO extends CastDTO {
|
||||||
|
|
||||||
|
@ApiProperty({ type: Number })
|
||||||
|
@IsNumber()
|
||||||
|
@IsNotEmpty()
|
||||||
|
id: number;
|
||||||
|
}
|
||||||
@ -27,7 +27,7 @@ export class CastService {
|
|||||||
return Cast.destroy({ where: { id: id } });
|
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) {
|
if (cast.id) {
|
||||||
const existingCast = await this.findByPk(cast.id);
|
const existingCast = await this.findByPk(cast.id);
|
||||||
if (existingCast) {
|
if (existingCast) {
|
||||||
|
|||||||
@ -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 { EventAnalyticsService } from './event-analytics.service';
|
||||||
import { Response } from 'express';
|
import { Response } from 'express';
|
||||||
import { GenericResponse } from '../common/GenericResponse.model';
|
import { GenericResponse } from '../common/GenericResponse.model';
|
||||||
import EventAnalytics from './event-analytics.entity';
|
import EventAnalytics from './event-analytics.entity';
|
||||||
import { ApiTags, ApiOperation, ApiResponse, ApiParam, ApiBody } from '@nestjs/swagger';
|
import { ApiTags, ApiOperation, ApiResponse, ApiParam, ApiBody } from '@nestjs/swagger';
|
||||||
|
import { EventAnalyticsDTO, EventAnalyticsUpdateDTO } from './event-analytics.dto';
|
||||||
|
|
||||||
@ApiTags('event-analytics')
|
@ApiTags('event-analytics')
|
||||||
@Controller('event-analytics')
|
@Controller('event-analytics')
|
||||||
@ -148,7 +149,7 @@ export class EventAnalyticsController {
|
|||||||
|
|
||||||
@Post()
|
@Post()
|
||||||
@ApiOperation({ summary: 'Insert a new event analytics record' })
|
@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({
|
@ApiResponse({
|
||||||
status: 400,
|
status: 400,
|
||||||
description: 'Invalid event analytics data',
|
description: 'Invalid event analytics data',
|
||||||
@ -163,7 +164,8 @@ export class EventAnalyticsController {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ApiResponse({ status: 201, description: 'Successfully created event analytics record' })
|
@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) {
|
if (!analytics) {
|
||||||
return res.status(400).send(new GenericResponse({
|
return res.status(400).send(new GenericResponse({
|
||||||
exception: true,
|
exception: true,
|
||||||
@ -172,15 +174,13 @@ export class EventAnalyticsController {
|
|||||||
stackTrace: 'Request'
|
stackTrace: 'Request'
|
||||||
}, null));
|
}, null));
|
||||||
}
|
}
|
||||||
|
|
||||||
delete analytics.id;
|
|
||||||
const response = await this.eventAnalyticsService.upsert(analytics, true);
|
const response = await this.eventAnalyticsService.upsert(analytics, true);
|
||||||
res.status(201).send(new GenericResponse(null, response));
|
res.status(201).send(new GenericResponse(null, response));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Put()
|
@Put()
|
||||||
@ApiOperation({ summary: 'Update an existing event analytics record' })
|
@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({
|
@ApiResponse({
|
||||||
status: 400,
|
status: 400,
|
||||||
description: 'Invalid event analytics data or ID missing',
|
description: 'Invalid event analytics data or ID missing',
|
||||||
@ -208,7 +208,8 @@ export class EventAnalyticsController {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ApiResponse({ status: 200, description: 'Successfully updated event analytics record' })
|
@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) {
|
if (!analytics || !analytics.id) {
|
||||||
return res.status(400).send(new GenericResponse({
|
return res.status(400).send(new GenericResponse({
|
||||||
exception: true,
|
exception: true,
|
||||||
|
|||||||
@ -27,7 +27,7 @@ export class EventAnalyticsService {
|
|||||||
return EventAnalytics.destroy({ where: { id: id } });
|
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) {
|
if (eventAnalytics.id) {
|
||||||
const existing = await this.findByPk(eventAnalytics.id);
|
const existing = await this.findByPk(eventAnalytics.id);
|
||||||
if (existing) {
|
if (existing) {
|
||||||
|
|||||||
@ -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 { EventCategoryService } from './event-category.service';
|
||||||
import { Response } from 'express';
|
import { Response } from 'express';
|
||||||
import { GenericResponse } from '../common/GenericResponse.model';
|
import { GenericResponse } from '../common/GenericResponse.model';
|
||||||
import EventCategory from './event-category.entity';
|
import EventCategory from './event-category.entity';
|
||||||
import { ApiTags, ApiOperation, ApiResponse, ApiParam, ApiBody } from '@nestjs/swagger';
|
import { ApiTags, ApiOperation, ApiResponse, ApiParam, ApiBody } from '@nestjs/swagger';
|
||||||
|
import { EventCategoryDTO, EventCategoryUpdateDTO } from './event-category.dto';
|
||||||
|
|
||||||
@ApiTags('eventCategory')
|
@ApiTags('eventCategory')
|
||||||
@Controller('eventCategory')
|
@Controller('eventCategory')
|
||||||
@ -151,7 +152,7 @@ export class EventCategoryController {
|
|||||||
|
|
||||||
@Post()
|
@Post()
|
||||||
@ApiOperation({ summary: 'Insert a new event category' })
|
@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: 201, description: 'Successfully created an event category' })
|
||||||
@ApiResponse({
|
@ApiResponse({
|
||||||
status: 400,
|
status: 400,
|
||||||
@ -166,7 +167,8 @@ export class EventCategoryController {
|
|||||||
data: null
|
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) {
|
if (!category) {
|
||||||
return res.status(400).send(new GenericResponse({
|
return res.status(400).send(new GenericResponse({
|
||||||
exception: true,
|
exception: true,
|
||||||
@ -175,15 +177,13 @@ export class EventCategoryController {
|
|||||||
stackTrace: 'Request'
|
stackTrace: 'Request'
|
||||||
}, null));
|
}, null));
|
||||||
}
|
}
|
||||||
|
|
||||||
delete category.id;
|
|
||||||
const response = await this.eventCategoryService.upsert(category, true);
|
const response = await this.eventCategoryService.upsert(category, true);
|
||||||
res.status(201).send(new GenericResponse(null, response));
|
res.status(201).send(new GenericResponse(null, response));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Put()
|
@Put()
|
||||||
@ApiOperation({ summary: 'Update an existing event category' })
|
@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: 200, description: 'Successfully updated event category' })
|
||||||
@ApiResponse({
|
@ApiResponse({
|
||||||
status: 400,
|
status: 400,
|
||||||
@ -211,7 +211,8 @@ export class EventCategoryController {
|
|||||||
data: null
|
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) {
|
if (!category || !category.id) {
|
||||||
return res.status(400).send(new GenericResponse({
|
return res.status(400).send(new GenericResponse({
|
||||||
exception: true,
|
exception: true,
|
||||||
|
|||||||
@ -26,7 +26,7 @@ export class EventCategoryService {
|
|||||||
return EventCategory.destroy({ where: { id } });
|
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) {
|
if (category.id) {
|
||||||
const existingCategory = await this.findByPk(category.id);
|
const existingCategory = await this.findByPk(category.id);
|
||||||
if (existingCategory) {
|
if (existingCategory) {
|
||||||
|
|||||||
@ -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 { EventEpisodeService } from './event-episodes.service';
|
||||||
import { Response } from 'express';
|
import { Response } from 'express';
|
||||||
import { GenericResponse } from '../common/GenericResponse.model';
|
import { GenericResponse } from '../common/GenericResponse.model';
|
||||||
import EventEpisode from './event-episodes.entity';
|
import EventEpisode from './event-episodes.entity';
|
||||||
import { ApiTags, ApiOperation, ApiResponse, ApiParam, ApiBody } from '@nestjs/swagger';
|
import { ApiTags, ApiOperation, ApiResponse, ApiParam, ApiBody } from '@nestjs/swagger';
|
||||||
|
import { EventEpisodeDTO, EventEpisodeUpdateDTO } from './event-episodes.dto';
|
||||||
|
|
||||||
@ApiTags('event-episode')
|
@ApiTags('event-episode')
|
||||||
@Controller('event-episode')
|
@Controller('event-episode')
|
||||||
@ -160,7 +161,7 @@ export class EventEpisodeController {
|
|||||||
|
|
||||||
@Post()
|
@Post()
|
||||||
@ApiOperation({ summary: 'Insert a new event episode' })
|
@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({
|
@ApiResponse({
|
||||||
status: 400,
|
status: 400,
|
||||||
description: 'Invalid event episode data',
|
description: 'Invalid event episode data',
|
||||||
@ -178,7 +179,8 @@ export class EventEpisodeController {
|
|||||||
status: 201,
|
status: 201,
|
||||||
description: 'Successfully created an event episode',
|
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) {
|
if (!eventEpisode) {
|
||||||
const response = new GenericResponse({
|
const response = new GenericResponse({
|
||||||
exception: true,
|
exception: true,
|
||||||
@ -188,7 +190,6 @@ export class EventEpisodeController {
|
|||||||
}, null);
|
}, null);
|
||||||
return res.status(400).send(response);
|
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 response = await this.eventEpisodeService.upsert(eventEpisode, true);
|
||||||
const httpResponse = new GenericResponse(null, response);
|
const httpResponse = new GenericResponse(null, response);
|
||||||
res.status(201).send(httpResponse);
|
res.status(201).send(httpResponse);
|
||||||
@ -196,7 +197,7 @@ export class EventEpisodeController {
|
|||||||
|
|
||||||
@Put()
|
@Put()
|
||||||
@ApiOperation({ summary: 'Update an existing event episode' })
|
@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({
|
@ApiResponse({
|
||||||
status: 400,
|
status: 400,
|
||||||
description: 'Invalid event episode data or ID missing',
|
description: 'Invalid event episode data or ID missing',
|
||||||
@ -227,7 +228,8 @@ export class EventEpisodeController {
|
|||||||
status: 200,
|
status: 200,
|
||||||
description: 'Successfully updated event episode',
|
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) {
|
if (!eventEpisode || !eventEpisode.id) {
|
||||||
const response = new GenericResponse({
|
const response = new GenericResponse({
|
||||||
exception: true,
|
exception: true,
|
||||||
|
|||||||
@ -91,3 +91,9 @@ export class EventEpisodeDTO {
|
|||||||
@IsNotEmpty()
|
@IsNotEmpty()
|
||||||
version: number;
|
version: number;
|
||||||
}
|
}
|
||||||
|
export class EventEpisodeUpdateDTO extends EventEpisodeDTO {
|
||||||
|
@ApiProperty({ type: Number })
|
||||||
|
@IsNumber()
|
||||||
|
@IsNotEmpty()
|
||||||
|
id: number;
|
||||||
|
}
|
||||||
@ -27,7 +27,7 @@ export class EventEpisodeService {
|
|||||||
return EventEpisode.destroy({ where: { id: id } });
|
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) {
|
if (eventEpisode.id) {
|
||||||
const existingEventEpisode = await this.findByPk(eventEpisode.id);
|
const existingEventEpisode = await this.findByPk(eventEpisode.id);
|
||||||
if (existingEventEpisode) {
|
if (existingEventEpisode) {
|
||||||
|
|||||||
@ -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 { EventService } from './event.service';
|
||||||
import { Response } from 'express';
|
import { Response } from 'express';
|
||||||
import { GenericResponse } from '../common/GenericResponse.model';
|
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 { FileInterceptor, FilesInterceptor } from '@nestjs/platform-express';
|
||||||
import { diskStorage } from 'multer';
|
import { diskStorage } from 'multer';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
|
import { EventDTO, EventUpdateDTO } from './event.dto';
|
||||||
|
|
||||||
@ApiTags('event')
|
@ApiTags('event')
|
||||||
@Controller('event')
|
@Controller('event')
|
||||||
@ -191,23 +192,24 @@ export class EventController {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
}))
|
}))
|
||||||
async insert(@Body() body: any, @Res() res: Response, @UploadedFiles() files?: Express.Multer.File[]) {
|
@UsePipes(new ValidationPipe({ whitelist: true , skipMissingProperties: true }))
|
||||||
const event = JSON.parse(body.event)
|
async insert(@Body() body: EventDTO, @Res() res: Response, @UploadedFiles() files?: Express.Multer.File[]) {
|
||||||
console.log(event);
|
// const event = JSON.parse(body)
|
||||||
if (!files) {
|
// console.log(body);
|
||||||
console.log("No files");
|
// if (!files) {
|
||||||
}
|
// console.log("No files");
|
||||||
if (!event.orgEmail) {
|
// }
|
||||||
|
if (!body.organizer_id) {
|
||||||
const response = new GenericResponse({
|
const response = new GenericResponse({
|
||||||
exception: true,
|
exception: true,
|
||||||
exceptionSeverity: 'HIGH',
|
exceptionSeverity: 'HIGH',
|
||||||
exceptionMessage: 'ERR.MISSING_ORG_EMAIL',
|
exceptionMessage: 'ERR.MISSING_ORGANIZER_ID',
|
||||||
stackTrace: 'Request'
|
stackTrace: 'Request'
|
||||||
}, null);
|
}, null);
|
||||||
return res.status(400).send(response);
|
return res.status(400).send(response);
|
||||||
}
|
}
|
||||||
console.log(files);
|
// console.log(files);
|
||||||
if (!event || !files) {
|
if (!body || !files) {
|
||||||
const response = new GenericResponse({
|
const response = new GenericResponse({
|
||||||
exception: true,
|
exception: true,
|
||||||
exceptionSeverity: 'HIGH',
|
exceptionSeverity: 'HIGH',
|
||||||
@ -218,12 +220,11 @@ export class EventController {
|
|||||||
}
|
}
|
||||||
const imageFiles = files.filter(file => file.mimetype.startsWith('image/')).map(file => file.filename);
|
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);
|
const videoFiles = files.filter(file => file.mimetype.startsWith('video/')).map(file => file.filename);
|
||||||
event.images = {
|
body.images = {
|
||||||
images: imageFiles,
|
images: imageFiles,
|
||||||
videos: videoFiles,
|
videos: videoFiles,
|
||||||
};
|
};
|
||||||
delete event.id;
|
const response = await this.eventService.upsert(body, true);
|
||||||
const response = await this.eventService.upsert(event, true);
|
|
||||||
const httpResponse = new GenericResponse(null, response);
|
const httpResponse = new GenericResponse(null, response);
|
||||||
res.status(201).send(httpResponse);
|
res.status(201).send(httpResponse);
|
||||||
}
|
}
|
||||||
@ -261,7 +262,8 @@ export class EventController {
|
|||||||
status: 200,
|
status: 200,
|
||||||
description: 'Successfully updated event',
|
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) {
|
if (!event || !event.id) {
|
||||||
const response = new GenericResponse({
|
const response = new GenericResponse({
|
||||||
exception: true,
|
exception: true,
|
||||||
|
|||||||
@ -13,11 +13,7 @@ export class EventService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async findByPk(id: number): Promise<Event> {
|
async findByPk(id: number): Promise<Event> {
|
||||||
|
return Event.findByPk(id);
|
||||||
const event = Event.findByPk(id,)
|
|
||||||
// //const textbookExists = await this.checkTextbookExists((await event).textbookId);
|
|
||||||
|
|
||||||
return event
|
|
||||||
}
|
}
|
||||||
|
|
||||||
findOne(event: Event): Promise<Event> {
|
findOne(event: Event): Promise<Event> {
|
||||||
@ -32,16 +28,14 @@ export class EventService {
|
|||||||
return Event.destroy({ where: { id: id } });
|
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) {
|
if (event.id) {
|
||||||
const existingEvent = await this.findByPk(event.id);
|
const existingEvent = await this.findByPk(event.id);
|
||||||
if (existingEvent) {
|
if (existingEvent) {
|
||||||
return Event.update(event, { where: { id: event.id } });
|
return Event.update(event, { where: { id: event.id } });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (insertIfNotFound) {
|
if (insertIfNotFound) {
|
||||||
//const textbookExists = await this.checkTextbookExists(event.textbookId);
|
|
||||||
|
|
||||||
return Event.create(event as any)
|
return Event.create(event as any)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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 { EventAdditionalDetailService } from './eventAdditionalDetail.service';
|
||||||
import { Response } from 'express';
|
import { Response } from 'express';
|
||||||
import { GenericResponse } from '../../common/GenericResponse.model';
|
import { GenericResponse } from '../../common/GenericResponse.model';
|
||||||
import EventAdditionalDetail from './eventAdditionalDetail.entity';
|
import EventAdditionalDetail from './eventAdditionalDetail.entity';
|
||||||
import { ApiTags, ApiOperation, ApiResponse, ApiParam, ApiBody } from '@nestjs/swagger';
|
import { ApiTags, ApiOperation, ApiResponse, ApiParam, ApiBody } from '@nestjs/swagger';
|
||||||
|
import { EventAdditionalDetailDTO, EventAdditionalDetailUpdateDTO } from './eventAdditionalDetail.dto';
|
||||||
|
|
||||||
@ApiTags('event/addl')
|
@ApiTags('event/addl')
|
||||||
@Controller('event/addl/')
|
@Controller('event/addl/')
|
||||||
@ -160,7 +161,7 @@ export class EventAdditionalDetailController {
|
|||||||
|
|
||||||
@Post()
|
@Post()
|
||||||
@ApiOperation({ summary: 'Insert a new eventAdditionalDetail' })
|
@ApiOperation({ summary: 'Insert a new eventAdditionalDetail' })
|
||||||
@ApiBody({ type: EventAdditionalDetail, description: 'EventAdditionalDetail data to insert' })
|
@ApiBody({ type: EventAdditionalDetailDTO, description: 'EventAdditionalDetail data to insert' })
|
||||||
@ApiResponse({
|
@ApiResponse({
|
||||||
status: 400,
|
status: 400,
|
||||||
description: 'Invalid eventAdditionalDetail data',
|
description: 'Invalid eventAdditionalDetail data',
|
||||||
@ -178,7 +179,8 @@ export class EventAdditionalDetailController {
|
|||||||
status: 201,
|
status: 201,
|
||||||
description: 'Successfully created a eventAdditionalDetail',
|
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) {
|
if (!eventAdditionalDetail) {
|
||||||
const response = new GenericResponse({
|
const response = new GenericResponse({
|
||||||
exception: true,
|
exception: true,
|
||||||
@ -188,7 +190,6 @@ export class EventAdditionalDetailController {
|
|||||||
}, null);
|
}, null);
|
||||||
return res.status(400).send(response);
|
return res.status(400).send(response);
|
||||||
}
|
}
|
||||||
delete eventAdditionalDetail.id;
|
|
||||||
const response = await this.eventAdditionalDetailService.upsert(eventAdditionalDetail, true);
|
const response = await this.eventAdditionalDetailService.upsert(eventAdditionalDetail, true);
|
||||||
const httpResponse = new GenericResponse(null, response);
|
const httpResponse = new GenericResponse(null, response);
|
||||||
res.status(201).send(httpResponse);
|
res.status(201).send(httpResponse);
|
||||||
@ -196,7 +197,7 @@ export class EventAdditionalDetailController {
|
|||||||
|
|
||||||
@Put()
|
@Put()
|
||||||
@ApiOperation({ summary: 'Update an existing eventAdditionalDetail' })
|
@ApiOperation({ summary: 'Update an existing eventAdditionalDetail' })
|
||||||
@ApiBody({ type: EventAdditionalDetail, description: 'EventAdditionalDetail data to update' })
|
@ApiBody({ type: EventAdditionalDetailUpdateDTO, description: 'EventAdditionalDetail data to update' })
|
||||||
@ApiResponse({
|
@ApiResponse({
|
||||||
status: 400,
|
status: 400,
|
||||||
description: 'Invalid eventAdditionalDetail data or ID missing',
|
description: 'Invalid eventAdditionalDetail data or ID missing',
|
||||||
@ -227,7 +228,8 @@ export class EventAdditionalDetailController {
|
|||||||
status: 200,
|
status: 200,
|
||||||
description: 'Successfully updated eventAdditionalDetail',
|
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) {
|
if (!eventAdditionalDetail || !eventAdditionalDetail.id) {
|
||||||
const response = new GenericResponse({
|
const response = new GenericResponse({
|
||||||
exception: true,
|
exception: true,
|
||||||
|
|||||||
@ -14,9 +14,7 @@ export class EventAdditionalDetailService {
|
|||||||
|
|
||||||
async findByPk(id: number): Promise<EventAdditionalDetail> {
|
async findByPk(id: number): Promise<EventAdditionalDetail> {
|
||||||
|
|
||||||
const eventAdditionalDetail = EventAdditionalDetail.findByPk(id,)
|
const eventAdditionalDetail = EventAdditionalDetail.findByPk(id,)
|
||||||
// //const textbookExists = await this.checkTextbookExists((await eventAdditionalDetail).textbookId);
|
|
||||||
|
|
||||||
return eventAdditionalDetail
|
return eventAdditionalDetail
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -32,16 +30,14 @@ export class EventAdditionalDetailService {
|
|||||||
return EventAdditionalDetail.destroy({ where: { id: id } });
|
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) {
|
if (eventAdditionalDetail.id) {
|
||||||
const existingEventAdditionalDetail = await this.findByPk(eventAdditionalDetail.id);
|
const existingEventAdditionalDetail = await this.findByPk(eventAdditionalDetail.id);
|
||||||
if (existingEventAdditionalDetail) {
|
if (existingEventAdditionalDetail) {
|
||||||
return EventAdditionalDetail.update(eventAdditionalDetail, { where: { id: eventAdditionalDetail.id } });
|
return EventAdditionalDetail.update(eventAdditionalDetail, { where: { id: eventAdditionalDetail.id } });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (insertIfNotFound) {
|
if (insertIfNotFound) {
|
||||||
//const textbookExists = await this.checkTextbookExists(eventAdditionalDetail.textbookId);
|
|
||||||
|
|
||||||
return EventAdditionalDetail.create(eventAdditionalDetail as any)
|
return EventAdditionalDetail.create(eventAdditionalDetail as any)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -181,7 +181,6 @@ export class PayoutController {
|
|||||||
})
|
})
|
||||||
@UsePipes(new ValidationPipe({ whitelist: true }))
|
@UsePipes(new ValidationPipe({ whitelist: true }))
|
||||||
async insert(@Body() payout: PayoutDTO, @Res() res: Response) {
|
async insert(@Body() payout: PayoutDTO, @Res() res: Response) {
|
||||||
console.log("Received payout:", payout);
|
|
||||||
if (!payout) {
|
if (!payout) {
|
||||||
const response = new GenericResponse({
|
const response = new GenericResponse({
|
||||||
exception: true,
|
exception: true,
|
||||||
|
|||||||
@ -14,11 +14,7 @@ export class PayoutService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async findByPk(id: number): Promise<Payout> {
|
async findByPk(id: number): Promise<Payout> {
|
||||||
|
return Payout.findByPk(id);
|
||||||
const payout = Payout.findByPk(id,)
|
|
||||||
// //const textbookExists = await this.checkTextbookExists((await payout).textbookId);
|
|
||||||
|
|
||||||
return payout
|
|
||||||
}
|
}
|
||||||
|
|
||||||
findOne(payout: Payout): Promise<Payout> {
|
findOne(payout: Payout): Promise<Payout> {
|
||||||
@ -40,7 +36,7 @@ export class PayoutService {
|
|||||||
return Payout.update(payout, { where: { id: payout.id } });
|
return Payout.update(payout, { where: { id: payout.id } });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (insertIfNotFound) {
|
if (insertIfNotFound) {
|
||||||
return Payout.create(payout as any)
|
return Payout.create(payout as any)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -25,7 +25,7 @@ export class PolicyService {
|
|||||||
return Policy.destroy({ where: { id: id } });
|
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) {
|
if (policy.id) {
|
||||||
const existingPolicy = await this.findByPk(policy.id);
|
const existingPolicy = await this.findByPk(policy.id);
|
||||||
if (existingPolicy) {
|
if (existingPolicy) {
|
||||||
|
|||||||
@ -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 { PromotionService } from './promotions.service'; // Updated service
|
||||||
import { Response } from 'express';
|
import { Response } from 'express';
|
||||||
import { GenericResponse } from '../common/GenericResponse.model';
|
import { GenericResponse } from '../common/GenericResponse.model';
|
||||||
import Promotion from './promotions.entity'; // Updated entity
|
import Promotion from './promotions.entity'; // Updated entity
|
||||||
import { ApiTags, ApiOperation, ApiResponse, ApiParam, ApiBody } from '@nestjs/swagger';
|
import { ApiTags, ApiOperation, ApiResponse, ApiParam, ApiBody } from '@nestjs/swagger';
|
||||||
|
import { PromotionDTO, PromotionUpdateDTO } from './promotions.dto';
|
||||||
|
|
||||||
@ApiTags('promotion')
|
@ApiTags('promotion')
|
||||||
@Controller('promotion')
|
@Controller('promotion')
|
||||||
@ -160,7 +161,7 @@ export class PromotionController {
|
|||||||
|
|
||||||
@Post()
|
@Post()
|
||||||
@ApiOperation({ summary: 'Insert a new promotion' })
|
@ApiOperation({ summary: 'Insert a new promotion' })
|
||||||
@ApiBody({ type: Promotion, description: 'Promotion data to insert' })
|
@ApiBody({ type: PromotionDTO, description: 'Promotion data to insert' })
|
||||||
@ApiResponse({
|
@ApiResponse({
|
||||||
status: 400,
|
status: 400,
|
||||||
description: 'Invalid promotion data',
|
description: 'Invalid promotion data',
|
||||||
@ -178,7 +179,8 @@ export class PromotionController {
|
|||||||
status: 201,
|
status: 201,
|
||||||
description: 'Successfully created a promotion',
|
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) {
|
if (!promotion) {
|
||||||
const response = new GenericResponse({
|
const response = new GenericResponse({
|
||||||
exception: true,
|
exception: true,
|
||||||
@ -188,7 +190,6 @@ export class PromotionController {
|
|||||||
}, null);
|
}, null);
|
||||||
return res.status(400).send(response);
|
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 response = await this.promotionService.upsert(promotion, true);
|
||||||
const httpResponse = new GenericResponse(null, response);
|
const httpResponse = new GenericResponse(null, response);
|
||||||
res.status(201).send(httpResponse);
|
res.status(201).send(httpResponse);
|
||||||
@ -196,7 +197,7 @@ export class PromotionController {
|
|||||||
|
|
||||||
@Put()
|
@Put()
|
||||||
@ApiOperation({ summary: 'Update an existing promotion' })
|
@ApiOperation({ summary: 'Update an existing promotion' })
|
||||||
@ApiBody({ type: Promotion, description: 'Promotion data to update' })
|
@ApiBody({ type: PromotionUpdateDTO, description: 'Promotion data to update' })
|
||||||
@ApiResponse({
|
@ApiResponse({
|
||||||
status: 400,
|
status: 400,
|
||||||
description: 'Invalid promotion data or ID missing',
|
description: 'Invalid promotion data or ID missing',
|
||||||
@ -227,7 +228,8 @@ export class PromotionController {
|
|||||||
status: 200,
|
status: 200,
|
||||||
description: 'Successfully updated promotion',
|
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) {
|
if (!promotion || !promotion.id) {
|
||||||
const response = new GenericResponse({
|
const response = new GenericResponse({
|
||||||
exception: true,
|
exception: true,
|
||||||
|
|||||||
@ -27,7 +27,7 @@ export class PromotionService {
|
|||||||
return Promotion.destroy({ where: { id: id } });
|
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) {
|
if (promotion.id) {
|
||||||
const existingPromotion = await this.findByPk(promotion.id);
|
const existingPromotion = await this.findByPk(promotion.id);
|
||||||
if (existingPromotion) {
|
if (existingPromotion) {
|
||||||
|
|||||||
@ -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();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@ -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 { RefundService } from './refund.service';
|
||||||
import { Response } from 'express';
|
import { Response } from 'express';
|
||||||
import { GenericResponse } from '../common/GenericResponse.model';
|
import { GenericResponse } from '../common/GenericResponse.model';
|
||||||
import Refund from './refund.entity';
|
import Refund from './refund.entity';
|
||||||
import { ApiTags, ApiOperation, ApiResponse, ApiParam, ApiBody } from '@nestjs/swagger';
|
import { ApiTags, ApiOperation, ApiResponse, ApiParam, ApiBody } from '@nestjs/swagger';
|
||||||
|
import { RefundDTO, RefundUpdateDTO } from './refund.dto';
|
||||||
|
|
||||||
@ApiTags('refund')
|
@ApiTags('refund')
|
||||||
@Controller('refund')
|
@Controller('refund')
|
||||||
@ -160,7 +161,7 @@ export class RefundController {
|
|||||||
|
|
||||||
@Post()
|
@Post()
|
||||||
@ApiOperation({ summary: 'Insert a new refund' })
|
@ApiOperation({ summary: 'Insert a new refund' })
|
||||||
@ApiBody({ type: Refund, description: 'Refund data to insert' })
|
@ApiBody({ type: RefundDTO, description: 'Refund data to insert' })
|
||||||
@ApiResponse({
|
@ApiResponse({
|
||||||
status: 400,
|
status: 400,
|
||||||
description: 'Invalid refund data',
|
description: 'Invalid refund data',
|
||||||
@ -178,7 +179,8 @@ export class RefundController {
|
|||||||
status: 201,
|
status: 201,
|
||||||
description: 'Successfully created a refund',
|
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) {
|
if (!refund) {
|
||||||
const response = new GenericResponse({
|
const response = new GenericResponse({
|
||||||
exception: true,
|
exception: true,
|
||||||
@ -188,7 +190,6 @@ export class RefundController {
|
|||||||
}, null);
|
}, null);
|
||||||
return res.status(400).send(response);
|
return res.status(400).send(response);
|
||||||
}
|
}
|
||||||
delete refund.id;
|
|
||||||
const response = await this.refundService.upsert(refund, true);
|
const response = await this.refundService.upsert(refund, true);
|
||||||
const httpResponse = new GenericResponse(null, response);
|
const httpResponse = new GenericResponse(null, response);
|
||||||
res.status(201).send(httpResponse);
|
res.status(201).send(httpResponse);
|
||||||
@ -196,7 +197,7 @@ export class RefundController {
|
|||||||
|
|
||||||
@Put()
|
@Put()
|
||||||
@ApiOperation({ summary: 'Update an existing refund' })
|
@ApiOperation({ summary: 'Update an existing refund' })
|
||||||
@ApiBody({ type: Refund, description: 'Refund data to update' })
|
@ApiBody({ type: RefundUpdateDTO, description: 'Refund data to update' })
|
||||||
@ApiResponse({
|
@ApiResponse({
|
||||||
status: 400,
|
status: 400,
|
||||||
description: 'Invalid refund data or ID missing',
|
description: 'Invalid refund data or ID missing',
|
||||||
@ -227,7 +228,8 @@ export class RefundController {
|
|||||||
status: 200,
|
status: 200,
|
||||||
description: 'Successfully updated refund',
|
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) {
|
if (!refund || !refund.id) {
|
||||||
const response = new GenericResponse({
|
const response = new GenericResponse({
|
||||||
exception: true,
|
exception: true,
|
||||||
|
|||||||
@ -13,11 +13,7 @@ export class RefundService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async findByPk(id: number): Promise<Refund> {
|
async findByPk(id: number): Promise<Refund> {
|
||||||
|
return Refund.findByPk(id);
|
||||||
const refund = Refund.findByPk(id,)
|
|
||||||
// //const textbookExists = await this.checkTextbookExists((await refund).textbookId);
|
|
||||||
|
|
||||||
return refund
|
|
||||||
}
|
}
|
||||||
|
|
||||||
findOne(refund: Refund): Promise<Refund> {
|
findOne(refund: Refund): Promise<Refund> {
|
||||||
@ -32,7 +28,7 @@ export class RefundService {
|
|||||||
return Refund.destroy({ where: { id: id } });
|
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) {
|
if (refund.id) {
|
||||||
const existingRefund = await this.findByPk(refund.id);
|
const existingRefund = await this.findByPk(refund.id);
|
||||||
if (existingRefund) {
|
if (existingRefund) {
|
||||||
@ -40,8 +36,6 @@ export class RefundService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (insertIfNotFound) {
|
if (insertIfNotFound) {
|
||||||
//const textbookExists = await this.checkTextbookExists(refund.textbookId);
|
|
||||||
|
|
||||||
return Refund.create(refund as any)
|
return Refund.create(refund as any)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -25,7 +25,7 @@ export class ResourcesService {
|
|||||||
return Resources.destroy({ where: { id: id } });
|
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) {
|
if (resources.id) {
|
||||||
const existingResources = await this.findByPk(resources.id);
|
const existingResources = await this.findByPk(resources.id);
|
||||||
if (existingResources) {
|
if (existingResources) {
|
||||||
|
|||||||
@ -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 { ReviewService } from './review.service';
|
||||||
import { Response } from 'express';
|
import { Response } from 'express';
|
||||||
import { GenericResponse } from '../common/GenericResponse.model';
|
import { GenericResponse } from '../common/GenericResponse.model';
|
||||||
import Review from './review.entity';
|
import Review from './review.entity';
|
||||||
import { ApiTags, ApiOperation, ApiResponse, ApiParam, ApiBody } from '@nestjs/swagger';
|
import { ApiTags, ApiOperation, ApiResponse, ApiParam, ApiBody } from '@nestjs/swagger';
|
||||||
|
import { ReviewDTO, ReviewUpdateDTO } from './review.dto';
|
||||||
|
|
||||||
@ApiTags('review')
|
@ApiTags('review')
|
||||||
@Controller('review')
|
@Controller('review')
|
||||||
@ -160,7 +161,7 @@ export class ReviewController {
|
|||||||
|
|
||||||
@Post()
|
@Post()
|
||||||
@ApiOperation({ summary: 'Insert a new review' })
|
@ApiOperation({ summary: 'Insert a new review' })
|
||||||
@ApiBody({ type: Review, description: 'Review data to insert' })
|
@ApiBody({ type: ReviewDTO, description: 'Review data to insert' })
|
||||||
@ApiResponse({
|
@ApiResponse({
|
||||||
status: 400,
|
status: 400,
|
||||||
description: 'Invalid review data',
|
description: 'Invalid review data',
|
||||||
@ -178,7 +179,8 @@ export class ReviewController {
|
|||||||
status: 201,
|
status: 201,
|
||||||
description: 'Successfully created a review',
|
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) {
|
if (!review) {
|
||||||
const response = new GenericResponse({
|
const response = new GenericResponse({
|
||||||
exception: true,
|
exception: true,
|
||||||
@ -188,7 +190,6 @@ export class ReviewController {
|
|||||||
}, null);
|
}, null);
|
||||||
return res.status(400).send(response);
|
return res.status(400).send(response);
|
||||||
}
|
}
|
||||||
delete review.id;
|
|
||||||
const response = await this.reviewService.upsert(review, true);
|
const response = await this.reviewService.upsert(review, true);
|
||||||
const httpResponse = new GenericResponse(null, response);
|
const httpResponse = new GenericResponse(null, response);
|
||||||
res.status(201).send(httpResponse);
|
res.status(201).send(httpResponse);
|
||||||
@ -196,7 +197,7 @@ export class ReviewController {
|
|||||||
|
|
||||||
@Put()
|
@Put()
|
||||||
@ApiOperation({ summary: 'Update an existing review' })
|
@ApiOperation({ summary: 'Update an existing review' })
|
||||||
@ApiBody({ type: Review, description: 'Review data to update' })
|
@ApiBody({ type: ReviewUpdateDTO, description: 'Review data to update' })
|
||||||
@ApiResponse({
|
@ApiResponse({
|
||||||
status: 400,
|
status: 400,
|
||||||
description: 'Invalid review data or ID missing',
|
description: 'Invalid review data or ID missing',
|
||||||
@ -227,7 +228,8 @@ export class ReviewController {
|
|||||||
status: 200,
|
status: 200,
|
||||||
description: 'Successfully updated review',
|
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) {
|
if (!review || !review.id) {
|
||||||
const response = new GenericResponse({
|
const response = new GenericResponse({
|
||||||
exception: true,
|
exception: true,
|
||||||
|
|||||||
@ -13,11 +13,7 @@ export class ReviewService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async findByPk(id: number): Promise<Review> {
|
async findByPk(id: number): Promise<Review> {
|
||||||
|
return Review.findByPk(id);
|
||||||
const review = Review.findByPk(id,)
|
|
||||||
// //const textbookExists = await this.checkTextbookExists((await review).textbookId);
|
|
||||||
|
|
||||||
return review
|
|
||||||
}
|
}
|
||||||
|
|
||||||
findOne(review: Review): Promise<Review> {
|
findOne(review: Review): Promise<Review> {
|
||||||
@ -32,16 +28,14 @@ export class ReviewService {
|
|||||||
return Review.destroy({ where: { id: id } });
|
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) {
|
if (review.id) {
|
||||||
const existingReview = await this.findByPk(review.id);
|
const existingReview = await this.findByPk(review.id);
|
||||||
if (existingReview) {
|
if (existingReview) {
|
||||||
return Review.update(review, { where: { id: review.id } });
|
return Review.update(review, { where: { id: review.id } });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (insertIfNotFound) {
|
if (insertIfNotFound) {
|
||||||
//const textbookExists = await this.checkTextbookExists(review.textbookId);
|
|
||||||
|
|
||||||
return Review.create(review as any)
|
return Review.create(review as any)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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 { SeatService } from './seat.service';
|
||||||
import { Response } from 'express';
|
import { Response } from 'express';
|
||||||
import { GenericResponse } from '../common/GenericResponse.model';
|
import { GenericResponse } from '../common/GenericResponse.model';
|
||||||
import Seat from './seat.entity';
|
import Seat from './seat.entity';
|
||||||
import { ApiTags, ApiOperation, ApiResponse, ApiParam, ApiBody } from '@nestjs/swagger';
|
import { ApiTags, ApiOperation, ApiResponse, ApiParam, ApiBody } from '@nestjs/swagger';
|
||||||
import { RedisService } from 'src/redis/redis.service';
|
import { RedisService } from 'src/redis/redis.service';
|
||||||
|
import { SeatDTO, SeatUpdateDTO } from './seat.dto';
|
||||||
|
|
||||||
@ApiTags('seat')
|
@ApiTags('seat')
|
||||||
@Controller('seat')
|
@Controller('seat')
|
||||||
@ -166,7 +167,7 @@ export class SeatController {
|
|||||||
|
|
||||||
@Post()
|
@Post()
|
||||||
@ApiOperation({ summary: 'Insert a new seat' })
|
@ApiOperation({ summary: 'Insert a new seat' })
|
||||||
@ApiBody({ type: Seat, description: 'Seat data to insert' })
|
@ApiBody({ type: SeatDTO, description: 'Seat data to insert' })
|
||||||
@ApiResponse({
|
@ApiResponse({
|
||||||
status: 400,
|
status: 400,
|
||||||
description: 'Invalid seat data',
|
description: 'Invalid seat data',
|
||||||
@ -184,7 +185,8 @@ export class SeatController {
|
|||||||
status: 201,
|
status: 201,
|
||||||
description: 'Successfully created a seat',
|
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) {
|
if (!seat) {
|
||||||
const response = new GenericResponse({
|
const response = new GenericResponse({
|
||||||
exception: true,
|
exception: true,
|
||||||
@ -194,7 +196,6 @@ export class SeatController {
|
|||||||
}, null);
|
}, null);
|
||||||
return res.status(400).send(response);
|
return res.status(400).send(response);
|
||||||
}
|
}
|
||||||
delete seat.id;
|
|
||||||
const response = await this.seatService.upsert(seat, true);
|
const response = await this.seatService.upsert(seat, true);
|
||||||
const httpResponse = new GenericResponse(null, response);
|
const httpResponse = new GenericResponse(null, response);
|
||||||
res.status(201).send(httpResponse);
|
res.status(201).send(httpResponse);
|
||||||
@ -202,7 +203,7 @@ export class SeatController {
|
|||||||
|
|
||||||
@Put()
|
@Put()
|
||||||
@ApiOperation({ summary: 'Update an existing seat' })
|
@ApiOperation({ summary: 'Update an existing seat' })
|
||||||
@ApiBody({ type: Seat, description: 'Seat data to update' })
|
@ApiBody({ type: SeatUpdateDTO, description: 'Seat data to update' })
|
||||||
@ApiResponse({
|
@ApiResponse({
|
||||||
status: 400,
|
status: 400,
|
||||||
description: 'Invalid seat data or ID missing',
|
description: 'Invalid seat data or ID missing',
|
||||||
@ -233,7 +234,8 @@ export class SeatController {
|
|||||||
status: 200,
|
status: 200,
|
||||||
description: 'Successfully updated seat',
|
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) {
|
if (!seat || !seat.id) {
|
||||||
const response = new GenericResponse({
|
const response = new GenericResponse({
|
||||||
exception: true,
|
exception: true,
|
||||||
|
|||||||
@ -13,9 +13,7 @@ export class SeatService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async findByPk(id: number): Promise<Seat> {
|
async findByPk(id: number): Promise<Seat> {
|
||||||
|
return Seat.findByPk(id);
|
||||||
const seat = Seat.findByPk(id,)
|
|
||||||
return seat
|
|
||||||
}
|
}
|
||||||
|
|
||||||
findOne(seat: Seat): Promise<Seat> {
|
findOne(seat: Seat): Promise<Seat> {
|
||||||
@ -34,14 +32,14 @@ export class SeatService {
|
|||||||
return Seat.update({ available: 'booked' }, { where: { eventId: eventId, seatNumber: seatNumber } });
|
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) {
|
if (seat.id) {
|
||||||
const existingSeat = await this.findByPk(seat.id);
|
const existingSeat = await this.findByPk(seat.id);
|
||||||
if (existingSeat) {
|
if (existingSeat) {
|
||||||
return Seat.update(seat, { where: { id: seat.id } });
|
return Seat.update(seat, { where: { id: seat.id } });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (insertIfNotFound) {
|
if (insertIfNotFound) {
|
||||||
return Seat.create(seat as any)
|
return Seat.create(seat as any)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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 { TheatreService } from './theatre.service';
|
||||||
import { Response } from 'express';
|
import { Response } from 'express';
|
||||||
import { GenericResponse } from '../common/GenericResponse.model';
|
import { GenericResponse } from '../common/GenericResponse.model';
|
||||||
import Theatre from './theatre.entity';
|
import Theatre from './theatre.entity';
|
||||||
import { ApiTags, ApiOperation, ApiResponse, ApiParam, ApiBody } from '@nestjs/swagger';
|
import { ApiTags, ApiOperation, ApiResponse, ApiParam, ApiBody } from '@nestjs/swagger';
|
||||||
|
import { TheatreDTO, TheatreUpdateDTO } from './theatre.dto';
|
||||||
|
|
||||||
@ApiTags('theatre')
|
@ApiTags('theatre')
|
||||||
@Controller('theatre')
|
@Controller('theatre')
|
||||||
@ -160,7 +161,7 @@ export class TheatreController {
|
|||||||
|
|
||||||
@Post()
|
@Post()
|
||||||
@ApiOperation({ summary: 'Insert a new theatre' })
|
@ApiOperation({ summary: 'Insert a new theatre' })
|
||||||
@ApiBody({ type: Theatre, description: 'Theatre data to insert' })
|
@ApiBody({ type: TheatreDTO, description: 'Theatre data to insert' })
|
||||||
@ApiResponse({
|
@ApiResponse({
|
||||||
status: 400,
|
status: 400,
|
||||||
description: 'Invalid theatre data',
|
description: 'Invalid theatre data',
|
||||||
@ -178,7 +179,8 @@ export class TheatreController {
|
|||||||
status: 201,
|
status: 201,
|
||||||
description: 'Successfully created a theatre',
|
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) {
|
if (!theatre) {
|
||||||
const response = new GenericResponse({
|
const response = new GenericResponse({
|
||||||
exception: true,
|
exception: true,
|
||||||
@ -188,7 +190,6 @@ export class TheatreController {
|
|||||||
}, null);
|
}, null);
|
||||||
return res.status(400).send(response);
|
return res.status(400).send(response);
|
||||||
}
|
}
|
||||||
delete theatre.id;
|
|
||||||
const response = await this.theatreService.upsert(theatre, true);
|
const response = await this.theatreService.upsert(theatre, true);
|
||||||
const httpResponse = new GenericResponse(null, response);
|
const httpResponse = new GenericResponse(null, response);
|
||||||
res.status(201).send(httpResponse);
|
res.status(201).send(httpResponse);
|
||||||
@ -196,7 +197,7 @@ export class TheatreController {
|
|||||||
|
|
||||||
@Put()
|
@Put()
|
||||||
@ApiOperation({ summary: 'Update an existing theatre' })
|
@ApiOperation({ summary: 'Update an existing theatre' })
|
||||||
@ApiBody({ type: Theatre, description: 'Theatre data to update' })
|
@ApiBody({ type: TheatreUpdateDTO, description: 'Theatre data to update' })
|
||||||
@ApiResponse({
|
@ApiResponse({
|
||||||
status: 400,
|
status: 400,
|
||||||
description: 'Invalid theatre data or ID missing',
|
description: 'Invalid theatre data or ID missing',
|
||||||
@ -227,7 +228,8 @@ export class TheatreController {
|
|||||||
status: 200,
|
status: 200,
|
||||||
description: 'Successfully updated theatre',
|
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) {
|
if (!theatre || !theatre.id) {
|
||||||
const response = new GenericResponse({
|
const response = new GenericResponse({
|
||||||
exception: true,
|
exception: true,
|
||||||
|
|||||||
@ -13,11 +13,7 @@ export class TheatreService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async findByPk(id: number): Promise<Theatre> {
|
async findByPk(id: number): Promise<Theatre> {
|
||||||
|
return Theatre.findByPk(id);
|
||||||
const theatre = Theatre.findByPk(id,)
|
|
||||||
// //const textbookExists = await this.checkTextbookExists((await theatre).textbookId);
|
|
||||||
|
|
||||||
return theatre
|
|
||||||
}
|
}
|
||||||
|
|
||||||
findOne(theatre: Theatre): Promise<Theatre> {
|
findOne(theatre: Theatre): Promise<Theatre> {
|
||||||
@ -32,7 +28,7 @@ export class TheatreService {
|
|||||||
return Theatre.destroy({ where: { id: id } });
|
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) {
|
if (theatre.id) {
|
||||||
const existingTheatre = await this.findByPk(theatre.id);
|
const existingTheatre = await this.findByPk(theatre.id);
|
||||||
if (existingTheatre) {
|
if (existingTheatre) {
|
||||||
@ -40,8 +36,6 @@ export class TheatreService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (insertIfNotFound) {
|
if (insertIfNotFound) {
|
||||||
//const textbookExists = await this.checkTextbookExists(theatre.textbookId);
|
|
||||||
|
|
||||||
return Theatre.create(theatre as any)
|
return Theatre.create(theatre as any)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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 { TheatreAdditionalDetailsService } from './theatreAdditionalDetails.service';
|
||||||
import { Response } from 'express';
|
import { Response } from 'express';
|
||||||
import { GenericResponse } from '../../common/GenericResponse.model';
|
import { GenericResponse } from '../../common/GenericResponse.model';
|
||||||
import TheatreAdditionalDetails from './theatreAdditionalDetails.entity';
|
import TheatreAdditionalDetails from './theatreAdditionalDetails.entity';
|
||||||
import { ApiTags, ApiOperation, ApiResponse, ApiParam, ApiBody } from '@nestjs/swagger';
|
import { ApiTags, ApiOperation, ApiResponse, ApiParam, ApiBody } from '@nestjs/swagger';
|
||||||
|
import { TheatreAdditionalDetailsDTO, TheatreAdditionalDetailsUpdateDTO } from './theatreAdditionalDetails.dto';
|
||||||
|
|
||||||
@ApiTags('theatreAdditionalDetails')
|
@ApiTags('theatreAdditionalDetails')
|
||||||
@Controller('theatreAdditionalDetails')
|
@Controller('theatreAdditionalDetails')
|
||||||
@ -160,7 +161,7 @@ export class TheatreAdditionalDetailsController {
|
|||||||
|
|
||||||
@Post()
|
@Post()
|
||||||
@ApiOperation({ summary: 'Insert a new theatreAdditionalDetails' })
|
@ApiOperation({ summary: 'Insert a new theatreAdditionalDetails' })
|
||||||
@ApiBody({ type: TheatreAdditionalDetails, description: 'TheatreAdditionalDetails data to insert' })
|
@ApiBody({ type: TheatreAdditionalDetailsDTO, description: 'TheatreAdditionalDetails data to insert' })
|
||||||
@ApiResponse({
|
@ApiResponse({
|
||||||
status: 400,
|
status: 400,
|
||||||
description: 'Invalid theatreAdditionalDetails data',
|
description: 'Invalid theatreAdditionalDetails data',
|
||||||
@ -178,7 +179,8 @@ export class TheatreAdditionalDetailsController {
|
|||||||
status: 201,
|
status: 201,
|
||||||
description: 'Successfully created a theatreAdditionalDetails',
|
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) {
|
if (!theatreAdditionalDetails) {
|
||||||
const response = new GenericResponse({
|
const response = new GenericResponse({
|
||||||
exception: true,
|
exception: true,
|
||||||
@ -188,7 +190,6 @@ export class TheatreAdditionalDetailsController {
|
|||||||
}, null);
|
}, null);
|
||||||
return res.status(400).send(response);
|
return res.status(400).send(response);
|
||||||
}
|
}
|
||||||
delete theatreAdditionalDetails.id;
|
|
||||||
const response = await this.theatreAdditionalDetailsService.upsert(theatreAdditionalDetails, true);
|
const response = await this.theatreAdditionalDetailsService.upsert(theatreAdditionalDetails, true);
|
||||||
const httpResponse = new GenericResponse(null, response);
|
const httpResponse = new GenericResponse(null, response);
|
||||||
res.status(201).send(httpResponse);
|
res.status(201).send(httpResponse);
|
||||||
@ -196,7 +197,7 @@ export class TheatreAdditionalDetailsController {
|
|||||||
|
|
||||||
@Put()
|
@Put()
|
||||||
@ApiOperation({ summary: 'Update an existing theatreAdditionalDetails' })
|
@ApiOperation({ summary: 'Update an existing theatreAdditionalDetails' })
|
||||||
@ApiBody({ type: TheatreAdditionalDetails, description: 'TheatreAdditionalDetails data to update' })
|
@ApiBody({ type: TheatreAdditionalDetailsUpdateDTO, description: 'TheatreAdditionalDetails data to update' })
|
||||||
@ApiResponse({
|
@ApiResponse({
|
||||||
status: 400,
|
status: 400,
|
||||||
description: 'Invalid theatreAdditionalDetails data or ID missing',
|
description: 'Invalid theatreAdditionalDetails data or ID missing',
|
||||||
@ -227,7 +228,8 @@ export class TheatreAdditionalDetailsController {
|
|||||||
status: 200,
|
status: 200,
|
||||||
description: 'Successfully updated theatreAdditionalDetails',
|
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) {
|
if (!theatreAdditionalDetails || !theatreAdditionalDetails.id) {
|
||||||
const response = new GenericResponse({
|
const response = new GenericResponse({
|
||||||
exception: true,
|
exception: true,
|
||||||
|
|||||||
@ -13,11 +13,7 @@ export class TheatreAdditionalDetailsService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async findByPk(id: number): Promise<TheatreAdditionalDetails> {
|
async findByPk(id: number): Promise<TheatreAdditionalDetails> {
|
||||||
|
return TheatreAdditionalDetails.findByPk(id);
|
||||||
const theatreAdditionalDetails = TheatreAdditionalDetails.findByPk(id,)
|
|
||||||
// //const textbookExists = await this.checkTextbookExists((await theatreAdditionalDetails).textbookId);
|
|
||||||
|
|
||||||
return theatreAdditionalDetails
|
|
||||||
}
|
}
|
||||||
|
|
||||||
findOne(theatreAdditionalDetails: TheatreAdditionalDetails): Promise<TheatreAdditionalDetails> {
|
findOne(theatreAdditionalDetails: TheatreAdditionalDetails): Promise<TheatreAdditionalDetails> {
|
||||||
@ -32,7 +28,7 @@ export class TheatreAdditionalDetailsService {
|
|||||||
return TheatreAdditionalDetails.destroy({ where: { id: id } });
|
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) {
|
if (theatreAdditionalDetails.id) {
|
||||||
const existingTheatreAdditionalDetails = await this.findByPk(theatreAdditionalDetails.id);
|
const existingTheatreAdditionalDetails = await this.findByPk(theatreAdditionalDetails.id);
|
||||||
if (existingTheatreAdditionalDetails) {
|
if (existingTheatreAdditionalDetails) {
|
||||||
@ -40,8 +36,6 @@ export class TheatreAdditionalDetailsService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (insertIfNotFound) {
|
if (insertIfNotFound) {
|
||||||
//const textbookExists = await this.checkTextbookExists(theatreAdditionalDetails.textbookId);
|
|
||||||
|
|
||||||
return TheatreAdditionalDetails.create(theatreAdditionalDetails as any)
|
return TheatreAdditionalDetails.create(theatreAdditionalDetails as any)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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 { TicketService } from './ticket.service';
|
||||||
import { Response } from 'express';
|
import { Response } from 'express';
|
||||||
import { GenericResponse } from '../common/GenericResponse.model';
|
import { GenericResponse } from '../common/GenericResponse.model';
|
||||||
import Ticket from './ticket.entity';
|
import Ticket from './ticket.entity';
|
||||||
import { ApiTags, ApiOperation, ApiResponse, ApiParam, ApiBody } from '@nestjs/swagger';
|
import { ApiTags, ApiOperation, ApiResponse, ApiParam, ApiBody } from '@nestjs/swagger';
|
||||||
|
import { TicketDTO, TicketUpdateDTO } from './ticket.dto';
|
||||||
|
|
||||||
@ApiTags('ticket')
|
@ApiTags('ticket')
|
||||||
@Controller('ticket')
|
@Controller('ticket')
|
||||||
@ -160,7 +161,7 @@ export class TicketController {
|
|||||||
|
|
||||||
@Post()
|
@Post()
|
||||||
@ApiOperation({ summary: 'Insert a new ticket' })
|
@ApiOperation({ summary: 'Insert a new ticket' })
|
||||||
@ApiBody({ type: Ticket, description: 'Ticket data to insert' })
|
@ApiBody({ type: TicketDTO, description: 'Ticket data to insert' })
|
||||||
@ApiResponse({
|
@ApiResponse({
|
||||||
status: 400,
|
status: 400,
|
||||||
description: 'Invalid ticket data',
|
description: 'Invalid ticket data',
|
||||||
@ -178,7 +179,8 @@ export class TicketController {
|
|||||||
status: 201,
|
status: 201,
|
||||||
description: 'Successfully created a ticket',
|
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) {
|
if (!ticket) {
|
||||||
const response = new GenericResponse({
|
const response = new GenericResponse({
|
||||||
exception: true,
|
exception: true,
|
||||||
@ -188,7 +190,6 @@ export class TicketController {
|
|||||||
}, null);
|
}, null);
|
||||||
return res.status(400).send(response);
|
return res.status(400).send(response);
|
||||||
}
|
}
|
||||||
delete ticket.id;
|
|
||||||
const response = await this.ticketService.upsert(ticket, true);
|
const response = await this.ticketService.upsert(ticket, true);
|
||||||
const httpResponse = new GenericResponse(null, response);
|
const httpResponse = new GenericResponse(null, response);
|
||||||
res.status(201).send(httpResponse);
|
res.status(201).send(httpResponse);
|
||||||
@ -196,7 +197,7 @@ export class TicketController {
|
|||||||
|
|
||||||
@Put()
|
@Put()
|
||||||
@ApiOperation({ summary: 'Update an existing ticket' })
|
@ApiOperation({ summary: 'Update an existing ticket' })
|
||||||
@ApiBody({ type: Ticket, description: 'Ticket data to update' })
|
@ApiBody({ type: TicketUpdateDTO, description: 'Ticket data to update' })
|
||||||
@ApiResponse({
|
@ApiResponse({
|
||||||
status: 400,
|
status: 400,
|
||||||
description: 'Invalid ticket data or ID missing',
|
description: 'Invalid ticket data or ID missing',
|
||||||
@ -227,7 +228,8 @@ export class TicketController {
|
|||||||
status: 200,
|
status: 200,
|
||||||
description: 'Successfully updated ticket',
|
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) {
|
if (!ticket || !ticket.id) {
|
||||||
const response = new GenericResponse({
|
const response = new GenericResponse({
|
||||||
exception: true,
|
exception: true,
|
||||||
|
|||||||
@ -13,11 +13,7 @@ export class TicketService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async findByPk(id: number): Promise<Ticket> {
|
async findByPk(id: number): Promise<Ticket> {
|
||||||
|
return Ticket.findByPk(id);
|
||||||
const ticket = Ticket.findByPk(id,)
|
|
||||||
// //const textbookExists = await this.checkTextbookExists((await ticket).textbookId);
|
|
||||||
|
|
||||||
return ticket
|
|
||||||
}
|
}
|
||||||
|
|
||||||
findOne(ticket: Ticket): Promise<Ticket> {
|
findOne(ticket: Ticket): Promise<Ticket> {
|
||||||
@ -32,7 +28,7 @@ export class TicketService {
|
|||||||
return Ticket.destroy({ where: { id: id } });
|
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) {
|
if (ticket.id) {
|
||||||
const existingTicket = await this.findByPk(ticket.id);
|
const existingTicket = await this.findByPk(ticket.id);
|
||||||
if (existingTicket) {
|
if (existingTicket) {
|
||||||
@ -40,14 +36,7 @@ export class TicketService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (insertIfNotFound) {
|
if (insertIfNotFound) {
|
||||||
//const textbookExists = await this.checkTextbookExists(ticket.textbookId);
|
|
||||||
|
|
||||||
return Ticket.create(ticket as any)
|
return Ticket.create(ticket as any)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// async assignTicketToUser(ticketId: number, userId: number): Promise<Ticket> {
|
|
||||||
// return Ticket.update({ userId: userId }, { where: { id: ticketId } });
|
|
||||||
// }
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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 { TicketPricingService } from './ticketPricing.service';
|
||||||
import { Response } from 'express';
|
import { Response } from 'express';
|
||||||
import { GenericResponse } from '../common/GenericResponse.model';
|
import { GenericResponse } from '../common/GenericResponse.model';
|
||||||
import TicketPricing from './ticketPricing.entity';
|
import TicketPricing from './ticketPricing.entity';
|
||||||
import { ApiTags, ApiOperation, ApiResponse, ApiParam, ApiBody } from '@nestjs/swagger';
|
import { ApiTags, ApiOperation, ApiResponse, ApiParam, ApiBody } from '@nestjs/swagger';
|
||||||
|
import { TicketPricingDTO, TicketPricingUpdateDTO } from './ticketPricing.dto';
|
||||||
|
|
||||||
@ApiTags('ticketPricing')
|
@ApiTags('ticketPricing')
|
||||||
@Controller('ticketPricing')
|
@Controller('ticketPricing')
|
||||||
@ -160,7 +161,7 @@ export class TicketPricingController {
|
|||||||
|
|
||||||
@Post()
|
@Post()
|
||||||
@ApiOperation({ summary: 'Insert a new ticketPricing' })
|
@ApiOperation({ summary: 'Insert a new ticketPricing' })
|
||||||
@ApiBody({ type: TicketPricing, description: 'TicketPricing data to insert' })
|
@ApiBody({ type: TicketPricingDTO, description: 'TicketPricing data to insert' })
|
||||||
@ApiResponse({
|
@ApiResponse({
|
||||||
status: 400,
|
status: 400,
|
||||||
description: 'Invalid ticketPricing data',
|
description: 'Invalid ticketPricing data',
|
||||||
@ -178,7 +179,8 @@ export class TicketPricingController {
|
|||||||
status: 201,
|
status: 201,
|
||||||
description: 'Successfully created a ticketPricing',
|
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) {
|
if (!ticketPricing) {
|
||||||
const response = new GenericResponse({
|
const response = new GenericResponse({
|
||||||
exception: true,
|
exception: true,
|
||||||
@ -188,7 +190,6 @@ export class TicketPricingController {
|
|||||||
}, null);
|
}, null);
|
||||||
return res.status(400).send(response);
|
return res.status(400).send(response);
|
||||||
}
|
}
|
||||||
delete ticketPricing.id;
|
|
||||||
const response = await this.ticketPricingService.upsert(ticketPricing, true);
|
const response = await this.ticketPricingService.upsert(ticketPricing, true);
|
||||||
const httpResponse = new GenericResponse(null, response);
|
const httpResponse = new GenericResponse(null, response);
|
||||||
res.status(201).send(httpResponse);
|
res.status(201).send(httpResponse);
|
||||||
@ -196,7 +197,7 @@ export class TicketPricingController {
|
|||||||
|
|
||||||
@Put()
|
@Put()
|
||||||
@ApiOperation({ summary: 'Update an existing ticketPricing' })
|
@ApiOperation({ summary: 'Update an existing ticketPricing' })
|
||||||
@ApiBody({ type: TicketPricing, description: 'TicketPricing data to update' })
|
@ApiBody({ type: TicketPricingUpdateDTO, description: 'TicketPricing data to update' })
|
||||||
@ApiResponse({
|
@ApiResponse({
|
||||||
status: 400,
|
status: 400,
|
||||||
description: 'Invalid ticketPricing data or ID missing',
|
description: 'Invalid ticketPricing data or ID missing',
|
||||||
@ -227,7 +228,8 @@ export class TicketPricingController {
|
|||||||
status: 200,
|
status: 200,
|
||||||
description: 'Successfully updated ticketPricing',
|
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) {
|
if (!ticketPricing || !ticketPricing.id) {
|
||||||
const response = new GenericResponse({
|
const response = new GenericResponse({
|
||||||
exception: true,
|
exception: true,
|
||||||
|
|||||||
@ -2,64 +2,71 @@ import { IsString, IsNumber, IsDate, IsOptional, IsNotEmpty } from 'class-valida
|
|||||||
import { ApiProperty } from '@nestjs/swagger';
|
import { ApiProperty } from '@nestjs/swagger';
|
||||||
import { Transform } from 'class-transformer';
|
import { Transform } from 'class-transformer';
|
||||||
|
|
||||||
export class TimeSlotDTO {
|
export class TicketPricingDTO {
|
||||||
|
|
||||||
@ApiProperty({ type: Number })
|
@ApiProperty({ type: Number })
|
||||||
@IsNumber()
|
@IsNumber()
|
||||||
@IsNotEmpty()
|
@IsNotEmpty()
|
||||||
eventId: number;
|
eventId: number;
|
||||||
|
|
||||||
@ApiProperty({ type: Date })
|
@ApiProperty({ type: Number })
|
||||||
@IsDate()
|
@IsOptional()
|
||||||
@IsNotEmpty()
|
@IsNumber()
|
||||||
@Transform(({ value }) => new Date(value))
|
timeSlotId: number;
|
||||||
startTime: Date;
|
|
||||||
|
|
||||||
@ApiProperty({ type: Date })
|
|
||||||
@IsDate()
|
|
||||||
@IsNotEmpty()
|
|
||||||
@Transform(({ value }) => new Date(value))
|
|
||||||
endTime: Date;
|
|
||||||
|
|
||||||
@ApiProperty({ type: String })
|
@ApiProperty({ type: String })
|
||||||
@IsString()
|
@IsString()
|
||||||
@IsNotEmpty()
|
@IsNotEmpty()
|
||||||
|
ticketType: string;
|
||||||
|
|
||||||
|
@ApiProperty({ type: Number })
|
||||||
|
@IsNumber()
|
||||||
|
@IsNotEmpty()
|
||||||
|
price: number;
|
||||||
|
|
||||||
|
@ApiProperty({ type: String })
|
||||||
|
@IsString()
|
||||||
|
@IsOptional()
|
||||||
status: string;
|
status: string;
|
||||||
|
|
||||||
@ApiProperty({ type: Date })
|
@ApiProperty({ type: Date })
|
||||||
@IsDate()
|
@IsDate()
|
||||||
@IsNotEmpty()
|
@IsOptional()
|
||||||
@Transform(({ value }) => new Date(value))
|
@Transform(({ value }) => new Date(value))
|
||||||
validFrom: Date;
|
validFrom: Date;
|
||||||
|
|
||||||
@ApiProperty({ type: Date })
|
@ApiProperty({ type: Date })
|
||||||
@IsDate()
|
@IsDate()
|
||||||
@IsNotEmpty()
|
@IsOptional()
|
||||||
@Transform(({ value }) => new Date(value))
|
@Transform(({ value }) => new Date(value))
|
||||||
validTill: Date;
|
validTill: Date;
|
||||||
|
|
||||||
@ApiProperty({ type: Date })
|
@ApiProperty({ type: Date })
|
||||||
@IsDate()
|
@IsDate()
|
||||||
@Transform(({ value }) => new Date(value))
|
@IsOptional()
|
||||||
|
@Transform(({ value }) => new Date(value))
|
||||||
createdAt: Date;
|
createdAt: Date;
|
||||||
|
|
||||||
@ApiProperty({ type: Date })
|
@ApiProperty({ type: Date })
|
||||||
@IsDate()
|
@IsDate()
|
||||||
@Transform(({ value }) => new Date(value))
|
@IsOptional()
|
||||||
|
@Transform(({ value }) => new Date(value))
|
||||||
updatedAt: Date;
|
updatedAt: Date;
|
||||||
|
|
||||||
@ApiProperty({ type: String })
|
@ApiProperty({ type: String })
|
||||||
@IsString()
|
@IsString()
|
||||||
|
@IsOptional()
|
||||||
createdBy: string;
|
createdBy: string;
|
||||||
|
|
||||||
@ApiProperty({ type: String })
|
@ApiProperty({ type: String })
|
||||||
@IsString()
|
@IsString()
|
||||||
|
@IsOptional()
|
||||||
modifiedBy: string;
|
modifiedBy: string;
|
||||||
|
|
||||||
@ApiProperty({ type: Date })
|
@ApiProperty({ type: Date })
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsDate()
|
@IsDate()
|
||||||
@Transform(({ value }) => value ? new Date(value) : null)
|
@Transform(({ value }) => value ? new Date(value) : null)
|
||||||
deletedAt: Date;
|
deletedAt: Date;
|
||||||
|
|
||||||
@ApiProperty({ type: Number })
|
@ApiProperty({ type: Number })
|
||||||
@ -68,9 +75,9 @@ export class TimeSlotDTO {
|
|||||||
version: number;
|
version: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class TimeSlotUpdateDTO extends TimeSlotDTO {
|
export class TicketPricingUpdateDTO extends TicketPricingDTO {
|
||||||
@ApiProperty({ type: Number })
|
@ApiProperty({ type: Number })
|
||||||
@IsNumber()
|
@IsNumber()
|
||||||
@IsNotEmpty()
|
@IsNotEmpty()
|
||||||
id: number
|
id: number;
|
||||||
}
|
}
|
||||||
@ -13,11 +13,7 @@ export class TicketPricingService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async findByPk(id: number): Promise<TicketPricing> {
|
async findByPk(id: number): Promise<TicketPricing> {
|
||||||
|
return TicketPricing.findByPk(id);
|
||||||
const ticketPricing = TicketPricing.findByPk(id,)
|
|
||||||
// //const textbookExists = await this.checkTextbookExists((await ticketPricing).textbookId);
|
|
||||||
|
|
||||||
return ticketPricing
|
|
||||||
}
|
}
|
||||||
|
|
||||||
findOne(ticketPricing: TicketPricing): Promise<TicketPricing> {
|
findOne(ticketPricing: TicketPricing): Promise<TicketPricing> {
|
||||||
@ -32,7 +28,7 @@ export class TicketPricingService {
|
|||||||
return TicketPricing.destroy({ where: { id: id } });
|
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) {
|
if (ticketPricing.id) {
|
||||||
const existingTicketPricing = await this.findByPk(ticketPricing.id);
|
const existingTicketPricing = await this.findByPk(ticketPricing.id);
|
||||||
if (existingTicketPricing) {
|
if (existingTicketPricing) {
|
||||||
@ -40,8 +36,6 @@ export class TicketPricingService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (insertIfNotFound) {
|
if (insertIfNotFound) {
|
||||||
//const textbookExists = await this.checkTextbookExists(ticketPricing.textbookId);
|
|
||||||
|
|
||||||
return TicketPricing.create(ticketPricing as any)
|
return TicketPricing.create(ticketPricing as any)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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 { TimeSlotService } from './timeSlot.service';
|
||||||
import { Response } from 'express';
|
import { Response } from 'express';
|
||||||
import { GenericResponse } from '../common/GenericResponse.model';
|
import { GenericResponse } from '../common/GenericResponse.model';
|
||||||
import TimeSlot from './timeSlot.entity';
|
import TimeSlot from './timeSlot.entity';
|
||||||
import { ApiTags, ApiOperation, ApiResponse, ApiParam, ApiBody } from '@nestjs/swagger';
|
import { ApiTags, ApiOperation, ApiResponse, ApiParam, ApiBody } from '@nestjs/swagger';
|
||||||
|
import { TimeSlotDTO, TimeSlotUpdateDTO } from './timeSlot.dto';
|
||||||
|
|
||||||
@ApiTags('timeSlot')
|
@ApiTags('timeSlot')
|
||||||
@Controller('timeSlot')
|
@Controller('timeSlot')
|
||||||
export class TimeSlotController {
|
export class TimeSlotController {
|
||||||
constructor(private timeSlotService: TimeSlotService) {}
|
constructor(private timeSlotService: TimeSlotService) { }
|
||||||
|
|
||||||
@Get("/all")
|
@Get("/all")
|
||||||
@ApiOperation({ summary: 'Get all timeSlots' })
|
@ApiOperation({ summary: 'Get all timeSlots' })
|
||||||
@ -31,7 +32,7 @@ export class TimeSlotController {
|
|||||||
})
|
})
|
||||||
async getAllTimeSlots(@Res() res: Response) {
|
async getAllTimeSlots(@Res() res: Response) {
|
||||||
const response = await this.timeSlotService.findAll() || [];
|
const response = await this.timeSlotService.findAll() || [];
|
||||||
if(!response) {
|
if (!response) {
|
||||||
const errorResponse = new GenericResponse({
|
const errorResponse = new GenericResponse({
|
||||||
exception: true,
|
exception: true,
|
||||||
exceptionSeverity: 'HIGH',
|
exceptionSeverity: 'HIGH',
|
||||||
@ -160,7 +161,7 @@ export class TimeSlotController {
|
|||||||
|
|
||||||
@Post()
|
@Post()
|
||||||
@ApiOperation({ summary: 'Insert a new timeSlot' })
|
@ApiOperation({ summary: 'Insert a new timeSlot' })
|
||||||
@ApiBody({ type: TimeSlot, description: 'TimeSlot data to insert' })
|
@ApiBody({ type: TimeSlotDTO, description: 'TimeSlot data to insert' })
|
||||||
@ApiResponse({
|
@ApiResponse({
|
||||||
status: 400,
|
status: 400,
|
||||||
description: 'Invalid timeSlot data',
|
description: 'Invalid timeSlot data',
|
||||||
@ -178,7 +179,8 @@ export class TimeSlotController {
|
|||||||
status: 201,
|
status: 201,
|
||||||
description: 'Successfully created a timeSlot',
|
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) {
|
if (!timeSlot) {
|
||||||
const response = new GenericResponse({
|
const response = new GenericResponse({
|
||||||
exception: true,
|
exception: true,
|
||||||
@ -188,7 +190,6 @@ export class TimeSlotController {
|
|||||||
}, null);
|
}, null);
|
||||||
return res.status(400).send(response);
|
return res.status(400).send(response);
|
||||||
}
|
}
|
||||||
delete timeSlot.id;
|
|
||||||
const response = await this.timeSlotService.upsert(timeSlot, true);
|
const response = await this.timeSlotService.upsert(timeSlot, true);
|
||||||
const httpResponse = new GenericResponse(null, response);
|
const httpResponse = new GenericResponse(null, response);
|
||||||
res.status(201).send(httpResponse);
|
res.status(201).send(httpResponse);
|
||||||
@ -196,7 +197,7 @@ export class TimeSlotController {
|
|||||||
|
|
||||||
@Put()
|
@Put()
|
||||||
@ApiOperation({ summary: 'Update an existing timeSlot' })
|
@ApiOperation({ summary: 'Update an existing timeSlot' })
|
||||||
@ApiBody({ type: TimeSlot, description: 'TimeSlot data to update' })
|
@ApiBody({ type: TimeSlotUpdateDTO, description: 'TimeSlot data to update' })
|
||||||
@ApiResponse({
|
@ApiResponse({
|
||||||
status: 400,
|
status: 400,
|
||||||
description: 'Invalid timeSlot data or ID missing',
|
description: 'Invalid timeSlot data or ID missing',
|
||||||
@ -227,7 +228,8 @@ export class TimeSlotController {
|
|||||||
status: 200,
|
status: 200,
|
||||||
description: 'Successfully updated timeSlot',
|
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) {
|
if (!timeSlot || !timeSlot.id) {
|
||||||
const response = new GenericResponse({
|
const response = new GenericResponse({
|
||||||
exception: true,
|
exception: true,
|
||||||
|
|||||||
@ -13,10 +13,7 @@ export class TimeSlotService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async findByPk(id: number): Promise<TimeSlot> {
|
async findByPk(id: number): Promise<TimeSlot> {
|
||||||
|
return TimeSlot.findByPk(id);
|
||||||
const timeSlot = TimeSlot.findByPk(id,)
|
|
||||||
|
|
||||||
return timeSlot
|
|
||||||
}
|
}
|
||||||
|
|
||||||
findOne(timeSlot: TimeSlot): Promise<TimeSlot> {
|
findOne(timeSlot: TimeSlot): Promise<TimeSlot> {
|
||||||
@ -31,7 +28,7 @@ export class TimeSlotService {
|
|||||||
return TimeSlot.destroy({ where: { id: id } });
|
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) {
|
if (timeSlot.id) {
|
||||||
const existingTimeSlot = await this.findByPk(timeSlot.id);
|
const existingTimeSlot = await this.findByPk(timeSlot.id);
|
||||||
if (existingTimeSlot) {
|
if (existingTimeSlot) {
|
||||||
@ -39,7 +36,6 @@ export class TimeSlotService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (insertIfNotFound) {
|
if (insertIfNotFound) {
|
||||||
|
|
||||||
return TimeSlot.create(timeSlot as any)
|
return TimeSlot.create(timeSlot as any)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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 { UserWatchlistService } from './user-watchlist.service';
|
import { UserWatchlistService } from './user-watchlist.service';
|
||||||
import { Response } from 'express';
|
import { Response } from 'express';
|
||||||
import { GenericResponse } from '../common/GenericResponse.model';
|
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 { ApiTags, ApiOperation, ApiResponse, ApiParam, ApiBody } from '@nestjs/swagger';
|
||||||
|
import { UserWatchlistDTO, UserWatchlistUpdateDTO } from './user-watchlist.dto';
|
||||||
|
|
||||||
@ApiTags('user-watchlist')
|
@ApiTags('user-watchlist')
|
||||||
@Controller('user-watchlist')
|
@Controller('user-watchlist')
|
||||||
export class UserWatchlistController {
|
export class UserWatchlistController {
|
||||||
constructor(private userWatchlistService: UserWatchlistService) {}
|
constructor(private userWatchlistService: UserWatchlistService) { }
|
||||||
|
|
||||||
@Get("/all")
|
@Get("/all")
|
||||||
@ApiOperation({ summary: 'Get all user watchlists' })
|
@ApiOperation({ summary: 'Get all user watchlists' })
|
||||||
@ -160,7 +161,7 @@ export class UserWatchlistController {
|
|||||||
|
|
||||||
@Post()
|
@Post()
|
||||||
@ApiOperation({ summary: 'Insert a new user watchlist' })
|
@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({
|
@ApiResponse({
|
||||||
status: 400,
|
status: 400,
|
||||||
description: 'Invalid user watchlist data',
|
description: 'Invalid user watchlist data',
|
||||||
@ -178,7 +179,8 @@ export class UserWatchlistController {
|
|||||||
status: 201,
|
status: 201,
|
||||||
description: 'Successfully created a user watchlist',
|
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) {
|
if (!userWatchlist) {
|
||||||
const response = new GenericResponse({
|
const response = new GenericResponse({
|
||||||
exception: true,
|
exception: true,
|
||||||
@ -188,7 +190,6 @@ export class UserWatchlistController {
|
|||||||
}, null);
|
}, null);
|
||||||
return res.status(400).send(response);
|
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 response = await this.userWatchlistService.upsert(userWatchlist, true);
|
||||||
const httpResponse = new GenericResponse(null, response);
|
const httpResponse = new GenericResponse(null, response);
|
||||||
res.status(201).send(httpResponse);
|
res.status(201).send(httpResponse);
|
||||||
@ -196,7 +197,7 @@ export class UserWatchlistController {
|
|||||||
|
|
||||||
@Put()
|
@Put()
|
||||||
@ApiOperation({ summary: 'Update an existing user watchlist' })
|
@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({
|
@ApiResponse({
|
||||||
status: 400,
|
status: 400,
|
||||||
description: 'Invalid user watchlist data or ID missing',
|
description: 'Invalid user watchlist data or ID missing',
|
||||||
@ -227,7 +228,8 @@ export class UserWatchlistController {
|
|||||||
status: 200,
|
status: 200,
|
||||||
description: 'Successfully updated user watchlist',
|
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) {
|
if (!userWatchlist || !userWatchlist.id) {
|
||||||
const response = new GenericResponse({
|
const response = new GenericResponse({
|
||||||
exception: true,
|
exception: true,
|
||||||
|
|||||||
@ -27,7 +27,7 @@ export class UserWatchlistService {
|
|||||||
return UserWatchlist.destroy({ where: { id: id } });
|
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) {
|
if (userWatchlist.id) {
|
||||||
const existingUserWatchlist = await this.findByPk(userWatchlist.id);
|
const existingUserWatchlist = await this.findByPk(userWatchlist.id);
|
||||||
if (existingUserWatchlist) {
|
if (existingUserWatchlist) {
|
||||||
|
|||||||
@ -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 { Response } from 'express';
|
||||||
import { UserAdditionalDetailsService } from './user-additional-details.service';
|
import { UserAdditionalDetailsService } from './user-additional-details.service';
|
||||||
import { GenericResponse } from 'src/common/GenericResponse.model';
|
import { GenericResponse } from 'src/common/GenericResponse.model';
|
||||||
import UserAdditionalDetail from './user-additional-details.entity';
|
import UserAdditionalDetail from './user-additional-details.entity';
|
||||||
import { ApiTags, ApiOperation, ApiResponse, ApiParam, ApiBody } from '@nestjs/swagger';
|
import { ApiTags, ApiOperation, ApiResponse, ApiParam, ApiBody } from '@nestjs/swagger';
|
||||||
|
import { UserAdditionalDetailDTO, UserAdditionalDetailUpdateDTO } from './user-additional-details.dto';
|
||||||
|
|
||||||
@ApiTags('user-additional-details')
|
@ApiTags('user-additional-details')
|
||||||
@Controller('users/addl/')
|
@Controller('users/addl/')
|
||||||
@ -163,7 +164,7 @@ export class UserAdditionalDetailsController {
|
|||||||
|
|
||||||
@Post()
|
@Post()
|
||||||
@ApiOperation({ summary: 'Insert a new user additional detail' })
|
@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({
|
@ApiResponse({
|
||||||
status: 400,
|
status: 400,
|
||||||
description: 'Failed to insert user additional detail',
|
description: 'Failed to insert user additional detail',
|
||||||
@ -194,7 +195,8 @@ export class UserAdditionalDetailsController {
|
|||||||
status: 201,
|
status: 201,
|
||||||
description: 'User additional detail successfully created',
|
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) {
|
if (!user) {
|
||||||
const response = new GenericResponse({
|
const response = new GenericResponse({
|
||||||
exception: true,
|
exception: true,
|
||||||
@ -205,7 +207,6 @@ export class UserAdditionalDetailsController {
|
|||||||
res.status(400).send(response);
|
res.status(400).send(response);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
delete user.id;
|
|
||||||
const response = await this.userAdditionalDetailsService.upsert(user, true);
|
const response = await this.userAdditionalDetailsService.upsert(user, true);
|
||||||
if (!response) {
|
if (!response) {
|
||||||
const response = new GenericResponse({
|
const response = new GenericResponse({
|
||||||
@ -223,7 +224,7 @@ export class UserAdditionalDetailsController {
|
|||||||
|
|
||||||
@Put()
|
@Put()
|
||||||
@ApiOperation({ summary: 'Update an existing user additional detail' })
|
@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({
|
@ApiResponse({
|
||||||
status: 400,
|
status: 400,
|
||||||
description: 'Failed to update user additional detail',
|
description: 'Failed to update user additional detail',
|
||||||
@ -254,7 +255,8 @@ export class UserAdditionalDetailsController {
|
|||||||
status: 200,
|
status: 200,
|
||||||
description: 'User additional detail successfully updated',
|
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) {
|
if (!user || !user.id) {
|
||||||
const response = new GenericResponse({
|
const response = new GenericResponse({
|
||||||
exception: true,
|
exception: true,
|
||||||
|
|||||||
@ -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;
|
||||||
|
}
|
||||||
@ -23,7 +23,7 @@ export class UserAdditionalDetailsService {
|
|||||||
return UserAdditionalDetail.destroy({where: {id: id}});
|
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) {
|
if(userDetail.id) {
|
||||||
const existingUser = await this.findByPk(userDetail.id);
|
const existingUser = await this.findByPk(userDetail.id);
|
||||||
if(existingUser) {
|
if(existingUser) {
|
||||||
|
|||||||
@ -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 { Response } from 'express';
|
||||||
import { GenericResponse } from 'src/common/GenericResponse.model';
|
import { GenericResponse } from 'src/common/GenericResponse.model';
|
||||||
import UserType from './user-type.entity';
|
import UserType from './user-type.entity';
|
||||||
import { UserTypesService } from './user-types.service';
|
import { UserTypesService } from './user-types.service';
|
||||||
import { ApiTags, ApiOperation, ApiResponse, ApiParam, ApiBody } from '@nestjs/swagger';
|
import { ApiTags, ApiOperation, ApiResponse, ApiParam, ApiBody } from '@nestjs/swagger';
|
||||||
|
import { UserTypeDTO, UserTypeUpdateDTO } from './user-type.dto';
|
||||||
|
|
||||||
@ApiTags('user-types')
|
@ApiTags('user-types')
|
||||||
@Controller('users/types')
|
@Controller('users/types')
|
||||||
@ -150,7 +151,7 @@ export class UserTypesController {
|
|||||||
|
|
||||||
@Post()
|
@Post()
|
||||||
@ApiOperation({ summary: 'Insert a new user type' })
|
@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({
|
@ApiResponse({
|
||||||
status: 400,
|
status: 400,
|
||||||
description: 'Failed to insert user type',
|
description: 'Failed to insert user type',
|
||||||
@ -168,7 +169,8 @@ export class UserTypesController {
|
|||||||
status: 201,
|
status: 201,
|
||||||
description: 'User type successfully created',
|
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) {
|
if (!user) {
|
||||||
const response = new GenericResponse({
|
const response = new GenericResponse({
|
||||||
exception: true,
|
exception: true,
|
||||||
@ -179,7 +181,6 @@ export class UserTypesController {
|
|||||||
res.status(400).send(response);
|
res.status(400).send(response);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
delete user.id;
|
|
||||||
const response = await this.userTypeService.upsert(user, true);
|
const response = await this.userTypeService.upsert(user, true);
|
||||||
if (!response) {
|
if (!response) {
|
||||||
const errorResponse = new GenericResponse({
|
const errorResponse = new GenericResponse({
|
||||||
@ -196,7 +197,7 @@ export class UserTypesController {
|
|||||||
|
|
||||||
@Put()
|
@Put()
|
||||||
@ApiOperation({ summary: 'Update an existing user type' })
|
@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({
|
@ApiResponse({
|
||||||
status: 400,
|
status: 400,
|
||||||
description: 'Failed to update user type',
|
description: 'Failed to update user type',
|
||||||
@ -227,7 +228,8 @@ export class UserTypesController {
|
|||||||
status: 200,
|
status: 200,
|
||||||
description: 'User type successfully updated',
|
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) {
|
if (!user || !user.id) {
|
||||||
const response = new GenericResponse({
|
const response = new GenericResponse({
|
||||||
exception: true,
|
exception: true,
|
||||||
@ -297,7 +299,7 @@ export class UserTypesController {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const response = await this.userTypeService.remove(id) || {};
|
const response = await this.userTypeService.remove(id) || {};
|
||||||
if(!response){
|
if (!response) {
|
||||||
const errorResponse = new GenericResponse({
|
const errorResponse = new GenericResponse({
|
||||||
exception: true,
|
exception: true,
|
||||||
exceptionSeverity: 'HIGH',
|
exceptionSeverity: 'HIGH',
|
||||||
|
|||||||
78
src/user/user-types/user-type.dto.ts
Normal file
78
src/user/user-types/user-type.dto.ts
Normal 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;
|
||||||
|
}
|
||||||
@ -25,7 +25,7 @@ export class UserTypesService {
|
|||||||
return UserType.destroy({where: {id: id}});
|
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) {
|
if(userDetail.id) {
|
||||||
const existingUser = await this.findByPk(userDetail.id);
|
const existingUser = await this.findByPk(userDetail.id);
|
||||||
if(existingUser) {
|
if(existingUser) {
|
||||||
|
|||||||
@ -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 { UserService } from './user.service';
|
||||||
import { Response } from 'express';
|
import { Response } from 'express';
|
||||||
import { GenericResponse } from '../common/GenericResponse.model';
|
import { GenericResponse } from '../common/GenericResponse.model';
|
||||||
import { User } from './user.entity';
|
import { User } from './user.entity';
|
||||||
import { ApiTags, ApiOperation, ApiResponse, ApiParam, ApiBody } from '@nestjs/swagger';
|
import { ApiTags, ApiOperation, ApiResponse, ApiParam, ApiBody } from '@nestjs/swagger';
|
||||||
|
import { UserDTO, UserUpdateDTO } from './user.dto';
|
||||||
|
|
||||||
@ApiTags('users')
|
@ApiTags('users')
|
||||||
@Controller('users')
|
@Controller('users')
|
||||||
@ -160,7 +161,7 @@ export class UserController {
|
|||||||
|
|
||||||
@Post()
|
@Post()
|
||||||
@ApiOperation({ summary: 'Insert a new user' })
|
@ApiOperation({ summary: 'Insert a new user' })
|
||||||
@ApiBody({ type: User, description: 'User data to insert' })
|
@ApiBody({ type: UserDTO, description: 'User data to insert' })
|
||||||
@ApiResponse({
|
@ApiResponse({
|
||||||
status: 400,
|
status: 400,
|
||||||
description: 'Failed to insert user',
|
description: 'Failed to insert user',
|
||||||
@ -179,7 +180,8 @@ export class UserController {
|
|||||||
status: 201,
|
status: 201,
|
||||||
description: 'User successfully created',
|
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) {
|
if (!user) {
|
||||||
const response = new GenericResponse({
|
const response = new GenericResponse({
|
||||||
exception: true,
|
exception: true,
|
||||||
@ -189,7 +191,6 @@ export class UserController {
|
|||||||
}, null);
|
}, null);
|
||||||
return res.status(400).send(response);
|
return res.status(400).send(response);
|
||||||
}
|
}
|
||||||
delete user.id;
|
|
||||||
if (user.password) {
|
if (user.password) {
|
||||||
user.password = this.encryptPassword(user.password);
|
user.password = this.encryptPassword(user.password);
|
||||||
}
|
}
|
||||||
@ -209,7 +210,7 @@ export class UserController {
|
|||||||
|
|
||||||
@Put()
|
@Put()
|
||||||
@ApiOperation({ summary: 'Update an existing user' })
|
@ApiOperation({ summary: 'Update an existing user' })
|
||||||
@ApiBody({ type: User, description: 'User data to update' })
|
@ApiBody({ type: UserUpdateDTO, description: 'User data to update' })
|
||||||
@ApiResponse({
|
@ApiResponse({
|
||||||
status: 400,
|
status: 400,
|
||||||
description: 'Failed to update user',
|
description: 'Failed to update user',
|
||||||
@ -240,7 +241,8 @@ export class UserController {
|
|||||||
status: 200,
|
status: 200,
|
||||||
description: 'User successfully updated',
|
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) {
|
if (!user || !user.id) {
|
||||||
const response = new GenericResponse({
|
const response = new GenericResponse({
|
||||||
exception: true,
|
exception: true,
|
||||||
|
|||||||
@ -30,7 +30,7 @@ export class UserService {
|
|||||||
return User.destroy({where: {id: id}});
|
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) {
|
if(userDetail.id) {
|
||||||
const existingUser = await this.findByPk(userDetail.id);
|
const existingUser = await this.findByPk(userDetail.id);
|
||||||
if(existingUser) {
|
if(existingUser) {
|
||||||
@ -41,8 +41,4 @@ export class UserService {
|
|||||||
return User.create(userDetail as any)
|
return User.create(userDetail as any)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async login(user: User): Promise<User> {
|
|
||||||
return User.findOne({where: user as any, include: UserAdditionalDetail})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user