refactor: extract the WITHIN_PAST_WEEK condition
This commit is contained in:
parent
0249005314
commit
374a4272a5
1 changed files with 9 additions and 3 deletions
|
|
@ -53,10 +53,12 @@ const getValidNotifications = (type, detail) => {
|
||||||
return db.any(sql, [type, detail]).catch(logger.error)
|
return db.any(sql, [type, detail]).catch(logger.error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const WITHIN_PAST_WEEK = `created > (CURRENT_TIMESTAMP - INTERVAL '7' DAY)`
|
||||||
|
|
||||||
const getNotifications = () => {
|
const getNotifications = () => {
|
||||||
const sql = `
|
const sql = `
|
||||||
SELECT * FROM notifications
|
SELECT * FROM notifications
|
||||||
WHERE valid AND created > (CURRENT_TIMESTAMP - INTERVAL '7' DAY)
|
WHERE valid AND ${WITHIN_PAST_WEEK}
|
||||||
ORDER BY created DESC
|
ORDER BY created DESC
|
||||||
`
|
`
|
||||||
return db.any(sql).catch(logger.error)
|
return db.any(sql).catch(logger.error)
|
||||||
|
|
@ -75,14 +77,18 @@ const hasUnreadNotifications = () => {
|
||||||
const sql = `
|
const sql = `
|
||||||
SELECT EXISTS
|
SELECT EXISTS
|
||||||
(SELECT * FROM notifications
|
(SELECT * FROM notifications
|
||||||
WHERE valid AND NOT read AND created > (CURRENT_TIMESTAMP - INTERVAL '7' DAY))
|
WHERE valid AND NOT read AND ${WITHIN_PAST_WEEK})
|
||||||
`
|
`
|
||||||
return db.oneOrNone(sql).then(res => res.exists).catch(logger.error)
|
return db.oneOrNone(sql).then(res => res.exists).catch(logger.error)
|
||||||
}
|
}
|
||||||
|
|
||||||
const getAlerts = () => {
|
const getAlerts = () => {
|
||||||
const types = ['fiatBalance', 'cryptoBalance', 'error']
|
const types = ['fiatBalance', 'cryptoBalance', 'error']
|
||||||
const sql = `SELECT * FROM notifications WHERE valid = 't' AND created > (CURRENT_TIMESTAMP - INTERVAL '7' DAY) AND type IN ($1:list) ORDER BY created DESC`
|
const sql = `
|
||||||
|
SELECT * FROM notifications
|
||||||
|
WHERE valid AND ${WITHIN_PAST_WEEK} AND type IN ($1:list)
|
||||||
|
ORDER BY created DESC
|
||||||
|
`
|
||||||
return db.any(sql, [types]).catch(logger.error)
|
return db.any(sql, [types]).catch(logger.error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue