feat: ability to enable/disable the bank connect feature (#423)

This commit is contained in:
Ahmed Bouhuolia
2024-04-24 20:01:04 +02:00
committed by GitHub
parent 1372a1f0a8
commit 7abfa6a162
10 changed files with 58 additions and 43 deletions

View File

@@ -8,10 +8,10 @@ export default class DashboardMetaController {
dashboardService: DashboardService;
/**
*
* Constructor router.
* @returns
*/
router() {
public router() {
const router = Router();
router.get('/boot', this.getDashboardBoot);
@@ -25,7 +25,7 @@ export default class DashboardMetaController {
* @param {Response} res -
* @param {NextFunction} next -
*/
getDashboardBoot = async (
private getDashboardBoot = async (
req: Request,
res: Response,
next: NextFunction

View File

@@ -180,6 +180,14 @@ module.exports = {
},
},
/**
* Bank Synchronization.
*/
bankSync: {
enabled: parseBoolean(defaultTo(process.env.BANKING_CONNECT, false), false),
provider: 'plaid',
},
/**
* Plaid.
*/

View File

@@ -1,6 +1,7 @@
export enum Features {
WAREHOUSES = 'warehouses',
BRANCHES = 'branches',
BankSyncing = 'BankSyncing'
}
export interface IFeatureAllItem {

View File

@@ -62,13 +62,13 @@ export default class MetableStore implements IMetableStore {
* @param {String} key -
* @param {Mixied} defaultValue -
*/
get(query: string | IMetaQuery, defaultValue: any): any | false {
get(query: string | IMetaQuery, defaultValue: any): any | null {
const metadata = this.find(query);
return metadata
? metadata.value
: typeof defaultValue !== 'undefined'
? defaultValue
: false;
: null;
}
/**

View File

@@ -1,8 +1,5 @@
import { defaultTo } from 'lodash';
import { Inject, Service } from 'typedi';
import { omit } from 'lodash';
import { FeaturesSettingsDriver } from './FeaturesSettingsDriver';
import { FeaturesConfigureManager } from './FeaturesConfigureManager';
import { IFeatureAllItem } from '@/interfaces';
@Service()
@@ -10,9 +7,6 @@ export class FeaturesManager {
@Inject()
private drive: FeaturesSettingsDriver;
@Inject()
private configure: FeaturesConfigureManager;
/**
* Turns-on the given feature name.
* @param {number} tenantId
@@ -40,35 +34,15 @@ export class FeaturesManager {
* @returns {Promise<void>}
*/
public async accessible(tenantId: number, feature: string) {
// Retrieves the feature default accessible value.
const defaultValue = this.configure.getFeatureConfigure(
feature,
'defaultValue'
);
const isAccessible = await this.drive.accessible(tenantId, feature);
return defaultTo(isAccessible, defaultValue);
return this.drive.accessible(tenantId, feature);
}
/**
* Retrieves the all features and their accessible value and default value.
* @param {number} tenantId
* @returns
* @returns {Promise<IFeatureAllItem[]>}
*/
public async all(tenantId: number): Promise<IFeatureAllItem[]> {
const all = await this.drive.all(tenantId);
return all.map((feature: IFeatureAllItem) => {
const defaultAccessible = this.configure.getFeatureConfigure(
feature.name,
'defaultValue'
);
const isAccessible = feature.isAccessible;
return {
...feature,
isAccessible: defaultTo(isAccessible, defaultAccessible),
};
});
return this.drive.all(tenantId);
}
}

View File

@@ -2,11 +2,15 @@ import { Service, Inject } from 'typedi';
import HasTenancyService from '@/services/Tenancy/TenancyService';
import { FeaturesConfigure } from './constants';
import { IFeatureAllItem } from '@/interfaces';
import { FeaturesConfigureManager } from './FeaturesConfigureManager';
@Service()
export class FeaturesSettingsDriver {
@Inject()
tenancy: HasTenancyService;
private tenancy: HasTenancyService;
@Inject()
private configure: FeaturesConfigureManager;
/**
* Turns-on the given feature name.
@@ -41,7 +45,15 @@ export class FeaturesSettingsDriver {
async accessible(tenantId: number, feature: string) {
const settings = this.tenancy.settings(tenantId);
return !!settings.get({ group: 'features', key: feature });
const defaultValue = this.configure.getFeatureConfigure(
feature,
'defaultValue'
);
const settingValue = settings.get(
{ group: 'features', key: feature },
defaultValue
);
return settingValue;
}
/**

View File

@@ -1,4 +1,6 @@
import { Features, IFeatureConfiugration } from '@/interfaces';
import config from '@/config';
import { defaultTo } from 'lodash';
export const FeaturesConfigure: IFeatureConfiugration[] = [
{
@@ -9,4 +11,8 @@ export const FeaturesConfigure: IFeatureConfiugration[] = [
name: Features.WAREHOUSES,
defaultValue: false,
},
{
name: Features.BankSyncing,
defaultValue: defaultTo(config.bankSync.enabled, false),
}
];