@@ -20,9 +20,12 @@ import updateZoom from 'lib/api/update/zoom';
2020import verifyAuth from 'lib/api/verify/auth' ;
2121import verifyBody from 'lib/api/verify/body' ;
2222import verifyDocExists from 'lib/api/verify/doc-exists' ;
23+ import verifyOptions from 'lib/api/verify/options' ;
24+ import verifyRecurIncludesTime from 'lib/api/verify/recur-includes-time' ;
2325import verifySubjectsCanBeTutored from 'lib/api/verify/subjects-can-be-tutored' ;
2426import verifyTimeInAvailability from 'lib/api/verify/time-in-availability' ;
2527
28+ export type UpdateMeetingOptions = { original : MeetingJSON } ;
2629export type UpdateMeetingRes = MeetingJSON ;
2730
2831export default async function updateMeeting (
@@ -35,6 +38,9 @@ export default async function updateMeeting(
3538 isMeetingJSON ,
3639 Meeting
3740 ) ;
41+ const options = verifyOptions < UpdateMeetingOptions > ( req . body , {
42+ original : body . toJSON ( ) ,
43+ } ) ;
3844
3945 const [ matchDoc , meetingDoc ] = await Promise . all ( [
4046 verifyDocExists ( 'matches' , body . match . id ) ,
@@ -62,7 +68,7 @@ export default async function updateMeeting(
6268 // - Admins can change 'approved' to 'pending' or 'logged'.
6369 // - Meeting people can change 'pending' to 'logged'.
6470
65- if ( original . time . recur ) {
71+ if ( original . id !== body . id && original . time . recur ) {
6672 // User is updating a recurring meeting. By default, we only update this
6773 // meeting and all future meetings:
6874 // 1. Create a new recurring meeting using this meeting's data.
@@ -72,16 +78,24 @@ export default async function updateMeeting(
7278 body . id = '' ;
7379 body . parentId = undefined ;
7480 body . venue = await createZoom ( body , people ) ;
81+
82+ // Ensure that the `until` value isn't before the `time.from` value (which
83+ // would prevent *any* meeting instances from being calculated).
84+ body . time . recur = verifyRecurIncludesTime ( body . time ) ;
7585 body . time . last = getLastTime ( body . time ) ;
7686
7787 const meeting = await createMeetingDoc ( body ) ;
7888 await createMeetingSearchObj ( meeting ) ;
7989
80- // TODO: We need to know the start time of the meeting instance before it
90+ // TODO: We need to know the start date of the meeting instance before it
8191 // was updated. Otherwise, we can't properly exclude it from the original.
8292 original . time . recur = RRule . optionsToString ( {
8393 ...RRule . parseString ( original . time . recur ) ,
84- until : body . time . from , // TODO: Replace with time before update.
94+ until : new Date (
95+ new Date ( options . original . time . from ) . getFullYear ( ) ,
96+ new Date ( options . original . time . from ) . getMonth ( ) ,
97+ new Date ( options . original . time . from ) . getDate ( )
98+ ) ,
8599 } ) ;
86100 original . time . last = getLastTime ( original . time ) ;
87101
0 commit comments