@@ -467,8 +467,8 @@ partiallyUpdateInterviewByRound.schema = Joi.object().keys({
467
467
jobCandidateId : Joi . string ( ) . uuid ( ) . required ( ) ,
468
468
round : Joi . number ( ) . integer ( ) . positive ( ) . required ( ) ,
469
469
data : Joi . object ( ) . keys ( {
470
- duration : Joi . number ( ) . integer ( ) . positive ( ) . required ( ) ,
471
- timezone : Joi . string ( ) . required ( ) ,
470
+ duration : Joi . number ( ) . integer ( ) . positive ( ) ,
471
+ timezone : Joi . string ( ) ,
472
472
hostUserId : Joi . string ( ) . uuid ( ) ,
473
473
expireTimestamp : Joi . date ( ) ,
474
474
availableTime : Joi . array ( ) . min ( 1 ) . items (
@@ -484,15 +484,15 @@ partiallyUpdateInterviewByRound.schema = Joi.object().keys({
484
484
end : Joi . string ( ) . regex ( InterviewConstants . Nylas . StartEndRegex ) . required ( ) ,
485
485
start : Joi . string ( ) . regex ( InterviewConstants . Nylas . StartEndRegex ) . required ( )
486
486
} )
487
- ) . required ( ) ,
487
+ ) ,
488
488
startTimestamp : Joi . date ( ) . greater ( 'now' ) . when ( 'status' , {
489
489
is : [ InterviewConstants . Status . Scheduled , InterviewConstants . Status . Rescheduled ] ,
490
- then : Joi . required ( ) ,
490
+ then : Joi . invalid ( null ) ,
491
491
otherwise : Joi . allow ( null )
492
492
} ) ,
493
493
endTimestamp : Joi . date ( ) . greater ( Joi . ref ( 'startTimestamp' ) ) . when ( 'status' , {
494
494
is : [ InterviewConstants . Status . Scheduled , InterviewConstants . Status . Rescheduled ] ,
495
- then : Joi . required ( ) ,
495
+ then : Joi . invalid ( null ) ,
496
496
otherwise : Joi . allow ( null )
497
497
} ) ,
498
498
status : Joi . interviewStatus ( ) ,
@@ -540,8 +540,8 @@ partiallyUpdateInterviewById.schema = Joi.object().keys({
540
540
currentUser : Joi . object ( ) . required ( ) ,
541
541
id : Joi . string ( ) . required ( ) ,
542
542
data : Joi . object ( ) . keys ( {
543
- duration : Joi . number ( ) . integer ( ) . positive ( ) . required ( ) ,
544
- timezone : Joi . string ( ) . required ( ) ,
543
+ duration : Joi . number ( ) . integer ( ) . positive ( ) ,
544
+ timezone : Joi . string ( ) ,
545
545
hostUserId : Joi . string ( ) . uuid ( ) ,
546
546
expireTimestamp : Joi . date ( ) ,
547
547
availableTime : Joi . array ( ) . min ( 1 ) . items (
@@ -557,15 +557,15 @@ partiallyUpdateInterviewById.schema = Joi.object().keys({
557
557
end : Joi . string ( ) . regex ( InterviewConstants . Nylas . StartEndRegex ) . required ( ) ,
558
558
start : Joi . string ( ) . regex ( InterviewConstants . Nylas . StartEndRegex ) . required ( )
559
559
} )
560
- ) . required ( ) ,
560
+ ) ,
561
561
startTimestamp : Joi . date ( ) . greater ( 'now' ) . when ( 'status' , {
562
562
is : [ InterviewConstants . Status . Scheduled , InterviewConstants . Status . Rescheduled ] ,
563
- then : Joi . required ( ) ,
563
+ then : Joi . invalid ( null ) ,
564
564
otherwise : Joi . allow ( null )
565
565
} ) ,
566
566
endTimestamp : Joi . date ( ) . greater ( Joi . ref ( 'startTimestamp' ) ) . when ( 'status' , {
567
567
is : [ InterviewConstants . Status . Scheduled , InterviewConstants . Status . Rescheduled ] ,
568
- then : Joi . required ( ) ,
568
+ then : Joi . invalid ( null ) ,
569
569
otherwise : Joi . allow ( null )
570
570
} ) ,
571
571
status : Joi . interviewStatus ( ) ,
@@ -767,6 +767,47 @@ async function updateCompletedInterviews () {
767
767
*/
768
768
async function partiallyUpdateInterviewByWebhook ( interviewId , webhookBody ) {
769
769
logger . info ( { component : 'InterviewService' , context : 'partiallyUpdateInterviewByWebhook' , message : `Received webhook for interview id "${ interviewId } ": ${ JSON . stringify ( webhookBody ) } ` } )
770
+
771
+ // this method is used by the Nylas webhooks, so use M2M user
772
+ const m2mUser = helper . getAuditM2Muser ( )
773
+ const bookingDetails = webhookBody . booking
774
+ const interviewStartTimeMoment = moment . unix ( bookingDetails . start_time )
775
+ const interviewEndTimeMoment = moment . unix ( bookingDetails . end_time )
776
+ let updatedInterview
777
+
778
+ if ( bookingDetails . is_confirmed ) {
779
+ try {
780
+ // CREATED + confirmed ==> inteview updated to scheduled
781
+ // UPDATED + cancelled ==> inteview expired
782
+ updatedInterview = await partiallyUpdateInterviewById (
783
+ m2mUser ,
784
+ interviewId ,
785
+ {
786
+ status : InterviewConstants . Status . Scheduled ,
787
+ startTimestamp : interviewStartTimeMoment . toDate ( ) ,
788
+ endTimestamp : interviewEndTimeMoment . toDate ( )
789
+ }
790
+ )
791
+
792
+ logger . debug ( {
793
+ component : 'InterviewService' ,
794
+ context : 'partiallyUpdateInterviewByWebhook' ,
795
+ message :
796
+ `~~~~~~~~~~~NEW EVENT~~~~~~~~~~~\nInterview Scheduled under account id ${
797
+ bookingDetails . account_id
798
+ } (email is ${ bookingDetails . recipient_email } ) in calendar id ${
799
+ bookingDetails . calendar_id
800
+ } . Event status is ${ InterviewConstants . Status . Scheduled } and starts from ${ interviewStartTimeMoment
801
+ . format ( 'MMM DD YYYY HH:mm' ) } and ends at ${ interviewEndTimeMoment
802
+ . format ( 'MMM DD YYYY HH:mm' ) } `
803
+ } )
804
+ } catch ( err ) {
805
+ logger . logFullError ( err , { component : 'InterviewService' , context : 'partiallyUpdateInterviewByWebhook' } )
806
+ throw new errors . BadRequestError ( `Could not update interview: ${ err . message } ` )
807
+ }
808
+
809
+ return updatedInterview
810
+ }
770
811
}
771
812
772
813
module . exports = {
0 commit comments