Skip to content

Commit

Permalink
Merge pull request #51 from Xitija/main2
Browse files Browse the repository at this point in the history
chore : made userId optional for event list api
  • Loading branch information
snehal0904 authored Nov 11, 2024
2 parents 99c4d02 + 24c85a2 commit 8a0af0d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/common/utils/constants.util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`,
Expand Down
17 changes: 11 additions & 6 deletions src/modules/event/event.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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);
Expand All @@ -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,
})
Expand All @@ -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,
Expand All @@ -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);
}
Expand Down

0 comments on commit 8a0af0d

Please sign in to comment.