1 | |
2 | type Motimate = { |
3 | token: string |
4 | } |
5 |
|
6 | export async function main( |
7 | auth: Motimate, |
8 | filter_id_: string | undefined, |
9 | filter_chapter_id_: string | undefined, |
10 | filter_user_id_: string | undefined, |
11 | filter_user_external_id_: string | undefined, |
12 | filter_moti_id_: string | undefined, |
13 | filter_moti_external_id_: string | undefined, |
14 | filter_created_at_lteq_: string | undefined |
15 | ) { |
16 | const url = new URL(`https://motimateapp.com/public_api/motis/chapter_completions`) |
17 |
|
18 | for (const [k, v] of [ |
19 | ['filter[id]', filter_id_], |
20 | ['filter[chapter_id]', filter_chapter_id_], |
21 | ['filter[user_id]', filter_user_id_], |
22 | ['filter[user_external_id]', filter_user_external_id_], |
23 | ['filter[moti_id]', filter_moti_id_], |
24 | ['filter[moti_external_id]', filter_moti_external_id_], |
25 | ['filter[created_at_lteq]', filter_created_at_lteq_] |
26 | ]) { |
27 | if (v !== undefined && v !== '' && k !== undefined) { |
28 | url.searchParams.append(k, v) |
29 | } |
30 | } |
31 |
|
32 | const response = await fetch(url, { |
33 | method: 'GET', |
34 | headers: { |
35 | Authorization: 'Bearer ' + auth.token |
36 | } |
37 | }) |
38 |
|
39 | if (!response.ok) { |
40 | const text = await response.text() |
41 | throw new Error(`${response.status} ${text}`) |
42 | } |
43 |
|
44 | return await response.json() |
45 | } |
46 |
|