diff --git a/packages/export-to-csv/src/commands/cm/export-to-csv.js b/packages/export-to-csv/src/commands/cm/export-to-csv.js index 35ceb046a2..96dee0c0aa 100644 --- a/packages/export-to-csv/src/commands/cm/export-to-csv.js +++ b/packages/export-to-csv/src/commands/cm/export-to-csv.js @@ -1,6 +1,7 @@ const {Command} = require('@contentstack/cli-command') const util = require('../../util/index') const ContentstackManagementSDK = require('@contentstack/management') +const config = require('../../util/config.js') class ExportToCsvCommand extends Command { @@ -15,7 +16,7 @@ class ExportToCsvCommand extends Command { const action = await util.startupQuestions() switch(action) { - case 'Export Entries to CSV': { + case config.exportEntries: { const organization = await util.chooseOrganization(this.managementAPIClient) // prompt for organization const stack = await util.chooseStack(this.managementAPIClient, organization.uid) // prompt for stack const contentTypes = await util.chooseContentType(this.managementAPIClient, stack.apiKey) // prompt for content Type @@ -31,7 +32,7 @@ class ExportToCsvCommand extends Command { } break; } - case 'Export Organization Users to CSV': { + case config.exportUsers: { try { const organization = await util.chooseOrganization(this.managementAPIClient, action) // prompt for organization const orgUsers = await util.getOrgUsers(this.managementAPIClient, organization.uid) diff --git a/packages/export-to-csv/src/util/config.js b/packages/export-to-csv/src/util/config.js index 2ace6655d2..22f5e0262d 100644 --- a/packages/export-to-csv/src/util/config.js +++ b/packages/export-to-csv/src/util/config.js @@ -1,3 +1,6 @@ module.exports = { - cancelString: 'Cancel and Exit' + cancelString: 'Cancel and Exit', + exportEntries: 'Export entries to a .CSV file', + exportUsers: 'Export organization users\' data to a .CSV file', + adminError: 'Unable to export data. Make sure you\'re an admin or owner of this organization' } \ No newline at end of file diff --git a/packages/export-to-csv/src/util/index.js b/packages/export-to-csv/src/util/index.js index 4ad6597384..df98a9b91a 100644 --- a/packages/export-to-csv/src/util/index.js +++ b/packages/export-to-csv/src/util/index.js @@ -11,7 +11,7 @@ const delimeter = (os.platform() === 'win32') ? '\\' : '/' function chooseOrganization(managementAPIClient, action) { return new Promise(async resolve => { let organizations - if (action === 'Export Organization Users to CSV') { + if (action === config.exportUsers) { organizations = await getOrganizationsWhereUserIsAdmin(managementAPIClient) } else { organizations = await getOrganizations(managementAPIClient) @@ -260,7 +260,7 @@ function startupQuestions() { type: 'list', name: 'action', message: 'Choose Action', - choices: ['Export entries to a .CSV file', 'Export organization users\' data to a .CSV file', 'Exit'], + choices: [config.exportEntries, config.exportUsers, 'Exit'], }] inquirer.prompt(actions).then(answers => { if(answers.action === 'Exit') @@ -277,7 +277,7 @@ function getOrgUsers(managementAPIClient, orgUid) { .then(response => { let organization = response.organizations.filter(org => org.uid === orgUid).pop() if (!organization.getInvitations) { - return reject(new Error('You need to be an admin for exporting this organization\'s users')) + return reject(new Error(config.adminError)) } organization.getInvitations().then(users => resolve(users)) }) @@ -304,7 +304,7 @@ function getOrgRoles(managementAPIClient, orgUid) { .then(response => { let organization = response.organizations.filter(org => org.uid === orgUid).pop() if (!organization.roles) { - return reject(new Error('You need to be an admin for exporting this organization\'s users')) + return reject(new Error(config.adminError)) } organization.roles().then(roles => resolve(roles)) })