Skip to content

Commit

Permalink
Adding ability to count live and draft submissions
Browse files Browse the repository at this point in the history
  • Loading branch information
l-gorman committed Jul 12, 2022
1 parent 805a222 commit dd0bc9c
Showing 1 changed file with 34 additions and 10 deletions.
44 changes: 34 additions & 10 deletions routes/metaData.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,16 @@ async function getSubmissionCounts(props) {


const token = await getCentralAuthToken()
const centralResponse = await axios({

let submissions = {
live:0,
draft:0
}

if (form.draft==true){
const centralResponseDraft = await axios({
method: "get",
url: url,
url: url.draft,
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + token
Expand All @@ -97,24 +104,41 @@ async function getSubmissionCounts(props) {
console.log(error)
throw error
})
submissions.draft = centralResponseDraft.data.length


}
if (form.live===true){

const centralResponseLive = await axios({
method: "get",
url: url.live,
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + token
},
})
.catch(function (error) {
console.log(error)
throw error
})


const number_of_submissions = centralResponse.data.length
submissions.live = centralResponseLive.data.length

return number_of_submissions
}
return submissions

}

function BuildSubmissionURL(props) {


if (props.form.live === true) {
return process.env.CENTRAL_URL + '/v1/projects/' + props.project.centralID + '/forms/' + props.form.centralID + '/submissions'
let submission_urls = {
live: process.env.CENTRAL_URL + '/v1/projects/' + props.project.centralID + '/forms/' + props.form.centralID + '/submissions',
draft: process.env.CENTRAL_URL + '/v1/projects/' + props.project.centralID + '/forms/' + props.form.centralID + '/draft/submissions'
}

if (props.form.draft = true) {
return process.env.CENTRAL_URL + '/v1/projects/' + props.project.centralID + '/forms/' + props.form.centralID + '/draft/submissions'
}
return submission_urls
}

module.exports = router
Expand Down

0 comments on commit dd0bc9c

Please sign in to comment.