From c63ae3c51554061d37f96476c9a0dcac97ea695d Mon Sep 17 00:00:00 2001 From: keyan Date: Thu, 28 Sep 2023 16:25:02 -0500 Subject: [PATCH] fix whenClause in item queries --- api/resolvers/item.js | 44 +++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/api/resolvers/item.js b/api/resolvers/item.js index 8a02cf92..ae12bbaf 100644 --- a/api/resolvers/item.js +++ b/api/resolvers/item.js @@ -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\'' }