@@ -14,7 +14,8 @@ import {
1414 FilterArgs ,
1515 Machinery ,
1616 ScheduleSlot ,
17- notGuest
17+ notGuest ,
18+ isSameDay
1819} from 'shared' ;
1920import { getCalendarQueryArgs } from '../prisma-query-args/calendar.query-args.js' ;
2021import { 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 }
0 commit comments