diff --git a/src/common/utils/constants.util.ts b/src/common/utils/constants.util.ts index 68d7b54..3fbfb1b 100644 --- a/src/common/utils/constants.util.ts +++ b/src/common/utils/constants.util.ts @@ -88,7 +88,7 @@ export const ERROR_MESSAGES = { 'End condition by occurrences is not implemented yet', EVENT_TYPE_CHANGE_NOT_SUPPORTED: 'Event type change not supported', USERID_INVALID: 'Invalid UserId', - PROVIDE_ONE_USERID_IN_QUERY: 'Please provide only one userid in query', + PROVIDE_ONE_USERID_IN_QUERY: 'Please provide userId in query params', API_REQ_FAILURE: (url: string) => `Error occurred on API Request: ${url}`, DB_QUERY_FAILURE: (url: string) => `Database Query Failed on API: ${url}`, API_FAILURE: (url: string) => `API Failure: ${url}`, diff --git a/src/modules/event/event.controller.ts b/src/modules/event/event.controller.ts index 6dcb84e..ce05121 100644 --- a/src/modules/event/event.controller.ts +++ b/src/modules/event/event.controller.ts @@ -53,7 +53,7 @@ export class EventController { @UseFilters(new AllExceptionsFilter(API_ID.CREATE_EVENT)) @Post('/create') @ApiBody({ type: CreateEventDto }) - @ApiQuery({ name: 'userid', required: true }) + @ApiQuery({ name: 'userId', required: true }) @UsePipes( new ValidationPipe({ transform: true }), new DateValidationPipe(), @@ -73,7 +73,7 @@ export class EventController { @Res() response: Response, @Req() request: Request, ) { - const userId: string = checkValidUserId(request.query.userid); + const userId: string = checkValidUserId(request.query?.userId); createEventDto.createdBy = userId; createEventDto.updatedBy = userId; return this.eventService.createEvent(createEventDto, response); @@ -82,7 +82,7 @@ export class EventController { @UseFilters(new AllExceptionsFilter(API_ID.GET_EVENTS)) @Post('/list') @ApiBody({ type: SearchFilterDto }) - @ApiQuery({ name: 'userid', required: true }) + @ApiQuery({ name: 'userId', required: true }) @ApiInternalServerErrorResponse({ description: ERROR_MESSAGES.INTERNAL_SERVER_ERROR, }) @@ -99,14 +99,19 @@ export class EventController { @Res() response: Response, @Req() request: Request, ) { - const userId: string = checkValidUserId(request.query.userid); + let userId: string; + if (!request.query?.userId) { + userId = null; + } else { + userId = checkValidUserId(request.query?.userId); + } return this.eventService.getEvents(response, requestBody, userId); } @UseFilters(new AllExceptionsFilter(API_ID.UPDATE_EVENT)) @Patch('/:id') @ApiBody({ type: UpdateEventDto }) - @ApiQuery({ name: 'userid', required: true }) + @ApiQuery({ name: 'userId', required: true }) @ApiResponse({ status: 200, description: SUCCESS_MESSAGES.EVENT_UPDATED }) @ApiInternalServerErrorResponse({ description: ERROR_MESSAGES.INTERNAL_SERVER_ERROR, @@ -121,7 +126,7 @@ export class EventController { if (!updateEventDto || Object.keys(updateEventDto).length === 0) { throw new BadRequestException(ERROR_MESSAGES.INVALID_REQUEST_BODY); } - const userId: string = checkValidUserId(request.query.userid); + const userId: string = checkValidUserId(request.query?.userId); updateEventDto.updatedBy = userId; return this.eventService.updateEvent(id, updateEventDto, response); }