Skip to content

Commit

Permalink
fix: update submissions query to work correctly and be a bit clearer
Browse files Browse the repository at this point in the history
  • Loading branch information
lucas committed May 10, 2021
1 parent 1e7c4ac commit 929d80a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
4 changes: 2 additions & 2 deletions lib/api/getSubmissions.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ module.exports = {
},
};

const getSubmissions = (context, { identifier, fromDate, toDate, formPublished, limit, page }) => {
return submissionsQuery(context, { identifier, fromDate, toDate, formPublished }).then(submissions => {
const getSubmissions = (context, { identifier, fromDate, toDate, showDraftSubmissions, limit, page }) => {
return submissionsQuery(context, { identifier, fromDate, toDate, showDraftSubmissions }).then(submissions => {
return {
formSubmissions: take(drop(submissions, limit * (page - 1)), limit),
total: submissions.length,
Expand Down
13 changes: 9 additions & 4 deletions lib/api/submissionsQuery.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
module.exports = ({ $mongo: { $db, $dbPub } }, { identifier, fromDate, toDate, formPublished }) => {
module.exports = ({ $mongo: { $db, $dbPub } }, { identifier, fromDate, toDate, showDraftSubmissions }) => {
const query = {};

if (identifier) query['settings.identifier'] = { $regex: identifier, $options: 'i' };

if (fromDate && fromDate !== 'undefined') {
fromDate = new Date(fromDate);
if (!query.$and) query.$and = [];
query.$and.push({ createdAt: { $gte: fromDate } });
}

if (toDate && toDate !== 'undefined') {
toDate = new Date(toDate);
if (!query.$and) query.$and = [];
query.$and.push({ createdAt: { $lte: toDate } });
}

if (formPublished === 'true') {
return $dbPub.collection('formSubmissions').find(query).sort({ createdAt: -1 }).toArray();
if (showDraftSubmissions) {
console.log('true, draft submissions only');
return $db.collection('formSubmissions').find(query).sort({ createdAt: -1 }).toArray();
}
return $db.collection('formSubmissions').find(query).sort({ createdAt: -1 }).toArray();

console.log('false, pub submissions');
return $dbPub.collection('formSubmissions').find(query).sort({ createdAt: -1 }).toArray();
};
12 changes: 5 additions & 7 deletions lib/components/FormSubmissions/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@
<div class="whppt-dashboard__wrapper">
<div class="whppt-dashboard__form">
<div class="whppt-filters-wrapper">
<whppt-checkbox
v-model="formPublished"
label="Show draft Submissions"
@change="fetchFormData(true)"
></whppt-checkbox>
<whppt-checkbox v-model="showDraftSubmissions" label="Show draft Submissions" @change="fetchFormData(true)" />
<whppt-button v-if="!filtersVisible" class="whppt-filters-button" @click="filtersVisible = true">
Show Filters
</whppt-button>
Expand Down Expand Up @@ -106,7 +102,7 @@ export default {
dialogActive: false,
selectedItem: undefined,
allSubmissions: [],
formPublished: false,
showDraftSubmissions: false,
}),
computed: {
items() {
Expand Down Expand Up @@ -146,7 +142,7 @@ export default {
const params = {
...this.filters,
formPublished: this.formPublished,
showDraftSubmissions: this.showDraftSubmissions || undefined,
limit: this.limit,
page: this.currentPage,
};
Expand Down Expand Up @@ -190,6 +186,8 @@ $primary-600: #5a67d8;
display: flex;
justify-content: space-between;
align-items: center;
min-height: 3rem;
margin-bottom: 0.5rem;
}
.whppt-filters-button {
margin-left: auto;
Expand Down

0 comments on commit 929d80a

Please sign in to comment.