Skip to content

Commit

Permalink
Merge pull request #42 from Xitija/create-api-changes
Browse files Browse the repository at this point in the history
PS - 1832 New events not updated when pattern and other detail change in combination
  • Loading branch information
snehal0904 authored Sep 18, 2024
2 parents b62608e + c41e927 commit 64d1783
Show file tree
Hide file tree
Showing 4 changed files with 295 additions and 250 deletions.
33 changes: 16 additions & 17 deletions src/common/pipes/event-validation.pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,13 @@ import { UpdateEventDto } from 'src/modules/event/dto/update-event.dto';
@Injectable()
export class DateValidationPipe implements PipeTransform {
transform(createEventDto: CreateEventDto | UpdateEventDto) {
console.log(
createEventDto,
'createEventDto',
createEventDto.startDatetime,
createEventDto.endDatetime,
);
const eventStartDate = createEventDto.startDatetime.split('T')[0];
const eventEndDate = createEventDto.endDatetime.split('T')[0];

const startDate = new Date(createEventDto.startDatetime);
const endDate = new Date(createEventDto.endDatetime);
const currentDate = new Date();

console.log(
startDate,
'start',
endDate,
'end',
currentDate,
createEventDto.isRecurring,
);
if (eventStartDate !== eventEndDate && createEventDto.isRecurring) {
throw new BadRequestException(
ERROR_MESSAGES.MULTIDAY_EVENT_NOT_RECURRING,
Expand Down Expand Up @@ -123,6 +109,8 @@ export class RecurringEndDateValidationPipe implements PipeTransform {
createEventDto.recurrencePattern?.endCondition?.value;
const endConditionType =
createEventDto.recurrencePattern?.endCondition?.type;
const recurringStartDate =
createEventDto.recurrencePattern.recurringStartDate;

if (!endConditionType || !endConditionValue) {
throw new BadRequestException(
Expand All @@ -142,7 +130,6 @@ export class RecurringEndDateValidationPipe implements PipeTransform {
);
}

const startDate = new Date(createEventDto.startDatetime);
const currentDate = new Date();
if (recurrenceEndDate < currentDate) {
throw new BadRequestException(
Expand All @@ -151,17 +138,18 @@ export class RecurringEndDateValidationPipe implements PipeTransform {
}

if (
recurrenceEndDate <= startDate &&
recurrenceEndDate <= new Date(createEventDto.startDatetime) &&
createEventDto instanceof CreateEventDto
) {
console.log('recurrenceEndDate', recurrenceEndDate);
throw new BadRequestException(
ERROR_MESSAGES.RECURRENCE_END_DATE_AFTER_EVENT_DATE,
);
}

const endDateTime = endConditionValue.split('T');
const endDate = endDateTime[0]; // recurring end date
const startDateTime = recurringStartDate.split('T');
const startDate = startDateTime[0];

if (
new Date(endConditionValue).getTime() !==
Expand All @@ -174,6 +162,17 @@ export class RecurringEndDateValidationPipe implements PipeTransform {
);
}

if (
new Date(recurringStartDate).getTime() !==
new Date(
startDate + 'T' + createEventDto.startDatetime.split('T')[1],
).getTime()
) {
throw new BadRequestException(
'Event Start time does not match with Recurrence Start time',
);
}

// createEventDto.recurrencePattern.endCondition.value = endDate;
} else if (endConditionType === EndConditionType.occurrences) {
const occurrences = Number(endConditionValue);
Expand Down
22 changes: 22 additions & 0 deletions src/common/utils/constants.util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,28 @@ export const ERROR_MESSAGES = {
EVENT_ATTENDEE_HISTORY_NOT_FOUND: 'Event attendee history not found',
EVENT_ATTENDEE_HISTORY_ITEM_NOT_FOUND:
'Event attendee history item not found',
RECURRENCE_START_DATE_IN_FUTURE: 'Recurrence start date must be in future',
END_DATE_CANNOT_CHANGE:
'End Date cannot be changed because it is passed away',
CANNOT_UPDATE_LOCATION_DETAILS_FOR_ONLINE_EVENT:
'Cannot update location or latitude or longitude details for an online event',
CANNOT_UPDATE_ONLINE_DETAILS_FOR_OFFLINE_EVENT:
'Cannot update online details for an offline event',
END_DATE_LESS_THAN_START_DATE:
'End date is passed is less than recurring start date',
CANNOT_PREPONE_PAST_EVENTS:
'Cannot update events prepone not allowed for past events',
CANNOT_EDIT_ARCHIVED_EVENTS: 'Cannot Edit archived events',
CANNOT_PASS_MAIN_EVENT_FALSE:
'You can not pass isMainEvent false because event is non recurring',
CREATION_LIMIT_UNAVAILABLE: 'Event creation limit unavailable',
CREATION_COUNT_EXCEEDED: 'Event Creation Count exceeded',
RECURRENCE_PERIOD_INSUFFICIENT: 'Event recurrence period insufficient',
PUBLIC_EVENTS: 'Public events not implemented!',
DAILY_FREQUENCY: 'Daily frequency is not implemented yet',
END_CONDITION_BY_OCCURENCES:
'End condition by occurrences is not implemented yet',
EVENT_TYPE_CHANGE_NOT_SUPPORTED: 'Event type change not supported',
};

export const SUCCESS_MESSAGES = {
Expand Down
42 changes: 2 additions & 40 deletions src/modules/event/event.controller.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
import {
Controller,
Get,
Post,
Body,
Patch,
Param,
Delete,
UsePipes,
Res,
ValidationPipe,
BadRequestException,
ParseUUIDPipe,
UseFilters,
} from '@nestjs/common';
import { EventService } from './event.service';
Expand Down Expand Up @@ -48,7 +45,7 @@ export class EventController {
constructor(
private readonly eventService: EventService,
private readonly configService: ConfigService,
) { }
) {}

@UseFilters(new AllExceptionsFilter(API_ID.CREATE_EVENT))
@Post('/create')
Expand Down Expand Up @@ -95,40 +92,16 @@ export class EventController {
return this.eventService.getEvents(response, requestBody);
}

@UseFilters(new AllExceptionsFilter(API_ID.GET_EVENT_BY_ID))
@Get('/:id')
@ApiOkResponse({
description: 'Get event details by id',
status: 200,
})
@ApiInternalServerErrorResponse({
description: ERROR_MESSAGES.INTERNAL_SERVER_ERROR,
})
findOne(@Param('id', ParseUUIDPipe) id: string, @Res() response: Response) {
// return this.eventService.getEventByID(id, response);
}

@UseFilters(new AllExceptionsFilter(API_ID.UPDATE_EVENT))
@Patch('/:id')
@ApiBody({ type: UpdateEventDto })
@ApiResponse({ status: 200, description: SUCCESS_MESSAGES.EVENT_UPDATED })
@ApiInternalServerErrorResponse({
description: ERROR_MESSAGES.INTERNAL_SERVER_ERROR,
})
// @UsePipes(
// new ValidationPipe({ transform: true }),
// new DateValidationPipe(),
// // new RegistrationDateValidationPipe(),
// new RecurringEndDateValidationPipe(),
// )
updateEvent(
@Param('id') id: string,
@Body(
new ValidationPipe({ transform: true }),
// new DateValidationPipe(),
// new RegistrationDateValidationPipe(),
// new RecurringEndDateValidationPipe(),
)
@Body(new ValidationPipe({ transform: true }))
updateEventDto: UpdateEventDto,
@Res() response: Response,
) {
Expand All @@ -137,15 +110,4 @@ export class EventController {
}
return this.eventService.updateEvent(id, updateEventDto, response);
}

@UseFilters(new AllExceptionsFilter(API_ID.DELETE_EVENT))
@Delete('/:id')
@ApiResponse({ status: 200, description: SUCCESS_MESSAGES.EVENT_DELETED })
@ApiResponse({ status: 404, description: ERROR_MESSAGES.EVENT_NOT_FOUND })
deleteEvent(
@Param('id', ParseUUIDPipe) id: string,
@Res() response: Response,
) {
// return this.eventService.deleteEvent(id, response);
}
}
Loading

0 comments on commit 64d1783

Please sign in to comment.