Skip to content

Commit

Permalink
Merge pull request #22 from Xitija/main
Browse files Browse the repository at this point in the history
PS - 1687 :  Add attendees against EventId
  • Loading branch information
vaivk369 authored Aug 9, 2024
2 parents 54d6c5f + c0ec991 commit 5823c0c
Show file tree
Hide file tree
Showing 8 changed files with 413 additions and 235 deletions.
3 changes: 2 additions & 1 deletion src/common/utils/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export type RepetitionDetail = {
}
| {}
| null;
metadata: any;
erMetaData: any;
eventRepetitionId: string;
startDateTime: Date;
endDateTime: Date;
Expand Down Expand Up @@ -71,6 +71,7 @@ export type RecurrencePattern = {
// byDay: string;
// byMonth: string;
// byMonthDay: string;
recurringStartDate: string;
endCondition: {
type: EndConditionType;
value: string;
Expand Down
30 changes: 29 additions & 1 deletion src/modules/attendees/attendees.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,11 +336,13 @@ export class AttendeesService {

createEventAttendeesRecord(
userId: string,
eventId: string,
eventRepetitionId: string,
creatorOrUpdaterId: string,
) {
const eventAttendees = new EventAttendees();
eventAttendees.userId = userId;
eventAttendees.eventId = eventId;
eventAttendees.eventRepetitionId = eventRepetitionId;
eventAttendees.enrolledAt = new Date();
eventAttendees.updatedAt = new Date();
Expand All @@ -354,9 +356,11 @@ export class AttendeesService {

async createAttendeesForRecurringEvents(
userIds: string[],
eventId: string,
eventRepetitionIds: [],
creatorOrUpdaterId: string,
) {
// TODO: check max attendees
// This method creates attendees when attendees are passed during creating event in attendees array and autoEnroll and isRestricted is true
// All the attendees passed will be added to all recurring events
// if there are 5 recurring events and 5 attendees then total 5*5 that is 25 entries will be added to the database
Expand All @@ -368,14 +372,38 @@ export class AttendeesService {
// attendeesRecords.push(
this.createEventAttendeesRecord(
userId,
eventId,
eventRepetitionId,
creatorOrUpdaterId,
// ),
),
);
promises.push(this.eventAttendeesRepository.insert(attendeesRecords));
});
await Promise.allSettled(promises);
const prm = await Promise.allSettled(promises);
prm.forEach((result) => {
if (result.status !== 'fulfilled') {
throw result.reason;
}
});
} catch (e) {
throw e;
}
}

async createAttendeesForEvents(
userIds: string[],
eventId: string,
creatorId: string,
) {
// This method creates attendees when attendees are passed during creating event in attendees array and autoEnroll and isRestricted is true
// All the attendees passed will be added to the event
try {
if (!userIds?.length) return;
const attendeesRecords = userIds.map((userId) =>
this.createEventAttendeesRecord(userId, eventId, null, creatorId),
);
await this.eventAttendeesRepository.insert(attendeesRecords);
} catch (e) {
throw e;
}
Expand Down
3 changes: 3 additions & 0 deletions src/modules/attendees/entity/attendees.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ export class EventAttendees {
@Column({ type: 'uuid' })
userId: string;

@Column({ type: 'uuid', nullable: true })
eventId: string;

@Column({ type: 'uuid', nullable: true })
eventRepetitionId: string;

Expand Down
12 changes: 11 additions & 1 deletion src/modules/event/dto/create-event.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ export class RecurrencePatternDto {
// @IsOptional()
// dayOfMonth: number;

recurringStartDate: string;

@ApiProperty({
type: EndCondition,
description: 'End Condition',
Expand Down Expand Up @@ -315,7 +317,6 @@ export class CreateEventDto {
@Type(() => String)
@ArrayMaxSize(200)
@IsUUID('4', { each: true })
@IsOptional()
attendees: string[];

@ApiProperty({
Expand Down Expand Up @@ -411,4 +412,13 @@ export class CreateEventDto {
@IsObject()
@IsOptional()
metaData: any;

@ApiProperty({
type: Object,
description: 'Meta data for recurring events',
example: '',
})
@IsObject()
@IsOptional()
erMetaData: any;
}
Loading

0 comments on commit 5823c0c

Please sign in to comment.