generated from bcgov/quickstart-openshift
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: ORV2-2353 / ORV2-2351 Credit Account Hold and Close (#1451)
- Loading branch information
Showing
10 changed files
with
473 additions
and
154 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
vehicles/src/common/constraint/credit-account-status-comment.constraint.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { | ||
ValidatorConstraint, | ||
ValidatorConstraintInterface, | ||
ValidationArguments, | ||
} from 'class-validator'; | ||
import { | ||
CreditAccountStatus, | ||
CreditAccountStatusValidType, | ||
} from '../enum/credit-account-status-type.enum'; | ||
|
||
@ValidatorConstraint({ | ||
name: 'CreditAccountStatusCommentConstraint', | ||
async: false, | ||
}) | ||
export class CreditAccountStatusCommentConstraint | ||
implements ValidatorConstraintInterface | ||
{ | ||
validate(comment: string | undefined, args: ValidationArguments) { | ||
const creditAccountStatusType = ( | ||
args.object as { | ||
creditAccountStatusType?: CreditAccountStatusValidType; | ||
} | ||
).creditAccountStatusType; // Access the searchString property from the same object | ||
|
||
// If CreditAccountStatusType.ACCOUNT_CLOSED or CreditAccountStatusType.ACCOUNT_ON_HOLD , comment should exists | ||
if ( | ||
(creditAccountStatusType === CreditAccountStatus.ACCOUNT_CLOSED || | ||
creditAccountStatusType === CreditAccountStatus.ACCOUNT_ON_HOLD) && | ||
!comment | ||
) { | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
defaultMessage() { | ||
return `Comment is required when activity type is ${CreditAccountStatus.ACCOUNT_CLOSED} or ${CreditAccountStatus.ACCOUNT_ON_HOLD}`; | ||
} | ||
} |
25 changes: 19 additions & 6 deletions
25
vehicles/src/common/enum/credit-account-status-type.enum.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,19 @@ | ||
export enum CreditAccountStatusType { | ||
ACCOUNT_ON_HOLD = 'ONHOLD', | ||
ACCOUNT_ACTIVE = 'ACTIVE', | ||
ACCOUNT_SETUP_FAIL = 'SETUP_FAIL', | ||
ACCOUNT_CLOSED = 'CLOSED', | ||
} | ||
export const CreditAccountStatus = { | ||
ACCOUNT_ON_HOLD: 'ONHOLD', | ||
ACCOUNT_ACTIVE: 'ACTIVE', | ||
ACCOUNT_CLOSED: 'CLOSED', | ||
ACCOUNT_SETUP_FAIL: 'SETUP_FAIL', | ||
} as const; | ||
|
||
export type CreditAccountStatusType = | ||
(typeof CreditAccountStatus)[keyof typeof CreditAccountStatus]; | ||
|
||
// Manually constructing the CreditAccountStatusValidType as a const | ||
export const CreditAccountStatusValid = { | ||
ACCOUNT_ON_HOLD: CreditAccountStatus.ACCOUNT_ON_HOLD, | ||
ACCOUNT_ACTIVE: CreditAccountStatus.ACCOUNT_ACTIVE, | ||
ACCOUNT_CLOSED: CreditAccountStatus.ACCOUNT_CLOSED, | ||
} as const; | ||
|
||
export type CreditAccountStatusValidType = | ||
(typeof CreditAccountStatus)[keyof typeof CreditAccountStatusValid]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,47 @@ | ||
import { CreditAccount } from '../../modules/credit-account/entities/credit-account.entity'; | ||
import { CreditAccountStatusType } from '../enum/credit-account-status-type.enum'; | ||
import { CreditAccountActivityType } from '../enum/credit-account-activity-type.enum'; | ||
import { | ||
CreditAccountStatus, | ||
CreditAccountStatusType, | ||
CreditAccountStatusValid, | ||
} from '../enum/credit-account-status-type.enum'; | ||
|
||
export const isActiveCreditAccount = (creditAccount: CreditAccount) => { | ||
return ( | ||
creditAccount?.creditAccountStatusType === | ||
CreditAccountStatusType.ACCOUNT_ACTIVE | ||
CreditAccountStatus.ACCOUNT_ACTIVE | ||
); | ||
}; | ||
|
||
export const isClosedCreditAccount = (creditAccount: CreditAccount) => { | ||
return ( | ||
creditAccount?.creditAccountStatusType === | ||
CreditAccountStatusType.ACCOUNT_CLOSED | ||
CreditAccountStatus.ACCOUNT_CLOSED | ||
); | ||
}; | ||
|
||
export const isOnHoldCreditAccount = (creditAccount: CreditAccount) => { | ||
return ( | ||
creditAccount?.creditAccountStatusType === | ||
CreditAccountStatus.ACCOUNT_ON_HOLD | ||
); | ||
}; | ||
|
||
export const getCreditAccountActivityType = ( | ||
creditAccount: CreditAccount, | ||
statusToUpdateTo: CreditAccountStatusType, | ||
) => { | ||
switch (statusToUpdateTo) { | ||
case CreditAccountStatusValid.ACCOUNT_ACTIVE: | ||
if (isClosedCreditAccount(creditAccount)) { | ||
return CreditAccountActivityType.ACCOUNT_REOPENED; | ||
} else if (isOnHoldCreditAccount(creditAccount)) { | ||
return CreditAccountActivityType.ACCOUNT_HOLD_REMOVED; | ||
} | ||
break; | ||
case CreditAccountStatusValid.ACCOUNT_ON_HOLD: | ||
return CreditAccountActivityType.ACCOUNT_ON_HOLD; | ||
case CreditAccountStatusValid.ACCOUNT_CLOSED: | ||
return CreditAccountActivityType.ACCOUNT_CLOSED; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.