From f588d0f2e99db598c4627b488cf5a37b986bc3ca Mon Sep 17 00:00:00 2001 From: Andrew Hyndman Date: Sun, 29 Oct 2023 16:52:25 -0400 Subject: [PATCH 01/12] knex: Add is_archived col to subrecipients table --- ...29204021_add_subrecipients_archived_col.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 packages/server/migrations/20231029204021_add_subrecipients_archived_col.js diff --git a/packages/server/migrations/20231029204021_add_subrecipients_archived_col.js b/packages/server/migrations/20231029204021_add_subrecipients_archived_col.js new file mode 100644 index 000000000..76720f28b --- /dev/null +++ b/packages/server/migrations/20231029204021_add_subrecipients_archived_col.js @@ -0,0 +1,19 @@ +/** + * @param { import("knex").Knex } knex + * @returns { Promise } + */ +exports.up = function (knex) { + return knex.schema.table('arpa_subrecipients', (table) => { + table.boolean('is_archived').notNullable().defaultTo(false); + }); +}; + +/** + * @param { import("knex").Knex } knex + * @returns { Promise } + */ +exports.down = function (knex) { + return knex.schema.table('arpa_subrecipients', (table) => { + table.dropColumn('is_archived'); + }); +}; From a152fbea7a13c4e187ec41bd2d44fae8aaa0f016 Mon Sep 17 00:00:00 2001 From: Andrew Hyndman Date: Sun, 29 Oct 2023 17:31:12 -0400 Subject: [PATCH 02/12] Add db helper: archiveRecipient --- .../src/arpa_reporter/db/arpa-subrecipients.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/packages/server/src/arpa_reporter/db/arpa-subrecipients.js b/packages/server/src/arpa_reporter/db/arpa-subrecipients.js index 5c983e5da..c6cd57df7 100644 --- a/packages/server/src/arpa_reporter/db/arpa-subrecipients.js +++ b/packages/server/src/arpa_reporter/db/arpa-subrecipients.js @@ -14,6 +14,21 @@ function baseQuery(trns) { .leftJoin('users AS users2', 'arpa_subrecipients.updated_by', 'users2.id'); } +async function archiveRecipient(id, { updatedByUser }, trns = knex) { + const query = trns('arpa_subrecipients') + .where('id', id) + .returning('*'); + + if (updatedByUser) { + query.update('updated_by', updatedByUser.id); + query.update('updated_at', knex.fn.now()); + } + + query.update('is_archived', knex.raw('NOT ??', ['is_archived'])); + + return query.then((rows) => rows[0]); +} + async function createRecipient(recipient, trns = knex) { const tenantId = useTenantId(); if (!(recipient.uei || recipient.tin)) { @@ -74,6 +89,7 @@ async function listRecipientsForReportingPeriod(periodId, trns = knex) { } module.exports = { + archiveRecipient, createRecipient, getRecipient, findRecipient, From 1af680ec3e26361da6ba00ab4de8ba5f7b7b631e Mon Sep 17 00:00:00 2001 From: Andrew Hyndman Date: Sun, 29 Oct 2023 17:31:36 -0400 Subject: [PATCH 03/12] Add route: /api/subrecipients/archive/:id --- .../src/arpa_reporter/routes/subrecipients.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/packages/server/src/arpa_reporter/routes/subrecipients.js b/packages/server/src/arpa_reporter/routes/subrecipients.js index 83c3d8d36..74db4ad1c 100644 --- a/packages/server/src/arpa_reporter/routes/subrecipients.js +++ b/packages/server/src/arpa_reporter/routes/subrecipients.js @@ -3,7 +3,9 @@ const express = require('express'); const router = express.Router(); const { requireUser } = require('../../lib/access-helpers'); -const { listRecipients, getRecipient, updateRecipient } = require('../db/arpa-subrecipients'); +const { + listRecipients, getRecipient, updateRecipient, archiveRecipient, +} = require('../db/arpa-subrecipients'); const { getRules } = require('../services/validation-rules'); router.get('/', requireUser, async (req, res) => { @@ -46,6 +48,21 @@ router.post('/:id', requireUser, async (req, res) => { res.json({ recipient: updatedRecipient }); }); +router.post('/archive/:id', requireUser, async (req, res) => { + const id = Number(req.params.id); + const { user } = req.session; + + const recipient = await getRecipient(id); + if (!recipient || recipient.tenant_id !== req.session.user.tenant_id) { + res.sendStatus(404); + res.end(); + return; + } + + const updatedRecipient = await archiveRecipient(recipient.id, { updatedByUser: user }); + res.json({ recipient: updatedRecipient }); +}); + module.exports = router; // NOTE: This file was copied from src/server/routes/subrecipients.js (git @ ada8bfdc98) in the arpa-reporter repo on 2022-09-23T20:05:47.735Z From fef281bd9c13efa4ade35fbe343380e1671e6bec Mon Sep 17 00:00:00 2001 From: Andrew Hyndman Date: Sun, 29 Oct 2023 17:32:40 -0400 Subject: [PATCH 04/12] UI: Add archive/restore actions to subrecipients view --- .../src/arpa_reporter/views/Subrecipients.vue | 81 +++++++++++++------ 1 file changed, 55 insertions(+), 26 deletions(-) diff --git a/packages/client/src/arpa_reporter/views/Subrecipients.vue b/packages/client/src/arpa_reporter/views/Subrecipients.vue index 259fc085c..858456d76 100644 --- a/packages/client/src/arpa_reporter/views/Subrecipients.vue +++ b/packages/client/src/arpa_reporter/views/Subrecipients.vue @@ -1,3 +1,9 @@ + +