Skip to content

Commit 79105b3

Browse files
committed
scheduling events marks confirmed users as busy during that time
1 parent 2e13410 commit 79105b3

2 files changed

Lines changed: 21 additions & 2 deletions

File tree

src/backend/src/services/calendar.services.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ import {
1414
FilterArgs,
1515
Machinery,
1616
ScheduleSlot,
17-
notGuest
17+
notGuest,
18+
isSameDay
1819
} from 'shared';
1920
import { getCalendarQueryArgs } from '../prisma-query-args/calendar.query-args.js';
2021
import { getEventTypeQueryArgs } from '../prisma-query-args/event-type.query-args.js';
@@ -1452,6 +1453,24 @@ export default class CalendarService {
14521453
...getEventQueryArgs(organization.organizationId)
14531454
});
14541455

1456+
// Remove the scheduled time from confirmed members' availabilities so they can't be
1457+
// double-booked for other events that require confirmation during the same time slot
1458+
const startHour = startTime.getHours();
1459+
const endHour = endTime.getHours();
1460+
for (const member of event.confirmedMembers) {
1461+
if (!member.drScheduleSettings) continue;
1462+
const existingAvailability = member.drScheduleSettings.availabilities.find((a) => isSameDay(a.dateSet, startTime));
1463+
if (!existingAvailability) continue;
1464+
// Availability index i represents local hour (10 + i); remove indices that fall within [startHour, endHour)
1465+
const updatedAvailability = existingAvailability.availability.filter(
1466+
(i) => !(10 + i >= startHour && 10 + i < endHour)
1467+
);
1468+
await prisma.availability.update({
1469+
where: { availabilityId: existingAvailability.availabilityId },
1470+
data: { availability: updatedAvailability }
1471+
});
1472+
}
1473+
14551474
const { eventTypeId } = updatedEvent;
14561475
const foundEventType = await prisma.event_Type.findUnique({
14571476
where: { eventTypeId }

src/frontend/src/utils/calendar.utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export const getPendingReason = (event: EventInstance): string | null => {
99
return 'This event has a scheduling conflict and requires approval.';
1010
} else if (event.approved === ConflictStatus.DENIED) {
1111
return 'This event was denied due to a scheduling conflict.';
12-
} else if (event.status === EventStatus.UNCONFIRMED) {
12+
} else if (event.status !== EventStatus.SCHEDULED) {
1313
return 'This event is unconfirmed and waiting to be scheduled.';
1414
}
1515
return null;

0 commit comments

Comments
 (0)