@@ -27,8 +27,12 @@ import userSecureSettingsTransformer from '../transformers/user-secure-settings.
2727import { validateUserIsPartOfFinanceTeam } from '../utils/reimbursement-requests.utils' ;
2828import userScheduleSettingsTransformer from '../transformers/user-schedule-settings.transformer' ;
2929import { userTransformer , userWithScheduleSettingsTransformer } from '../transformers/user.transformer' ;
30- import { getUserRole } from '../utils/users.utils' ;
31- import { getUserQueryArgs , getUserWithSettingsQueryArgs } from '../prisma-query-args/user.query-args' ;
30+ import { getUserRole , updateUserAvailability } from '../utils/users.utils' ;
31+ import {
32+ getUserQueryArgs ,
33+ getUserScheduleSettingsQueryArgs ,
34+ getUserWithSettingsQueryArgs
35+ } from '../prisma-query-args/user.query-args' ;
3236import { getAuthUserQueryArgs } from '../prisma-query-args/auth-user.query-args' ;
3337import authenticatedUserTransformer from '../transformers/auth-user.transformer' ;
3438
@@ -44,7 +48,7 @@ export default class UsersService {
4448 include : {
4549 roles : true ,
4650 userSettings : true ,
47- drScheduleSettings : true ,
51+ drScheduleSettings : getUserScheduleSettingsQueryArgs ( ) ,
4852 organizations : true
4953 }
5054 } ) ;
@@ -480,7 +484,8 @@ export default class UsersService {
480484 static async getUserScheduleSettings ( userId : string , submitter : PrismaUser ) : Promise < UserScheduleSettings > {
481485 if ( submitter . userId !== userId ) throw new AccessDeniedException ( 'You can only access your own schedule settings' ) ;
482486 const scheduleSettings = await prisma . schedule_Settings . findUnique ( {
483- where : { userId }
487+ where : { userId } ,
488+ ...getUserScheduleSettingsQueryArgs ( )
484489 } ) ;
485490 if ( ! scheduleSettings ) throw new HttpException ( 404 , 'User Schedule Settings Not Found' ) ;
486491
@@ -501,28 +506,32 @@ export default class UsersService {
501506 personalZoomLink : string ,
502507 availability : number [ ]
503508 ) : Promise < UserScheduleSettings > {
504- const existingUser = await prisma . schedule_Settings . findFirst ( {
505- where : { personalGmail, userId : { not : user . userId } } // excludes the current user from check
506- } ) ;
509+ if ( personalGmail !== '' ) {
510+ const existingUser = await prisma . schedule_Settings . findFirst ( {
511+ where : { personalGmail, userId : { not : user . userId } } // excludes the current user from check
512+ } ) ;
507513
508- if ( existingUser ) {
509- throw new HttpException ( 400 , 'Email already in use' ) ;
514+ if ( existingUser ) {
515+ throw new HttpException ( 400 , 'Email already in use' ) ;
516+ }
510517 }
511518
512519 const newUserScheduleSettings = await prisma . schedule_Settings . upsert ( {
513520 where : { userId : user . userId } ,
514521 update : {
515522 personalGmail,
516- personalZoomLink,
517- availability
523+ personalZoomLink
518524 } ,
519525 create : {
520526 userId : user . userId ,
521527 personalGmail,
522- personalZoomLink,
523- availability
524- }
528+ personalZoomLink
529+ } ,
530+ ... getUserScheduleSettingsQueryArgs ( )
525531 } ) ;
532+
533+ await updateUserAvailability ( availability , newUserScheduleSettings , user , new Date ( ) ) ;
534+
526535 return userScheduleSettingsTransformer ( newUserScheduleSettings ) ;
527536 }
528537}
0 commit comments