Skip to content

Commit

Permalink
fix: order by fields
Browse files Browse the repository at this point in the history
  • Loading branch information
dadiorchen committed Apr 6, 2022
1 parent 2b36956 commit d2546d8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
Empty file modified .husky/pre-commit
100644 → 100755
Empty file.
15 changes: 9 additions & 6 deletions server/models/Earnings.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ class Earnings {
case 'calculated_at':
orderBy = 'calculated_at';
break;
case 'paid_at':
orderBy = 'paid_at';
break;
default:
orderBy = undefined;
break;
Expand Down Expand Up @@ -135,8 +138,8 @@ class Earnings {

async getEarnings(filter, limitOptions) {
const filterCriteria = this.constructor.FilterCriteria({ ...filter });
const sortBy = filterCriteria?.sort_by;
const order = filterCriteria?.order;
const sortBy = filter.sort_by;
const { order } = filter;
const { earnings, count } = await this._earningsRepository.getEarnings(
filterCriteria,
limitOptions,
Expand All @@ -152,8 +155,8 @@ class Earnings {

if (sortBy === 'grower') {
formattedEarnings.sort((a, b) => {
const nameA = a.grower?.toUpperCase(); // ignore upper and lowercase
const nameB = b.grower?.toUpperCase(); // ignore upper and lowercase
const nameA = a.grower?.toUpperCase() || ""; // ignore upper and lowercase
const nameB = b.grower?.toUpperCase() || ""; // ignore upper and lowercase

if (nameA < nameB) {
return order === 'asc' ? -1 : 1;
Expand All @@ -166,8 +169,8 @@ class Earnings {
}
if (sortBy === 'funder') {
formattedEarnings.sort((a, b) => {
const nameA = a.funder?.toUpperCase(); // ignore upper and lowercase
const nameB = b.funder?.toUpperCase(); // ignore upper and lowercase
const nameA = a.funder?.toUpperCase() || ""; // ignore upper and lowercase
const nameB = b.funder?.toUpperCase() || ""; // ignore upper and lowercase
if (nameA < nameB) {
return order === 'asc' ? -1 : 1;
}
Expand Down

0 comments on commit d2546d8

Please sign in to comment.