diff --git a/app/definitions/IServer.ts b/app/definitions/IServer.ts index 3f36d7feb..9eee6ee82 100644 --- a/app/definitions/IServer.ts +++ b/app/definitions/IServer.ts @@ -1,5 +1,7 @@ import Model from '@nozbe/watermelondb/Model'; +import { IEnterpriseModules } from '../reducers/enterpriseModules'; + export interface IServer { name: string; iconURL: string; @@ -13,7 +15,7 @@ export interface IServer { autoLockTime?: number; biometry?: boolean; uniqueID: string; - enterpriseModules: string; + enterpriseModules: IEnterpriseModules; E2E_Enable: boolean; } diff --git a/app/lib/methods/enterpriseModules.js b/app/lib/methods/enterpriseModules.ts similarity index 82% rename from app/lib/methods/enterpriseModules.js rename to app/lib/methods/enterpriseModules.ts index 34313074d..8769e3818 100644 --- a/app/lib/methods/enterpriseModules.js +++ b/app/lib/methods/enterpriseModules.ts @@ -1,11 +1,12 @@ +import sdk from '../rocketchat/services/sdk'; import { compareServerVersion } from '../utils'; import { store as reduxStore } from '../auxStore'; import database from '../database'; import log from '../../utils/log'; import { clearEnterpriseModules, setEnterpriseModules as setEnterpriseModulesAction } from '../../actions/enterpriseModules'; -export const LICENSE_OMNICHANNEL_MOBILE_ENTERPRISE = 'omnichannel-mobile-enterprise'; -export const LICENSE_LIVECHAT_ENTERPRISE = 'livechat-enterprise'; +const LICENSE_OMNICHANNEL_MOBILE_ENTERPRISE = 'omnichannel-mobile-enterprise'; +const LICENSE_LIVECHAT_ENTERPRISE = 'livechat-enterprise'; export async function setEnterpriseModules() { try { @@ -29,17 +30,17 @@ export async function setEnterpriseModules() { } export function getEnterpriseModules() { - return new Promise(async resolve => { + return new Promise(async resolve => { try { const { version: serverVersion, server: serverId } = reduxStore.getState().server; if (compareServerVersion(serverVersion, 'greaterThanOrEqualTo', '3.1.0')) { // RC 3.1.0 - const enterpriseModules = await this.methodCallWrapper('license:getModules'); + const enterpriseModules = await sdk.methodCallWrapper('license:getModules'); if (enterpriseModules) { const serversDB = database.servers; const serversCollection = serversDB.get('servers'); const server = await serversCollection.find(serverId); - await serversDB.action(async () => { + await serversDB.write(async () => { await server.update(s => { s.enterpriseModules = enterpriseModules.join(','); }); @@ -56,7 +57,7 @@ export function getEnterpriseModules() { }); } -export function hasLicense(module) { +export function hasLicense(module: string) { const { enterpriseModules } = reduxStore.getState(); return enterpriseModules.includes(module); } diff --git a/app/lib/utils.ts b/app/lib/utils.ts index bece818b2..3a0e58e12 100644 --- a/app/lib/utils.ts +++ b/app/lib/utils.ts @@ -18,7 +18,7 @@ const methods = { }; export const compareServerVersion = ( - currentServerVersion: string, + currentServerVersion: string | null, method: keyof typeof methods, versionToCompare: string ): boolean => diff --git a/app/reducers/enterpriseModules.ts b/app/reducers/enterpriseModules.ts index 78616e246..fbd9fd52f 100644 --- a/app/reducers/enterpriseModules.ts +++ b/app/reducers/enterpriseModules.ts @@ -1,7 +1,7 @@ import { TActionEnterpriseModules } from '../actions/enterpriseModules'; import { ENTERPRISE_MODULES } from '../actions/actionsTypes'; -export type IEnterpriseModules = 'omnichannel-mobile-enterprise' | 'livechat-enterprise'; +export type IEnterpriseModules = string; export const initialState: IEnterpriseModules[] = [];