-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support archiving subrecipients #2164
Changes from all commits
f588d0f
a152fbe
1af680e
fef281b
b4a2970
33933a8
8b05e54
8a74b3f
aa675d5
d514442
f179015
7b12bc4
7799e8b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/** | ||
* @param { import("knex").Knex } knex | ||
* @returns { Promise<void> } | ||
*/ | ||
exports.up = function (knex) { | ||
return knex.schema.table('arpa_subrecipients', (table) => { | ||
table.timestamp('archived_at'); | ||
}); | ||
}; | ||
|
||
/** | ||
* @param { import("knex").Knex } knex | ||
* @returns { Promise<void> } | ||
*/ | ||
exports.down = function (knex) { | ||
return knex.schema.table('arpa_subrecipients', (table) => { | ||
table.dropColumn('archived_at'); | ||
}); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,29 @@ function baseQuery(trns) { | |
.leftJoin('users AS users2', 'arpa_subrecipients.updated_by', 'users2.id'); | ||
} | ||
|
||
/** | ||
* Archive or restore a subrecipient. | ||
* | ||
* Call t his method to archive or restore an arpa_subrecipients table. | ||
*/ | ||
async function archiveOrRestoreRecipient(id, { updatedByUser }, trns = knex) { | ||
const query = trns('arpa_subrecipients') | ||
.where('id', id) | ||
.returning('*'); | ||
|
||
if (updatedByUser) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this be required? At the very least, we might want to always update the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't have a strong opinion here. I just copied this pattern from the I did mark session as required in the API endpoint though, so it should always be set in practice. |
||
query.update('updated_by', updatedByUser.id); | ||
query.update('updated_at', knex.fn.now()); | ||
} | ||
|
||
query.update( | ||
'archived_at', | ||
knex.raw('CASE WHEN archived_at IS NULL THEN ?? ELSE NULL END', [knex.fn.now()]), | ||
); | ||
|
||
return query.then((rows) => rows[0]); | ||
} | ||
|
||
async function createRecipient(recipient, trns = knex) { | ||
const tenantId = useTenantId(); | ||
if (!(recipient.uei || recipient.tin)) { | ||
|
@@ -70,10 +93,11 @@ async function listRecipients(trns = knex) { | |
} | ||
|
||
async function listRecipientsForReportingPeriod(periodId, trns = knex) { | ||
return baseQuery(trns).where('reporting_period_id', periodId); | ||
return baseQuery(trns).where('reporting_period_id', periodId).whereNotNull('archived_at'); | ||
} | ||
|
||
module.exports = { | ||
archiveOrRestoreRecipient, | ||
createRecipient, | ||
getRecipient, | ||
findRecipient, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we want to leave the
console.log
in here?