-
Notifications
You must be signed in to change notification settings - Fork 4
/
TradeQuery.ts
73 lines (64 loc) · 1.8 KB
/
TradeQuery.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import {Kit} from '../..';
import {
QueryTradesArgs, QueryTradesOrderByOrderByClause,
Trade,
TradePaginator, TradeType,
} from '../../interfaces/PoliticsAndWarGraphQL';
import GraphQL from '../../services/GraphQL';
export interface Parameters {
id?: number;
type?: TradeType | string;
first?: number;
page?: number;
nation_id?: string[];
offer_resource?: string;
buy_or_sell?: string;
accepted?: boolean;
orderBy?: QueryTradesOrderByOrderByClause
}
/**
* Gets a list of trades
* @param {Parameters} params Query parameters to customize your results
* @param {string} query The graphql query to get info with
* @param {boolean} paginator If true returns paginator info
* @return {Promise<Trade[] | TradePaginator>}
*/
export default async function tradeQuery(this: Kit, params: Parameters, query: string, paginator?: false): Promise<Trade[]>;
export default async function tradeQuery(this: Kit, params: Parameters, query: string, paginator: true): Promise<TradePaginator>;
export default async function tradeQuery(
this: Kit,
params: Parameters,
query: string,
paginator?: boolean,
): Promise<Trade[] | TradePaginator> {
const argsToParameters = GraphQL.generateParameters(params as QueryTradesArgs, ['type']);
const res = await GraphQL.makeCall(`
{
trades${argsToParameters} {
${
(paginator) ?
`
paginatorInfo {
count,
currentPage,
firstItem,
hasMorePages,
lastItem,
lastPage,
perPage,
total
},
`:''
}
data {
${query}
}
}
}
`, this.apiKey);
this.setRateLimit(res.rateLimit);
if (paginator) {
return res.data.trades as TradePaginator;
}
return res.data.trades.data as Trade[];
}