From e5e07117d1e26e94629e50ff5ed3e60ab168f457 Mon Sep 17 00:00:00 2001 From: Andrew Hyndman Date: Mon, 30 Oct 2023 22:08:11 -0400 Subject: [PATCH] Improve naming for archive toggling method Also add a couple doc comments for additional clarity. --- .../src/arpa_reporter/views/Subrecipients.vue | 16 ++++++++++++---- .../src/arpa_reporter/db/arpa-subrecipients.js | 9 +++++++-- .../src/arpa_reporter/routes/subrecipients.js | 4 ++-- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/packages/client/src/arpa_reporter/views/Subrecipients.vue b/packages/client/src/arpa_reporter/views/Subrecipients.vue index 858456d762..0f48400496 100644 --- a/packages/client/src/arpa_reporter/views/Subrecipients.vue +++ b/packages/client/src/arpa_reporter/views/Subrecipients.vue @@ -50,8 +50,8 @@ Edit - - + + @@ -136,13 +136,21 @@ export default { this.$refs.recipientsTable.changeSort([]); }, - async archiveSubrecipient(id) { + /** + * Archive or restore a subrecipient. + * + * Call this method to taggle the `is_archived` flag for a subrecipient record. + * + * @param {*} id + * The ID of the subrecipient to archive or restore. + */ + async archiveOrRestoreSubrecipient(id) { this.loading = true; const result = await post(`/api/subrecipients/archive/${id}`); if (result.error) { this.$store.commit('addAlert', { - text: `archiveSubrecipient Error (${result.status}): ${result.error}`, + text: `archiveOrRestoreSubrecipient Error (${result.status}): ${result.error}`, level: 'err', }); } else { diff --git a/packages/server/src/arpa_reporter/db/arpa-subrecipients.js b/packages/server/src/arpa_reporter/db/arpa-subrecipients.js index 3d57e04885..9931c38c8c 100644 --- a/packages/server/src/arpa_reporter/db/arpa-subrecipients.js +++ b/packages/server/src/arpa_reporter/db/arpa-subrecipients.js @@ -14,7 +14,12 @@ function baseQuery(trns) { .leftJoin('users AS users2', 'arpa_subrecipients.updated_by', 'users2.id'); } -async function archiveRecipient(id, { updatedByUser }, trns = knex) { +/** + * Archive or restore a subrecipient. + * + * Call t his method to toggle the `is_archived` column in the arpa_subrecipients table. + */ +async function archiveOrRestoreRecipient(id, { updatedByUser }, trns = knex) { const query = trns('arpa_subrecipients') .where('id', id) .returning('*'); @@ -89,7 +94,7 @@ async function listRecipientsForReportingPeriod(periodId, trns = knex) { } module.exports = { - archiveRecipient, + archiveOrRestoreRecipient, createRecipient, getRecipient, findRecipient, diff --git a/packages/server/src/arpa_reporter/routes/subrecipients.js b/packages/server/src/arpa_reporter/routes/subrecipients.js index 74db4ad1c5..5a7e960a4e 100644 --- a/packages/server/src/arpa_reporter/routes/subrecipients.js +++ b/packages/server/src/arpa_reporter/routes/subrecipients.js @@ -4,7 +4,7 @@ const router = express.Router(); const { requireUser } = require('../../lib/access-helpers'); const { - listRecipients, getRecipient, updateRecipient, archiveRecipient, + listRecipients, getRecipient, updateRecipient, archiveOrRestoreRecipient, } = require('../db/arpa-subrecipients'); const { getRules } = require('../services/validation-rules'); @@ -59,7 +59,7 @@ router.post('/archive/:id', requireUser, async (req, res) => { return; } - const updatedRecipient = await archiveRecipient(recipient.id, { updatedByUser: user }); + const updatedRecipient = await archiveOrRestoreRecipient(recipient.id, { updatedByUser: user }); res.json({ recipient: updatedRecipient }); });