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