-
Notifications
You must be signed in to change notification settings - Fork 4
/
BountyQuery.ts
70 lines (62 loc) · 1.73 KB
/
BountyQuery.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
import {Kit} from '../..';
import {
Bounty,
BountyPaginator,
QueryBountiesArgs,
QueryBountiesOrderByOrderByClause,
} from '../../interfaces/PoliticsAndWarGraphQL';
import GraphQL from '../../services/GraphQL';
export interface Parameters {
nation_id?: number[];
min_amount?: number;
max_amount?: number;
first?: number;
page?: number;
orderBy?: QueryBountiesOrderByOrderByClause;
}
/**
* Gets a list of bounties
* @param {Parameters} params Query parameters to customize your results
* @param {string} query The graphql query to get info with
* @param {boolean} paginator If true it will return paginator info
* @return {Promise<Bounty[] | BountyPaginator>}
*/
export default async function bountyQuery(this: Kit, params: Parameters, query: string, paginator?: false): Promise<Bounty[]>;
export default async function bountyQuery(this: Kit, params: Parameters, query: string, paginator: true): Promise<BountyPaginator>;
export default async function bountyQuery(
this: Kit,
params: Parameters,
query: string,
paginator?: boolean,
): Promise<Bounty[] | BountyPaginator> {
const argsToParameters = GraphQL.generateParameters(params as QueryBountiesArgs);
const res = await GraphQL.makeCall(`
{
bounties${argsToParameters} {
${
(paginator) ?
`
paginatorInfo {
count,
currentPage,
firstItem,
hasMorePages,
lastItem,
lastPage,
perPage,
total
},
`:''
}
data {
${query}
}
}
}
`, this.apiKey);
this.setRateLimit(res.rateLimit);
if (paginator) {
return res.data.bounties;
}
return res.data.bounties.data as Bounty[];
}