fix whenClause in item queries

This commit is contained in:
keyan 2023-09-28 16:25:02 -05:00
parent 0dad69111e
commit c63ae3c515
1 changed files with 22 additions and 22 deletions

View File

@ -75,28 +75,6 @@ export async function getItem (parent, { id }, { me, models }) {
return item
}
function whenClause (when, type) {
let interval = ` AND "${type === 'bookmarks' ? 'Bookmark' : 'Item'}".created_at >= $1 - INTERVAL `
switch (when) {
case 'forever':
interval = ''
break
case 'week':
interval += "'7 days'"
break
case 'month':
interval += "'1 month'"
break
case 'year':
interval += "'1 year'"
break
default:
interval += "'1 day'"
break
}
return interval
}
const orderByClause = async (by, me, models, type) => {
switch (by) {
case 'comments':
@ -207,6 +185,28 @@ export const whereClause = (...clauses) => {
return clause ? ` WHERE ${clause} ` : ''
}
function whenClause (when, type) {
let interval = `"${type === 'bookmarks' ? 'Bookmark' : 'Item'}".created_at >= $1 - INTERVAL `
switch (when) {
case 'forever':
interval = ''
break
case 'week':
interval += "'7 days'"
break
case 'month':
interval += "'1 month'"
break
case 'year':
interval += "'1 year'"
break
default:
interval += "'1 day'"
break
}
return interval
}
const activeOrMine = (me) => {
return me ? `("Item".status <> 'STOPPED' OR "Item"."userId" = ${me.id})` : '"Item".status <> \'STOPPED\''
}