Fixed value destructuring for null values (#20803)

ref 4267ff9

Found while testing other code. Appears to fail destructuring which
prevents the job from running.
This commit is contained in:
Steve Larson 2024-08-20 14:04:35 -05:00 committed by GitHub
parent 4267ff9be6
commit 8e1f5529c7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -20,9 +20,9 @@ module.exports = {
const startDate = new Date(); const startDate = new Date();
// separate queries is much faster than using max/greatest (with coalesce to handle nulls) across columns // separate queries is much faster than using max/greatest (with coalesce to handle nulls) across columns
let {maxOpenedAt} = events.includes('opened') ? await db.knex('email_recipients').select(db.knex.raw('MAX(opened_at) as maxOpenedAt')).first() : null; let maxOpenedAt = events.includes('opened') ? await db.knex('email_recipients').select(db.knex.raw('MAX(opened_at) as maxOpenedAt')).first().maxOpenedAt : null;
let {maxDeliveredAt} = events.includes('delivered') ? await db.knex('email_recipients').select(db.knex.raw('MAX(delivered_at) as maxDeliveredAt')).first() : null; let maxDeliveredAt = events.includes('delivered') ? await db.knex('email_recipients').select(db.knex.raw('MAX(delivered_at) as maxDeliveredAt')).first().maxDeliveredAt : null;
let {maxFailedAt} = events.includes('failed') ? await db.knex('email_recipients').select(db.knex.raw('MAX(failed_at) as maxFailedAt')).first() : null; let maxFailedAt = events.includes('failed') ? await db.knex('email_recipients').select(db.knex.raw('MAX(failed_at) as maxFailedAt')).first().maxFailedAt : null;
if (maxOpenedAt && !(maxOpenedAt instanceof Date)) { if (maxOpenedAt && !(maxOpenedAt instanceof Date)) {
// SQLite returns a string instead of a Date // SQLite returns a string instead of a Date