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.
ORV2-2294 Backend API - Create Credit Account (#1438)
Co-authored-by: praju-aot <[email protected]> Co-authored-by: Praveen Raju <[email protected]>
- Loading branch information
1 parent
110898f
commit 080725f
Showing
49 changed files
with
2,074 additions
and
46 deletions.
There are no files selected for viewing
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
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
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
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
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
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
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
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
22 changes: 22 additions & 0 deletions
22
vehicles/src/common/decorator/is-feature-flag-enabled.decorator.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,22 @@ | ||
import { Reflector } from '@nestjs/core'; | ||
|
||
/** | ||
* Decorator to check if a specific feature flag is enabled. | ||
* | ||
* The feature flag can be used to conditionally enable or disable parts of the application | ||
* depending on the current configuration or environment setup. | ||
* | ||
* Usage: | ||
* | ||
* ```typescript | ||
* @IsFeatureFlagEnabled('featureName') | ||
* async someFunction() { | ||
* // function implementation | ||
* } | ||
* ``` | ||
* | ||
* @param {string} flagName - The name of the feature flag to check. | ||
* @returns {MethodDecorator} The method decorator to be applied. | ||
*/ | ||
|
||
export const IsFeatureFlagEnabled = Reflector.createDecorator<string>(); |
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
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
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,22 @@ | ||
export const CreditAccountLimit = { | ||
PREPAID: 'PREPAID', | ||
500: '500', | ||
1000: '1000', | ||
2000: '2000', | ||
5000: '5000', | ||
7500: '7500', | ||
10000: '10000', | ||
15000: '15000', | ||
20000: '20000', | ||
30000: '30000', | ||
40000: '40000', | ||
50000: '50000', | ||
60000: '60000', | ||
70000: '70000', | ||
80000: '80000', | ||
90000: '90000', | ||
100000: '100000', | ||
} as const; | ||
|
||
export type CreditAccountLimitType = | ||
(typeof CreditAccountLimit)[keyof typeof CreditAccountLimit]; |
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,6 @@ | ||
export enum CreditAccountStatusType { | ||
ACCOUNT_ON_HOLD = 'ONHOLD', | ||
ACCOUNT_ACTIVE = 'ACTIVE', | ||
ACCOUNT_SETUP = 'SETUP', | ||
ACCOUNT_SETUP_FAIL = 'SETUP_FAIL', | ||
ACCOUNT_CLOSED = '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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export enum CreditAccountUserType { | ||
ACCOUNT_HOLDER = 'HOLDER', | ||
ACCOUNT_USER = 'USER', | ||
} |
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,4 +1,5 @@ | ||
export enum GovCommonServices { | ||
COMMON_HOSTED_EMAIL_SERVICE = 'CHES', | ||
COMMON_DOCUMENT_GENERATION_SERVICE = 'CDOGS', | ||
CREDIT_ACCOUNT_SERVICE = 'CREDIT_ACCOUNT', | ||
} |
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
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,61 @@ | ||
import { CACHE_MANAGER } from '@nestjs/cache-manager'; | ||
import { | ||
CanActivate, | ||
ExecutionContext, | ||
Inject, | ||
Injectable, | ||
} from '@nestjs/common'; | ||
import { Reflector } from '@nestjs/core'; | ||
import { Cache } from 'cache-manager'; | ||
import { IsFeatureFlagEnabled } from '../decorator/is-feature-flag-enabled.decorator'; | ||
import { CacheKey } from '../enum/cache-key.enum'; | ||
import { FeatureFlagValue } from '../enum/feature-flag-value.enum'; | ||
import { getMapFromCache } from '../helper/cache.helper'; | ||
|
||
/** | ||
* @class FeatureFlagGuard | ||
* @description A guard that checks if a specific feature flag is enabled before allowing access to a route. | ||
* @implements {CanActivate} | ||
* | ||
* @constructor | ||
* @param {Reflector} reflector - A utility for accessing decorated metadata on classes and methods. | ||
* @param {Cache} cacheManager - A cache manager instance for retrieving feature flag values. | ||
* | ||
* @method canActivate | ||
* @description Determines if the current request can proceed based on the feature flag status. | ||
* @param {ExecutionContext} context - The context of the current execution (e.g., request). | ||
* @returns {Promise<boolean>} - A promise that resolves to true if the feature flag is enabled, otherwise false. | ||
*/ | ||
@Injectable() | ||
export class FeatureFlagGuard implements CanActivate { | ||
constructor( | ||
private reflector: Reflector, | ||
@Inject(CACHE_MANAGER) | ||
private readonly cacheManager: Cache, | ||
) {} | ||
|
||
/** | ||
* Determines if the current request can proceed based on the feature flag status. | ||
* | ||
* @method canActivate | ||
* @param {ExecutionContext} context - The context of the current execution (e.g., request). | ||
* @returns {Promise<boolean>} - A promise that resolves to true if the feature flag is enabled, otherwise false. | ||
*/ | ||
async canActivate(context: ExecutionContext): Promise<boolean> { | ||
const featureFlagKey = this.reflector.getAllAndOverride<string>( | ||
IsFeatureFlagEnabled, | ||
[context.getHandler(), context.getClass()], | ||
); | ||
// Guard is invoked regardless of the decorator being actively called | ||
if (!featureFlagKey) return Promise.resolve(true); | ||
const featureFlags = await getMapFromCache( | ||
this.cacheManager, | ||
CacheKey.FEATURE_FLAG_TYPE, | ||
); | ||
const isFeatureEnabled = | ||
featureFlags?.[featureFlagKey] && | ||
(featureFlags[featureFlagKey] as FeatureFlagValue) === | ||
FeatureFlagValue.ENABLED; | ||
return isFeatureEnabled; | ||
} | ||
} |
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
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,16 @@ | ||
import { CreditAccount } from '../../modules/credit-account/entities/credit-account.entity'; | ||
import { CreditAccountStatusType } from '../enum/credit-account-status-type.enum'; | ||
|
||
export const isActiveCreditAccount = (creditAccount: CreditAccount) => { | ||
return ( | ||
creditAccount?.creditAccountStatusType === | ||
CreditAccountStatusType.ACCOUNT_ACTIVE | ||
); | ||
}; | ||
|
||
export const isClosedCreditAccount = (creditAccount: CreditAccount) => { | ||
return ( | ||
creditAccount?.creditAccountStatusType === | ||
CreditAccountStatusType.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
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.