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) {