Skip to content

Commit

Permalink
fix: replace filter interface with typescript partial interface
Browse files Browse the repository at this point in the history
  • Loading branch information
kparikh9 committed Feb 19, 2022
1 parent ee11b19 commit b5f4bdc
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
6 changes: 4 additions & 2 deletions server/infra/database/TransactionRepository.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import Filter from 'interfaces/Filter';
import FilterOptions from 'interfaces/FilterOptions';
import Transaction from 'interfaces/Transaction';
import BaseRepository from './BaseRepository';
Expand All @@ -9,7 +8,10 @@ export default class TransactionRepository extends BaseRepository<Transaction> {
super('wallet.transaction', session);
}

async getByFilter(filter: Filter, options: FilterOptions) {
async getByFilter(
filter: Partial<{ token_id: string; wallet_id: string }>,
options: FilterOptions,
) {
const { token_id, wallet_id } = filter;
const { limit, offset } = options;
let sql = `
Expand Down
11 changes: 8 additions & 3 deletions server/models/Transaction.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import TransactionRepository from 'infra/database/TransactionRepository';
import Filter from 'interfaces/Filter';
import FilterOptions from 'interfaces/FilterOptions';
import Transaction from 'interfaces/Transaction';

function getByFilter(
transactionRepository: TransactionRepository,
): (filter: Filter, options: FilterOptions) => Promise<Transaction[]> {
return async function (filter: Filter, options: FilterOptions) {
): (
filter: Partial<{ token_id: string; wallet_id: string }>,
options: FilterOptions,
) => Promise<Transaction[]> {
return async function (
filter: Partial<{ token_id: string; wallet_id: string }>,
options: FilterOptions,
) {
const transactions = await transactionRepository.getByFilter(
filter,
options,
Expand Down
3 changes: 1 addition & 2 deletions server/routers/transactionsRouter.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import express from 'express';
import Joi from 'joi';
import TransactionRepository from 'infra/database/TransactionRepository';
import Filter from 'interfaces/Filter';
import Transaction from 'models/Transaction';
import { handlerWrapper } from './utils';
import Session from '../infra/database/Session';
Expand All @@ -25,7 +24,7 @@ router.get(
limit = parseInt(limit);
offset = parseInt(offset);
const repo = new TransactionRepository(new Session());
const filter: Filter = {};
const filter: Partial<{ token_id: string; wallet_id: string }> = {};
if (token_id) {
filter.token_id = token_id;
} else if (wallet_id) {
Expand Down

0 comments on commit b5f4bdc

Please sign in to comment.