From a80b6b3b83dbf238e295c88fb564242d7cf0d2dc Mon Sep 17 00:00:00 2001 From: Kathleen Tuite Date: Mon, 18 Nov 2024 15:27:21 -0800 Subject: [PATCH] renaming and removing unused functions --- lib/model/query/submissions.js | 7 ++----- lib/resources/forms.js | 6 +++--- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/lib/model/query/submissions.js b/lib/model/query/submissions.js index c8dd3a954..303a97948 100644 --- a/lib/model/query/submissions.js +++ b/lib/model/query/submissions.js @@ -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`); //////////////////////////////////////////////////////////////////////////////// @@ -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, diff --git a/lib/resources/forms.js b/lib/resources/forms.js index 6899a22a6..15cf8f585 100644 --- a/lib/resources/forms.js +++ b/lib/resources/forms.js @@ -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))); @@ -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 @@ -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)));