From 13da65667ae40c16fef5154dd52f60aea9ff212e Mon Sep 17 00:00:00 2001 From: Kunal Zanke <50258809+kunalznk@users.noreply.github.com> Date: Thu, 16 Mar 2023 19:46:47 +0530 Subject: [PATCH] fix: #291 tress order by default time_created --- server/routers/treesRouter.ts | 10 ++++------ server/routers/treesRouterV2.ts | 10 ++++------ 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/server/routers/treesRouter.ts b/server/routers/treesRouter.ts index a99357c0..6fb8d738 100644 --- a/server/routers/treesRouter.ts +++ b/server/routers/treesRouter.ts @@ -76,16 +76,14 @@ router.get( const options: FilterOptions = { limit, offset, + orderBy: { + column: order_by || 'time_created', + direction: desc === true ? 'desc' : 'asc', + }, }; if (planter_id) { filter.planter_id = planter_id; - if (order_by) { - options.orderBy = { - column: order_by === 'created_at' ? 'time_created' : order_by, - direction: desc === true ? 'desc' : 'asc', - }; - } } else if (organization_id) { filter.organization_id = organization_id; } else if (startDate && endDate) { diff --git a/server/routers/treesRouterV2.ts b/server/routers/treesRouterV2.ts index 6e15af1c..81e0cc4d 100644 --- a/server/routers/treesRouterV2.ts +++ b/server/routers/treesRouterV2.ts @@ -76,16 +76,14 @@ router.get( const options: FilterOptions = { limit, offset, + orderBy: { + column: order_by || 'time_created', + direction: desc === true ? 'desc' : 'asc', + }, }; if (planter_id) { filter.planter_id = planter_id; - if (order_by) { - options.orderBy = { - column: order_by === 'created_at' ? 'time_created' : order_by, - direction: desc === true ? 'desc' : 'asc', - }; - } } else if (organization_id) { filter.organization_id = organization_id; } else if (startDate && endDate) {