Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Minor refactoring of the submissions client factory #1040

Merged
merged 1 commit into from
Jan 25, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions src/public/modules/forms/services/submissions.client.factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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(() => {
Expand Down