55
66// eslint-disable-next-line @typescript-eslint/no-unused-vars
77import type { Multer } from 'multer' ;
8- import { Reimbursement_Request , Reimbursement_Status_Type , User } from '@prisma/client' ;
8+ import { Club_Accounts , Reimbursement_Request , Reimbursement_Status_Type , User } from '@prisma/client' ;
99import {
1010 ClubAccount ,
1111 ExpenseType ,
@@ -131,6 +131,10 @@ export default class ReimbursementRequestService {
131131
132132 if ( ! expenseType . allowed ) throw new HttpException ( 400 , `The expense type ${ expenseType . name } is not allowed!` ) ;
133133
134+ if ( ! expenseType . allowedRefundSources . includes ( account ) ) {
135+ throw new HttpException ( 400 , 'The submitted refund source is not allowed to be used with the submitted expense type' ) ;
136+ }
137+
134138 const validatedReimbursementProudcts = await validateReimbursementProducts ( reimbursementProducts ) ;
135139
136140 const createdReimbursementRequest = await prisma . reimbursement_Request . create ( {
@@ -268,6 +272,9 @@ export default class ReimbursementRequestService {
268272
269273 if ( ! expenseType ) throw new NotFoundException ( 'Expense Type' , expenseTypeId ) ;
270274 if ( ! expenseType . allowed ) throw new HttpException ( 400 , 'Expense Type Not Allowed' ) ;
275+ if ( ! expenseType . allowedRefundSources . includes ( account ) ) {
276+ throw new HttpException ( 400 , 'The submitted refund source is not allowed to be used with the submitted expense type' ) ;
277+ }
271278
272279 await updateReimbursementProducts (
273280 oldReimbursementRequest . reimbursementProducts ,
@@ -463,15 +470,23 @@ export default class ReimbursementRequestService {
463470 * @param name The name of the expense type
464471 * @param code the expense type's SABO code
465472 * @param allowed whether or not this expense type is allowed
473+ * @param allowedRefundSources an array of Club_Accounts representing allowed refund sources
466474 * @returns the created expense type
467475 */
468- static async createExpenseType ( submitter : User , name : string , code : number , allowed : boolean ) {
476+ static async createExpenseType (
477+ submitter : User ,
478+ name : string ,
479+ code : number ,
480+ allowed : boolean ,
481+ allowedRefundSources : Club_Accounts [ ]
482+ ) {
469483 if ( ! isAdmin ( submitter . role ) ) throw new AccessDeniedAdminOnlyException ( 'create expense types' ) ;
470484 const expense = await prisma . expense_Type . create ( {
471485 data : {
472486 name,
473487 allowed,
474- code
488+ code,
489+ allowedRefundSources
475490 }
476491 } ) ;
477492
@@ -487,7 +502,14 @@ export default class ReimbursementRequestService {
487502 * @param submitter the person editing expense type code number
488503 * @returns the updated expense type
489504 */
490- static async editExpenseType ( expenseTypeId : string , code : number , name : string , allowed : boolean , submitter : User ) {
505+ static async editExpenseType (
506+ expenseTypeId : string ,
507+ code : number ,
508+ name : string ,
509+ allowed : boolean ,
510+ submitter : User ,
511+ allowedRefundSources : Club_Accounts [ ]
512+ ) {
491513 if ( ! isHead ( submitter . role ) )
492514 throw new AccessDeniedException ( 'Only the head or admin can update account code number and name' ) ;
493515
@@ -502,7 +524,8 @@ export default class ReimbursementRequestService {
502524 data : {
503525 name,
504526 code,
505- allowed
527+ allowed,
528+ allowedRefundSources
506529 }
507530 } ) ;
508531
0 commit comments