Chore: Migrate methods/enterpriseModules to TS (#3706)
Co-authored-by: Diego Mello <diegolmello@gmail.com>
This commit is contained in:
parent
e58bdb8fe7
commit
c5cc192dc9
|
@ -1,5 +1,7 @@
|
||||||
import Model from '@nozbe/watermelondb/Model';
|
import Model from '@nozbe/watermelondb/Model';
|
||||||
|
|
||||||
|
import { IEnterpriseModules } from '../reducers/enterpriseModules';
|
||||||
|
|
||||||
export interface IServer {
|
export interface IServer {
|
||||||
name: string;
|
name: string;
|
||||||
iconURL: string;
|
iconURL: string;
|
||||||
|
@ -13,7 +15,7 @@ export interface IServer {
|
||||||
autoLockTime?: number;
|
autoLockTime?: number;
|
||||||
biometry?: boolean;
|
biometry?: boolean;
|
||||||
uniqueID: string;
|
uniqueID: string;
|
||||||
enterpriseModules: string;
|
enterpriseModules: IEnterpriseModules;
|
||||||
E2E_Enable: boolean;
|
E2E_Enable: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
|
import sdk from '../rocketchat/services/sdk';
|
||||||
import { compareServerVersion } from '../utils';
|
import { compareServerVersion } from '../utils';
|
||||||
import { store as reduxStore } from '../auxStore';
|
import { store as reduxStore } from '../auxStore';
|
||||||
import database from '../database';
|
import database from '../database';
|
||||||
import log from '../../utils/log';
|
import log from '../../utils/log';
|
||||||
import { clearEnterpriseModules, setEnterpriseModules as setEnterpriseModulesAction } from '../../actions/enterpriseModules';
|
import { clearEnterpriseModules, setEnterpriseModules as setEnterpriseModulesAction } from '../../actions/enterpriseModules';
|
||||||
|
|
||||||
export const LICENSE_OMNICHANNEL_MOBILE_ENTERPRISE = 'omnichannel-mobile-enterprise';
|
const LICENSE_OMNICHANNEL_MOBILE_ENTERPRISE = 'omnichannel-mobile-enterprise';
|
||||||
export const LICENSE_LIVECHAT_ENTERPRISE = 'livechat-enterprise';
|
const LICENSE_LIVECHAT_ENTERPRISE = 'livechat-enterprise';
|
||||||
|
|
||||||
export async function setEnterpriseModules() {
|
export async function setEnterpriseModules() {
|
||||||
try {
|
try {
|
||||||
|
@ -29,17 +30,17 @@ export async function setEnterpriseModules() {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getEnterpriseModules() {
|
export function getEnterpriseModules() {
|
||||||
return new Promise(async resolve => {
|
return new Promise<void>(async resolve => {
|
||||||
try {
|
try {
|
||||||
const { version: serverVersion, server: serverId } = reduxStore.getState().server;
|
const { version: serverVersion, server: serverId } = reduxStore.getState().server;
|
||||||
if (compareServerVersion(serverVersion, 'greaterThanOrEqualTo', '3.1.0')) {
|
if (compareServerVersion(serverVersion, 'greaterThanOrEqualTo', '3.1.0')) {
|
||||||
// RC 3.1.0
|
// RC 3.1.0
|
||||||
const enterpriseModules = await this.methodCallWrapper('license:getModules');
|
const enterpriseModules = await sdk.methodCallWrapper('license:getModules');
|
||||||
if (enterpriseModules) {
|
if (enterpriseModules) {
|
||||||
const serversDB = database.servers;
|
const serversDB = database.servers;
|
||||||
const serversCollection = serversDB.get('servers');
|
const serversCollection = serversDB.get('servers');
|
||||||
const server = await serversCollection.find(serverId);
|
const server = await serversCollection.find(serverId);
|
||||||
await serversDB.action(async () => {
|
await serversDB.write(async () => {
|
||||||
await server.update(s => {
|
await server.update(s => {
|
||||||
s.enterpriseModules = enterpriseModules.join(',');
|
s.enterpriseModules = enterpriseModules.join(',');
|
||||||
});
|
});
|
||||||
|
@ -56,7 +57,7 @@ export function getEnterpriseModules() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function hasLicense(module) {
|
export function hasLicense(module: string) {
|
||||||
const { enterpriseModules } = reduxStore.getState();
|
const { enterpriseModules } = reduxStore.getState();
|
||||||
return enterpriseModules.includes(module);
|
return enterpriseModules.includes(module);
|
||||||
}
|
}
|
|
@ -18,7 +18,7 @@ const methods = {
|
||||||
};
|
};
|
||||||
|
|
||||||
export const compareServerVersion = (
|
export const compareServerVersion = (
|
||||||
currentServerVersion: string,
|
currentServerVersion: string | null,
|
||||||
method: keyof typeof methods,
|
method: keyof typeof methods,
|
||||||
versionToCompare: string
|
versionToCompare: string
|
||||||
): boolean =>
|
): boolean =>
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import { TActionEnterpriseModules } from '../actions/enterpriseModules';
|
import { TActionEnterpriseModules } from '../actions/enterpriseModules';
|
||||||
import { ENTERPRISE_MODULES } from '../actions/actionsTypes';
|
import { ENTERPRISE_MODULES } from '../actions/actionsTypes';
|
||||||
|
|
||||||
export type IEnterpriseModules = 'omnichannel-mobile-enterprise' | 'livechat-enterprise';
|
export type IEnterpriseModules = string;
|
||||||
|
|
||||||
export const initialState: IEnterpriseModules[] = [];
|
export const initialState: IEnterpriseModules[] = [];
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue