Skip to content

Commit

Permalink
Improve naming for archive toggling method
Browse files Browse the repository at this point in the history
Also add a couple doc comments for additional clarity.
  • Loading branch information
Andrew Hyndman committed Dec 16, 2023
1 parent 439fca3 commit 2b4aacd
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
16 changes: 12 additions & 4 deletions packages/client/src/arpa_reporter/views/Subrecipients.vue
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@

<span class="d-flex flex-column" v-else-if="props.column.field === 'edit'" >
<router-link v-if="!props.row.is_archived" tag="button" class="btn btn-sm btn-secondary mb-2" :to="`/subrecipients/${props.row.id}`">Edit</router-link>
<button v-if="props.row.is_archived" class="btn btn-sm btn-primary" @click="archiveSubrecipient(props.row.id)">Restore</button>
<button v-else class="btn btn-sm btn-outline-danger" @click="archiveSubrecipient(props.row.id)">Archive</button>
<button v-if="props.row.is_archived" class="btn btn-sm btn-primary" @click="archiveOrRestoreSubrecipient(props.row.id)">Restore</button>
<button v-else class="btn btn-sm btn-outline-danger" @click="archiveOrRestoreSubrecipient(props.row.id)">Archive</button>
</span>

<span v-else>
Expand Down Expand Up @@ -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 {
Expand Down
9 changes: 7 additions & 2 deletions packages/server/src/arpa_reporter/db/arpa-subrecipients.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('*');
Expand Down Expand Up @@ -89,7 +94,7 @@ async function listRecipientsForReportingPeriod(periodId, trns = knex) {
}

module.exports = {
archiveRecipient,
archiveOrRestoreRecipient,
createRecipient,
getRecipient,
findRecipient,
Expand Down
4 changes: 2 additions & 2 deletions packages/server/src/arpa_reporter/routes/subrecipients.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down Expand Up @@ -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 });
});

Expand Down

0 comments on commit 2b4aacd

Please sign in to comment.