Skip to content

Commit

Permalink
fix(worker): add accepted_at ts for invalid recipients (#2081)
Browse files Browse the repository at this point in the history
  • Loading branch information
stanleynguyen committed Jul 6, 2023
1 parent c15810b commit 4add756
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions worker/src/core/loaders/message-worker/util/govsg.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,15 @@ class Govsg {
}
})
if (invalidIdsDetectedFromFormat.length > 0) {
// Note: have to add accepted_at here though it doesn't make sense conceptually
// as the field is being used to check whether a campaign can be logged
await this.postmanConnection.query(
`UPDATE
govsg_ops
SET
status = 'INVALID_RECIPIENT', updated_at=clock_timestamp()
status = 'INVALID_RECIPIENT',
accepted_at=clock_timestamp(),
updated_at=clock_timestamp()
WHERE
id IN (:ids);`,
{
Expand Down Expand Up @@ -139,13 +143,17 @@ class Govsg {
)
// update govsg_ops table with invalid messages
if (invalidMessages.length > 0) {
// Note: have to add accepted_at here though it doesn't make sense conceptually
// as the field is being used to check whether a campaign can be logged
await this.postmanConnection.query(
`UPDATE
govsg_ops
SET
status = 'INVALID_RECIPIENT', updated_at=clock_timestamp()
WHERE
id IN (:ids);`,
govsg_ops
SET
status = 'INVALID_RECIPIENT',
accepted_at=clock_timestamp(),
updated_at=clock_timestamp()
WHERE
id IN (:ids);`,
{
replacements: { ids: invalidMessages.map((message) => message.id) },
type: QueryTypes.UPDATE,
Expand Down Expand Up @@ -218,8 +226,12 @@ class Govsg {
})
} catch (error: any) {
if ((error as { errorCode: string }).errorCode === 'invalid_recipient') {
// Note: have to add accepted_at here though it doesn't make sense conceptually
// as the field is being used to check whether a campaign can be logged
await this.postmanConnection.query(
`UPDATE govsg_ops SET status='INVALID_RECIPIENT', updated_at=clock_timestamp()
`UPDATE govsg_ops SET status='INVALID_RECIPIENT',
accepted_at=clock_timestamp(),
updated_at=clock_timestamp()
where id=:id`,
{
replacements: {
Expand Down

0 comments on commit 4add756

Please sign in to comment.