Skip to content

Commit

Permalink
feat: /wallets query parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
pranavkparti committed Oct 3, 2023
1 parent b8556f2 commit 9ae9487
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 13 deletions.
16 changes: 8 additions & 8 deletions server/models/Wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,20 +143,20 @@ class Wallet {
id,
limitOptions,
name,
// sort_by,
// order,
// created_at_start_date,
// created_at_end_date,
sort_by,
order,
created_at_start_date,
created_at_end_date,
getCount,
) {
return this._walletRepository.getAllWallets(
id,
limitOptions,
name,
// sort_by,
// order,
// created_at_start_date,
// created_at_end_date,
sort_by,
order,
created_at_start_date,
created_at_end_date,
getCount,
);
}
Expand Down
24 changes: 19 additions & 5 deletions server/repositories/WalletRepository.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ class WalletRepository extends BaseRepository {
id,
limitOptions,
name,
// sort_by,
// order,
// created_at_start_date,
// created_at_end_date,
sort_by,
order,
created_at_start_date,
created_at_end_date,
getCount,
) {
let query = this._session
Expand Down Expand Up @@ -111,7 +111,21 @@ class WalletRepository extends BaseRepository {
union2 = union2.where('name', 'ilike', `%${name}%`);
}

query = query.union(union1, union2);
query = query.union(union1, union2).orderBy(sort_by, order);

query = this._session.getDB().select('*').from(query.as('t'));

if (created_at_start_date) {
query = query.whereRaw(`cast("created_at" as date) >= ?`, [
created_at_start_date,
]);
}

if (created_at_end_date) {
query = query.whereRaw(`cast("created_at" as date) <= ?`, [
created_at_end_date,
]);
}

// total count query (before applying limit and offset options)
const countQuery = this._session
Expand Down
4 changes: 4 additions & 0 deletions server/services/WalletService.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ class WalletService {
id,
limitOptions,
name,
sort_by,
order,
created_at_start_date,
created_at_end_date,
getWalletCount,
);
return {
Expand Down

0 comments on commit 9ae9487

Please sign in to comment.