From fd44b03834f80332c03f06c8b5c11998f79ec65b Mon Sep 17 00:00:00 2001 From: Frank Chen Date: Mon, 25 Jan 2021 00:04:02 +0000 Subject: [PATCH] refactor: Minor refactoring of the submissions client factory --- .../services/submissions.client.factory.js | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/public/modules/forms/services/submissions.client.factory.js b/src/public/modules/forms/services/submissions.client.factory.js index c478459d0a..815560dcff 100644 --- a/src/public/modules/forms/services/submissions.client.factory.js +++ b/src/public/modules/forms/services/submissions.client.factory.js @@ -46,6 +46,17 @@ function SubmissionsFactory( const publicSubmitUrl = '/v2/submissions/:responseMode/:formId' const previewSubmitUrl = '/v2/submissions/:responseMode/preview/:formId' + const generateDownloadUrl = (params, downloadAttachments) => { + let resUrl = `${fixParamsToUrl(params, submitAdminUrl)}/download?` + if (params.startDate && params.endDate) { + resUrl += `startDate=${params.startDate}&endDate=${params.endDate}&` + } + if (downloadAttachments) { + resUrl += `downloadAttachments=true&` + } + return resUrl + } + /** * Creates form data and submits as multi-part * @param {String} resUrl @@ -277,14 +288,7 @@ function SubmissionsFactory( }) } - let resUrl = `${fixParamsToUrl(params, submitAdminUrl)}/download?` - if (params.startDate && params.endDate) { - resUrl += `startDate=${params.startDate}&endDate=${params.endDate}&` - } - if (downloadAttachments) { - resUrl += `downloadAttachments=true&` - } - + let resUrl = generateDownloadUrl(params, downloadAttachments) let experimentalCsvGenerator = new CsvMHGenerator( expectedNumResponses, NUM_OF_METADATA_ROWS, @@ -399,7 +403,7 @@ function SubmissionsFactory( 'Failed to download data, is there a network issue?', err, ) - workerPool.forEach((worker) => worker.terminate()) + killWorkers(workerPool) reject(err) }) .finally(() => {