From b5f4bdc9abea522021d677e50d241cec6edffbe3 Mon Sep 17 00:00:00 2001 From: Kparikh9 Date: Sat, 19 Feb 2022 10:51:53 -0500 Subject: [PATCH] fix: replace filter interface with typescript partial interface --- server/infra/database/TransactionRepository.ts | 6 ++++-- server/models/Transaction.ts | 11 ++++++++--- server/routers/transactionsRouter.ts | 3 +-- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/server/infra/database/TransactionRepository.ts b/server/infra/database/TransactionRepository.ts index 73c740b6..cbd2cc02 100644 --- a/server/infra/database/TransactionRepository.ts +++ b/server/infra/database/TransactionRepository.ts @@ -1,4 +1,3 @@ -import Filter from 'interfaces/Filter'; import FilterOptions from 'interfaces/FilterOptions'; import Transaction from 'interfaces/Transaction'; import BaseRepository from './BaseRepository'; @@ -9,7 +8,10 @@ export default class TransactionRepository extends BaseRepository { 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 = ` diff --git a/server/models/Transaction.ts b/server/models/Transaction.ts index 50a26b95..00d93018 100644 --- a/server/models/Transaction.ts +++ b/server/models/Transaction.ts @@ -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 { - return async function (filter: Filter, options: FilterOptions) { +): ( + filter: Partial<{ token_id: string; wallet_id: string }>, + options: FilterOptions, +) => Promise { + return async function ( + filter: Partial<{ token_id: string; wallet_id: string }>, + options: FilterOptions, + ) { const transactions = await transactionRepository.getByFilter( filter, options, diff --git a/server/routers/transactionsRouter.ts b/server/routers/transactionsRouter.ts index 1195da8f..25797cff 100644 --- a/server/routers/transactionsRouter.ts +++ b/server/routers/transactionsRouter.ts @@ -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'; @@ -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) {