Skip to content

Commit 30222e7

Browse files
committed
#2743: user's availability calendar now reflects RSVP'd meetings
1 parent 9570f46 commit 30222e7

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed

src/backend/src/services/design-reviews.services.ts

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,76 @@ export default class DesignReviewsService {
396396
updatedDesignReview.wbsElement
397397
);
398398
}
399+
400+
// Mark all attendees as unavailable during the scheduled meeting time
401+
for (const member of updatedDesignReview.confirmedMembers) {
402+
let userSettings = await prisma.schedule_Settings.findUnique({
403+
where: { userId: member.userId },
404+
...getUserScheduleSettingsQueryArgs()
405+
});
406+
407+
if (!userSettings) {
408+
userSettings = await prisma.schedule_Settings.create({
409+
data: {
410+
userId: member.userId,
411+
availabilities: {
412+
createMany: {
413+
data: [
414+
{
415+
availability: [],
416+
dateSet: dateScheduled
417+
}
418+
]
419+
}
420+
},
421+
personalGmail: '',
422+
personalZoomLink: ''
423+
},
424+
...getUserScheduleSettingsQueryArgs()
425+
});
426+
}
427+
428+
// Check if user has availability already for the scheduled date
429+
// TODO: Due to the off-by-one date bug, need to adjust one day from the scheduled date
430+
const existingAvailability = userSettings.availabilities.find((availability) => {
431+
const availabilityDate = new Date(availability.dateSet);
432+
const scheduledDate = new Date(updatedDesignReview.dateScheduled);
433+
// Subtract one day from scheduledDate
434+
const dayAfterScheduled = new Date(scheduledDate);
435+
dayAfterScheduled.setDate(scheduledDate.getDate() + 1);
436+
return availabilityDate.toDateString() === dayAfterScheduled.toDateString();
437+
});
438+
439+
// const existingAvailability = userSettings.availabilities.find(
440+
// (availability) => availability.dateSet.toDateString() === updatedDesignReview.dateScheduled.toDateString()
441+
// );
442+
443+
if (existingAvailability) {
444+
// Remove meeting times from existing availability
445+
const updatedAvailability = existingAvailability.availability.filter((time) => !meetingTimes.includes(time));
446+
447+
await prisma.availability.update({
448+
where: { availabilityId: existingAvailability.availabilityId },
449+
data: {
450+
availability: updatedAvailability
451+
}
452+
});
453+
454+
await prisma.schedule_Settings.update({
455+
where: { userId: member.userId },
456+
data: {
457+
availabilities: {
458+
update: {
459+
where: { availabilityId: existingAvailability.availabilityId },
460+
data: {
461+
availability: updatedAvailability
462+
}
463+
}
464+
}
465+
}
466+
});
467+
}
468+
}
399469
}
400470

401471
return designReviewTransformer(updatedDesignReview);

0 commit comments

Comments
 (0)