Skip to content

Commit

Permalink
renaming and removing unused functions
Browse files Browse the repository at this point in the history
  • Loading branch information
ktuite committed Nov 18, 2024
1 parent 0aa79c1 commit a80b6b3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
7 changes: 2 additions & 5 deletions lib/model/query/submissions.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,10 @@ createVersion.audit.withResult = true;
const update = (form, submission, data) => ({ one }) => one(updater(submission, data)).then(construct(Submission));
update.audit = (form, submission, data) => (log) => log('submission.update', form, Object.assign({ submissionId: submission.id, submissionDefId: submission.def.id, instanceId: submission.def.instanceId }, data));

const clearDraftSubmissions = (formId) => ({ run }) =>
run(sql`delete from submissions where "formId"=${formId} and draft=true`);

const clearDraftSubmissionsForProject = (projectId) => ({ run }) =>
run(sql`DELETE FROM submissions USING forms WHERE submissions."formId" = forms.id AND forms."projectId" = ${projectId} AND submissions.draft=true`);

const softDeleteDraftSubmissions = (formId) => ({ run }) =>
const deleteDraftSubmissions = (formId) => ({ run }) =>
run(sql`UPDATE submissions SET "deletedAt"=now() WHERE "formId"=${formId} AND "draft"=true AND "deletedAt" IS NULL`);

////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -478,7 +475,7 @@ select count(*) from deleted_submissions`);

module.exports = {
createNew, createVersion,
update, del, restore, purge, clearDraftSubmissions, clearDraftSubmissionsForProject, softDeleteDraftSubmissions,
update, del, restore, purge, clearDraftSubmissionsForProject, deleteDraftSubmissions,
setSelectMultipleValues, getSelectMultipleValuesForExport,
getByIdsWithDef, getSubAndDefById,
getByIds, getAllForFormByIds, getById, countByFormId, verifyVersion,
Expand Down
6 changes: 3 additions & 3 deletions lib/resources/forms.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ module.exports = (service, endpoint) => {
: getPartial(Forms, request, project, Keys)))
.then((partial) => Promise.all([
Forms.createVersion(partial, form, false),
Submissions.softDeleteDraftSubmissions(form.id)
Submissions.deleteDraftSubmissions(form.id)
]))
.then(() => Forms.clearUnneededDrafts(form))) // remove drafts made obsolete by new draft
.then(success)));
Expand All @@ -162,7 +162,7 @@ module.exports = (service, endpoint) => {
.then(() => Forms.getByProjectAndXmlFormId(params.projectId, params.id, false, Form.DraftVersion))
.then(getOrNotFound)
: resolve(form)))
.then(((form) => Promise.all([ Forms.publish(form), Submissions.softDeleteDraftSubmissions(form.id) ])))
.then(((form) => Promise.all([ Forms.publish(form), Submissions.deleteDraftSubmissions(form.id) ])))
.then(success)));

// Entity/Dataset-specific endpoint that is used to show how publishing
Expand Down Expand Up @@ -244,7 +244,7 @@ module.exports = (service, endpoint) => {
.then(rejectIf(((form) => form.draftDefId == null), noargs(Problem.user.notFound)))
.then((form) => Promise.all([
Forms.clearDraft(form).then(() => Forms.clearUnneededDrafts(form)),
Submissions.softDeleteDraftSubmissions(form.id),
Submissions.deleteDraftSubmissions(form.id),
Audits.log(auth.actor, 'form.update.draft.delete', form, { oldDraftDefId: form.draftDefId })
]))
.then(success)));
Expand Down

0 comments on commit a80b6b3

Please sign in to comment.