Skip to content

Commit

Permalink
Normalize registration data
Browse files Browse the repository at this point in the history
  • Loading branch information
tassoevan committed Sep 15, 2023
1 parent f6e9cd2 commit 57bf51a
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 24 deletions.
22 changes: 11 additions & 11 deletions apps/meteor/app/cloud/server/functions/buildRegistrationData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ type WorkspaceRegistrationData<T> = {
seats: number;
allowMarketing: SettingValue;
accountName: SettingValue;
organizationType: unknown;
industry: unknown;
orgSize: unknown;
country: unknown;
language: unknown;
organizationType: string;
industry: string;
orgSize: string;
country: string;
language: string;
agreePrivacyTerms: SettingValue;
website: SettingValue;
siteName: SettingValue;
Expand Down Expand Up @@ -61,15 +61,15 @@ export async function buildWorkspaceRegistrationData<T extends string | undefine
seats,
allowMarketing,
accountName,
organizationType,
industry,
orgSize,
country,
language,
organizationType: String(organizationType),
industry: String(industry),
orgSize: String(orgSize),
country: String(country),
language: String(language),
agreePrivacyTerms,
website,
siteName,
workspaceType,
workspaceType: String(workspaceType),
deploymentMethod: stats.deploy.method,
deploymentPlatform: stats.deploy.platform,
version: stats.version,
Expand Down
4 changes: 4 additions & 0 deletions apps/meteor/app/cloud/server/functions/syncWorkspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ const fetchSyncPayload = async ({ reconnectCheck = false }: { reconnectCheck?: b
body: info,
});

if (!response.ok) {
throw new CloudWorkspaceConnectionError(`Failed to connect to Rocket.Chat Cloud: ${response.statusText}`);
}

const payload = await response.json();

if (!payload) {
Expand Down
34 changes: 22 additions & 12 deletions apps/meteor/app/statistics/server/lib/statistics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ import { getAppsStatistics } from './getAppsStatistics';
import { getImporterStatistics } from './getImporterStatistics';
import { getServicesStatistics } from './getServicesStatistics';

const wizardFields = ['Organization_Type', 'Industry', 'Size', 'Country', 'Language', 'Server_Type', 'Register_Server'];

const getUserLanguages = async (totalUsers: number): Promise<{ [key: string]: number }> => {
const result = await Users.getUserLanguages();

Expand Down Expand Up @@ -70,17 +68,29 @@ export const statistics = {
const statistics = {} as IStats;
const statsPms = [];

const fetchWizardSettingValue = async <T>(settingName: string): Promise<T | undefined> => {
return ((await Settings.findOne(settingName))?.value as T | undefined) ?? undefined;
};

// Setup Wizard
statistics.wizard = {};
await Promise.all(
wizardFields.map(async (field) => {
const record = await Settings.findOne(field);
if (record) {
const wizardField = field.replace(/_/g, '').replace(field[0], field[0].toLowerCase());
statistics.wizard[wizardField] = record.value;
}
}),
);
const [organizationType, industry, size, country, language, serverType, registerServer] = await Promise.all([
fetchWizardSettingValue<string>('Organization_Type'),
fetchWizardSettingValue<string>('Industry'),
fetchWizardSettingValue<string>('Size'),
fetchWizardSettingValue<string>('Country'),
fetchWizardSettingValue<string>('Language'),
fetchWizardSettingValue<string>('Server_Type'),
fetchWizardSettingValue<boolean>('Register_Server'),
]);
statistics.wizard = {
organizationType,
industry,
size,
country,
language,
serverType,
registerServer,
};

// Version
const uniqueID = await Settings.findOne('uniqueID');
Expand Down
10 changes: 9 additions & 1 deletion packages/core-typings/src/IStats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,15 @@ import type { ITeamStats } from './ITeam';

export interface IStats {
_id: string;
wizard: Record<string, unknown>;
wizard: {
organizationType?: string;
industry?: string;
size?: string;
country?: string;
language?: string;
serverType?: string;
registerServer?: boolean;
};
uniqueId: string;
installedAt?: string;
version?: string;
Expand Down

0 comments on commit 57bf51a

Please sign in to comment.