Created
December 28, 2022 21:14
-
-
Save shreyakupadhyay/20c21ef312f92199ebde01c8c980e0dd to your computer and use it in GitHub Desktop.
Intermediate level typescript implementation of API response handling
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- common payload: stats associated with data --> | |
type StatsRange = { | |
max: number, min: number | |
} | |
type StatsKeys = 'count' | 'aum' | 'priceusd' | 'value' | |
interface PartialStats<Type extends string|number|symbol, RangeType> { | |
stats?: Partial<Record<Type, RangeType>> | |
} | |
<!-- common payload: pagination info --> | |
type Pagination = { | |
pagination?: { | |
currentPage: number, | |
perPage: number, | |
total: number, | |
totalPages: number | |
} | |
} | |
<!-- api: onboarding data --> | |
type APIResponseOnboards = { | |
count: number, | |
unixTimeStamp: number, | |
timestamp: string, | |
} | |
<!-- api: historical data --> | |
type APIResponseHistorical = { | |
aum: number, | |
unixTimeStamp: number, | |
} | |
<!-- api: wallets data --> | |
type APIResponseWallets = { | |
wid: number, | |
tenant: number, | |
portfolioValue: number, | |
address: string, | |
} | |
<!-- all api data handling --> | |
interface APIResponseData<Type> extends PartialStats<StatsKeys, StatsRange>, Pagination { | |
data : { | |
data: Type[], | |
field?: string, | |
grouping?: string | |
}[] | APIResponseWallets[], | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment