diff --git a/server/routers/treesRouter.ts b/server/routers/treesRouter.ts index 6fb8d738..a99357c0 100644 --- a/server/routers/treesRouter.ts +++ b/server/routers/treesRouter.ts @@ -76,14 +76,16 @@ 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) {