Skip to content

Commit

Permalink
Merge pull request #293 from kunalznk/tree_order
Browse files Browse the repository at this point in the history
fix: #291 tress order by default time_created
  • Loading branch information
dadiorchen authored Mar 17, 2023
2 parents 6677cbb + 13da656 commit 6c7545a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
10 changes: 4 additions & 6 deletions server/routers/treesRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
10 changes: 4 additions & 6 deletions server/routers/treesRouterV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 6c7545a

Please sign in to comment.