1 | |
2 | type Motimate = { |
3 | token: string |
4 | } |
5 |
|
6 | export async function main( |
7 | auth: Motimate, |
8 | include: string | undefined, |
9 | filter_assigned_to_all_: string | undefined, |
10 | filter_id_: string | undefined, |
11 | filter_external_id_: string | undefined, |
12 | filter_has_diploma_: string | undefined, |
13 | filter_category_id_: string | undefined, |
14 | filter_category_external_id_: string | undefined, |
15 | filter_folder_id_: string | undefined, |
16 | filter_publish_status_: string | undefined, |
17 | filter_default_language_: string | undefined, |
18 | filter_tags_: string | undefined, |
19 | filter_created_at_lteq_: string | undefined, |
20 | filter_updated_at_lteq_: string | undefined |
21 | ) { |
22 | const url = new URL(`https://motimateapp.com/public_api/learning_paths`) |
23 |
|
24 | for (const [k, v] of [ |
25 | ['include', include], |
26 | ['filter[assigned_to_all]', filter_assigned_to_all_], |
27 | ['filter[id]', filter_id_], |
28 | ['filter[external_id]', filter_external_id_], |
29 | ['filter[has_diploma]', filter_has_diploma_], |
30 | ['filter[category_id]', filter_category_id_], |
31 | ['filter[category_external_id]', filter_category_external_id_], |
32 | ['filter[folder_id]', filter_folder_id_], |
33 | ['filter[publish_status]', filter_publish_status_], |
34 | ['filter[default_language]', filter_default_language_], |
35 | ['filter[tags]', filter_tags_], |
36 | ['filter[created_at_lteq]', filter_created_at_lteq_], |
37 | ['filter[updated_at_lteq]', filter_updated_at_lteq_] |
38 | ]) { |
39 | if (v !== undefined && v !== '' && k !== undefined) { |
40 | url.searchParams.append(k, v) |
41 | } |
42 | } |
43 |
|
44 | const response = await fetch(url, { |
45 | method: 'GET', |
46 | headers: { |
47 | Authorization: 'Bearer ' + auth.token |
48 | } |
49 | }) |
50 |
|
51 | if (!response.ok) { |
52 | const text = await response.text() |
53 | throw new Error(`${response.status} ${text}`) |
54 | } |
55 |
|
56 | return await response.json() |
57 | } |
58 |
|