@@ -33,8 +33,8 @@ import {
3333 validateReimbursementProducts ,
3434 validateUserEditRRPermissions ,
3535 validateRefund ,
36- isUserHeadOrOnFinance ,
37- validateUserIsPartOfFinanceTeamOrHead
36+ validateUserIsPartOfFinanceTeamOrHead ,
37+ isUserOnFinanceTeam
3838} from '../utils/reimbursement-requests.utils' ;
3939import {
4040 AccessDeniedAdminOnlyException ,
@@ -171,7 +171,12 @@ export default class ReimbursementRequestService {
171171 * @returns All the reimbursements in the database
172172 */
173173 static async getAllReimbursements ( user : User , organization : Organization ) : Promise < Reimbursement [ ] > {
174- await isUserHeadOrOnFinance ( user , organization . organizationId ) ;
174+ const isUserAuthorized =
175+ ( await isUserOnFinanceTeam ( user , organization . organizationId ) ) ||
176+ ( await userHasPermission ( user . userId , organization . organizationId , isHead ) ) ;
177+ if ( ! isUserAuthorized ) {
178+ throw new AccessDeniedException ( `You are not a member of the finance team!` ) ;
179+ }
175180
176181 const reimbursements = await prisma . reimbursement . findMany ( {
177182 where : {
@@ -789,7 +794,12 @@ export default class ReimbursementRequestService {
789794 * @returns the 'deleted' account code
790795 */
791796 static async deleteAccountCode ( accountCodeId : string , submitter : User , organization : Organization ) {
792- await isUserHeadOrOnFinance ( submitter , organization . organizationId ) ;
797+ const isUserAuthorized =
798+ ( await isUserOnFinanceTeam ( submitter , organization . organizationId ) ) ||
799+ ( await userHasPermission ( submitter . userId , organization . organizationId , isHead ) ) ;
800+ if ( ! isUserAuthorized ) {
801+ throw new AccessDeniedException ( `You are not a member of the finance team!` ) ;
802+ }
793803
794804 const accountCode = await ReimbursementRequestService . getSingleAccountCode ( accountCodeId , organization ) ;
795805
@@ -896,7 +906,12 @@ export default class ReimbursementRequestService {
896906 * @returns an array of the prisma version of the reimbursement requests transformed to the shared version
897907 */
898908 static async getAllReimbursementRequests ( user : User , organization : Organization ) : Promise < ReimbursementRequest [ ] > {
899- await isUserHeadOrOnFinance ( user , organization . organizationId ) ;
909+ const isUserAuthorized =
910+ ( await isUserOnFinanceTeam ( user , organization . organizationId ) ) ||
911+ ( await userHasPermission ( user . userId , organization . organizationId , isHead ) ) ;
912+ if ( ! isUserAuthorized ) {
913+ throw new AccessDeniedException ( `You are not a member of the finance team!` ) ;
914+ }
900915
901916 const reimbursementRequests = await prisma . reimbursement_Request . findMany ( {
902917 where : { dateDeleted : null , accountCode : { organizationId : organization . organizationId } } ,
@@ -1106,12 +1121,15 @@ export default class ReimbursementRequestService {
11061121 } ,
11071122 ...getReimbursementStatusQueryArgs ( organization . organizationId )
11081123 } ) ;
1109-
1110- await sendReimbursementRequestLeadershipApprovedNotification (
1111- reimbursementRequest . notificationSlackThreads ,
1112- submitter . userId ,
1113- reimbursementRequest . recipientId
1114- ) ;
1124+ try {
1125+ await sendReimbursementRequestLeadershipApprovedNotification (
1126+ reimbursementRequest . notificationSlackThreads ,
1127+ submitter . userId ,
1128+ reimbursementRequest . recipientId
1129+ ) ;
1130+ } catch ( e : unknown ) {
1131+ console . error ( 'Error sending reimbursement request leadership approved notification:' , e ) ;
1132+ }
11151133
11161134 return reimbursementStatusTransformer ( reimbursementStatus ) ;
11171135 }
@@ -1192,11 +1210,15 @@ export default class ReimbursementRequestService {
11921210 ...getReimbursementStatusQueryArgs ( organization . organizationId )
11931211 } ) ;
11941212
1195- await sendPendingSaboSubmissionNotification (
1196- reimbursementRequest . notificationSlackThreads ,
1197- submitter . userId ,
1198- reimbursementRequest . recipientId
1199- ) ;
1213+ try {
1214+ await sendPendingSaboSubmissionNotification (
1215+ reimbursementRequest . notificationSlackThreads ,
1216+ submitter . userId ,
1217+ reimbursementRequest . recipientId
1218+ ) ;
1219+ } catch ( e : unknown ) {
1220+ console . error ( 'Error sending pending SABO submission notification:' , e ) ;
1221+ }
12001222
12011223 return reimbursementStatusTransformer ( reimbursementStatus ) ;
12021224 }
@@ -1270,7 +1292,11 @@ export default class ReimbursementRequestService {
12701292 ...getReimbursementStatusQueryArgs ( organization . organizationId )
12711293 } ) ;
12721294
1273- await sendSubmittedToSaboNotification ( reimbursementRequest . notificationSlackThreads ) ;
1295+ try {
1296+ await sendSubmittedToSaboNotification ( reimbursementRequest . notificationSlackThreads ) ;
1297+ } catch ( e : unknown ) {
1298+ console . error ( 'Error sending submitted to SABO notification:' , e ) ;
1299+ }
12741300
12751301 return reimbursementStatusTransformer ( reimbursementStatus ) ;
12761302 }
@@ -1339,7 +1365,11 @@ export default class ReimbursementRequestService {
13391365 'Reimbursement Request successfully updated, however no slack message was sent as recipient is missing their settings!'
13401366 ) ;
13411367
1342- await sendReimbursementRequestDeniedNotification ( recipientSettings . slackId , reimbursementRequestId ) ;
1368+ try {
1369+ await sendReimbursementRequestDeniedNotification ( recipientSettings . slackId , reimbursementRequestId ) ;
1370+ } catch ( e : unknown ) {
1371+ console . error ( 'Error sending reimbursement request denied notification:' , e ) ;
1372+ }
13431373
13441374 return reimbursementStatusTransformer ( reimbursementStatus ) ;
13451375 }
@@ -1401,8 +1431,12 @@ export default class ReimbursementRequestService {
14011431 throw new InvalidOrganizationException ( 'Vendor' ) ;
14021432 }
14031433
1404- if ( existingVendor . addedByUserId !== submitter . userId ) {
1405- await isUserHeadOrOnFinance ( submitter , organization . organizationId ) ;
1434+ const isUserAuthorized =
1435+ existingVendor . addedByUserId === submitter . userId ||
1436+ ( await isUserOnFinanceTeam ( submitter , organization . organizationId ) ) ||
1437+ ( await userHasPermission ( submitter . userId , organization . organizationId , isHead ) ) ;
1438+ if ( ! isUserAuthorized ) {
1439+ throw new AccessDeniedException ( `You are not a member of the finance team!` ) ;
14061440 }
14071441
14081442 const users = await getUsers ( twoFactorContacts ) ;
@@ -1453,8 +1487,12 @@ export default class ReimbursementRequestService {
14531487 throw new InvalidOrganizationException ( 'Vendor' ) ;
14541488 }
14551489
1456- if ( existingVendor . addedByUserId !== submitter . userId ) {
1457- await isUserHeadOrOnFinance ( submitter , organization . organizationId ) ;
1490+ const isUserAuthorized =
1491+ existingVendor . addedByUserId === submitter . userId ||
1492+ ( await isUserOnFinanceTeam ( submitter , organization . organizationId ) ) ||
1493+ ( await userHasPermission ( submitter . userId , organization . organizationId , isHead ) ) ;
1494+ if ( ! isUserAuthorized ) {
1495+ throw new AccessDeniedException ( `You are not a member of the finance team!` ) ;
14581496 }
14591497
14601498 const deletedVendor = await prisma . vendor . update ( {
@@ -1582,7 +1620,11 @@ export default class ReimbursementRequestService {
15821620 ...getReimbursementStatusQueryArgs ( organization . organizationId )
15831621 } ) ;
15841622
1585- await sendReimbursementRequestPendingFinanceNotification ( reimbursementRequest . notificationSlackThreads ) ;
1623+ try {
1624+ await sendReimbursementRequestPendingFinanceNotification ( reimbursementRequest . notificationSlackThreads ) ;
1625+ } catch ( e : unknown ) {
1626+ console . error ( 'Error sending reimbursement request pending finance notification:' , e ) ;
1627+ }
15861628
15871629 return reimbursementStatusTransformer ( updatedReimbursementStatus ) ;
15881630 }
@@ -1636,7 +1678,11 @@ export default class ReimbursementRequestService {
16361678 ...getReimbursementStatusQueryArgs ( organization . organizationId )
16371679 } ) ;
16381680
1639- await sendReimbursementRequestChangesRequestedNotification ( reimbursementRequest . notificationSlackThreads , user . userId ) ;
1681+ try {
1682+ await sendReimbursementRequestChangesRequestedNotification ( reimbursementRequest . notificationSlackThreads , user . userId ) ;
1683+ } catch ( e : unknown ) {
1684+ console . error ( 'Error sending reimbursement request changes requested notification:' , e ) ;
1685+ }
16401686
16411687 return reimbursementStatusTransformer ( deletedStatus ) ;
16421688 }
@@ -1995,7 +2041,11 @@ export default class ReimbursementRequestService {
19952041 comment += ` ${ [ ...new Set ( restOfTags ) ] . join ( ' ' ) } ` ;
19962042 }
19972043
1998- await sendThreadResponse ( reimbursementRequest . notificationSlackThreads , comment ) ;
2044+ try {
2045+ await sendThreadResponse ( reimbursementRequest . notificationSlackThreads , comment ) ;
2046+ } catch ( e : unknown ) {
2047+ console . error ( 'Error sending thread response:' , e ) ;
2048+ }
19992049
20002050 return reimbursementRequestCommentTransformer ( createdComment ) ;
20012051 }
0 commit comments