Skip to content

Commit e864cba

Browse files
committed
feat: currency filter param
1 parent 41308fe commit e864cba

2 files changed

Lines changed: 9 additions & 5 deletions

File tree

constants/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,10 @@ export const SUPPORTED_QUOTES = [ // avoids hitting the DB every time for data t
144144
'usd' as SupportedQuotesType,
145145
'cad' as SupportedQuotesType
146146
]
147-
147+
export const SUPPORTED_QUOTES_FROM_ID: KeyValueT<SupportedQuotesType> = {
148+
1: 'usd',
149+
2: 'cad'
150+
}
148151
export const HUMAN_READABLE_DATE_FORMAT = 'YYYY-MM-DD'
149152

150153
export const PRICE_API_DATE_FORMAT = 'YYYY-MM-DD'

pages/api/paybutton/download/transactions/[paybuttonId].ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ import {
66
PAYBUTTON_TRANSACTIONS_FILE_HEADERS,
77
DECIMALS,
88
SUPPORTED_QUOTES,
9-
DEFAULT_QUOTE_SLUG,
109
SupportedQuotesType,
1110
NetworkTickersType,
1211
NETWORK_TICKERS,
13-
NETWORK_IDS
12+
NETWORK_IDS,
13+
SUPPORTED_QUOTES_FROM_ID
1414
} from 'constants/index'
1515
import { TransactionWithAddressAndPrices, fetchTransactionsByPaybuttonId, getTransactionValueInCurrency } from 'services/transactionService'
1616
import { PaybuttonWithAddresses, fetchPaybuttonById } from 'services/paybuttonService'
@@ -147,14 +147,15 @@ export default async (req: any, res: any): Promise<void> => {
147147
const networkTickerReq = req.query.network as string
148148

149149
const networkTicker = (networkTickerReq !== '' && isNetworkValid(networkTickerReq as NetworkTickersType)) ? networkTickerReq.toUpperCase() as NetworkTickersType : undefined
150-
150+
const quoteId = req.query.currency as number
151+
const quoteSlug = SUPPORTED_QUOTES_FROM_ID[quoteId]
151152
const paybutton = await fetchPaybuttonById(paybuttonId)
152153
if (paybutton.providerUserId !== userId) {
153154
throw new Error(RESPONSE_MESSAGES.RESOURCE_DOES_NOT_BELONG_TO_USER_400.message)
154155
}
155156

156157
res.setHeader('Content-Type', 'text/csv')
157-
await downloadPaybuttonTransactionsFile(res, paybutton, DEFAULT_QUOTE_SLUG, networkTicker)
158+
await downloadPaybuttonTransactionsFile(res, paybutton, quoteSlug, networkTicker)
158159
} catch (error: any) {
159160
switch (error.message) {
160161
case RESPONSE_MESSAGES.PAYBUTTON_ID_NOT_PROVIDED_400.message:

0 commit comments

Comments
 (0)