mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 04:40:32 +00:00
add server to monorepo.
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
import { Service, Inject } from 'typedi';
|
||||
import HasTenancyService from '@/services/Tenancy/TenancyService';
|
||||
import { FeaturesConfigure } from './constants';
|
||||
import { IFeatureAllItem } from '@/interfaces';
|
||||
|
||||
@Service()
|
||||
export class FeaturesSettingsDriver {
|
||||
@Inject()
|
||||
tenancy: HasTenancyService;
|
||||
|
||||
/**
|
||||
* Turns-on the given feature name.
|
||||
* @param {number} tenantId
|
||||
* @param {string} feature
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
async turnOn(tenantId: number, feature: string) {
|
||||
const settings = this.tenancy.settings(tenantId);
|
||||
|
||||
settings.set({ group: 'features', key: feature, value: true });
|
||||
}
|
||||
|
||||
/**
|
||||
* Turns-off the given feature name.
|
||||
* @param {number} tenantId
|
||||
* @param {string} feature
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
async turnOff(tenantId: number, feature: string) {
|
||||
const settings = this.tenancy.settings(tenantId);
|
||||
|
||||
settings.set({ group: 'features', key: feature, value: false });
|
||||
}
|
||||
|
||||
/**
|
||||
* Detarmines the given feature name is accessiable.
|
||||
* @param {number} tenantId
|
||||
* @param {string} feature
|
||||
* @returns {Promise<boolean|null|undefined>}
|
||||
*/
|
||||
async accessible(tenantId: number, feature: string) {
|
||||
const settings = this.tenancy.settings(tenantId);
|
||||
|
||||
return !!settings.get({ group: 'features', key: feature });
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the all features and their accessible value and default value.
|
||||
* @param {number} tenantId
|
||||
* @returns {Promise<IFeatureAllItem>}
|
||||
*/
|
||||
async all(tenantId: number): Promise<IFeatureAllItem[]> {
|
||||
const mappedOpers = FeaturesConfigure.map(async (featureConfigure) => {
|
||||
const { name, defaultValue } = featureConfigure;
|
||||
const isAccessible = await this.accessible(
|
||||
tenantId,
|
||||
featureConfigure.name
|
||||
);
|
||||
return { name, isAccessible, defaultAccessible: defaultValue };
|
||||
});
|
||||
return Promise.all(mappedOpers);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user