1 | |
2 | |
3 | * List time-off requests for Organization |
4 | * List time-off requests for Organization |
5 | **Token scopes**: `time-off:read` |
6 | */ |
7 | export async function main( |
8 | auth: RT.Deel, |
9 | status?: string | undefined, |
10 | start_date?: string | undefined, |
11 | end_date?: string | undefined, |
12 | approval_start_date?: string | undefined, |
13 | approval_end_date?: string | undefined, |
14 | updated_start_date?: string | undefined, |
15 | updated_end_date?: string | undefined, |
16 | page_size?: string | undefined, |
17 | policy_types?: string | undefined, |
18 | hris_profile_ids?: string | undefined, |
19 | next?: string | undefined |
20 | ) { |
21 | const url = new URL(`https://api.letsdeel.com/rest/v2/time_offs`) |
22 | for (const [k, v] of [ |
23 | ['status', status], |
24 | ['start_date', start_date], |
25 | ['end_date', end_date], |
26 | ['approval_start_date', approval_start_date], |
27 | ['approval_end_date', approval_end_date], |
28 | ['updated_start_date', updated_start_date], |
29 | ['updated_end_date', updated_end_date], |
30 | ['page_size', page_size], |
31 | ['policy_types', policy_types], |
32 | ['hris_profile_ids', hris_profile_ids], |
33 | ['next', next] |
34 | ]) { |
35 | if (v !== undefined && v !== '') { |
36 | url.searchParams.append(k, v) |
37 | } |
38 | } |
39 | const response = await fetch(url, { |
40 | method: 'GET', |
41 | headers: { |
42 | Authorization: 'Bearer ' + auth.apiKey |
43 | }, |
44 | body: undefined |
45 | }) |
46 | if (!response.ok) { |
47 | const text = await response.text() |
48 | throw new Error(`${response.status} ${text}`) |
49 | } |
50 | return await response.json() |
51 | } |
52 |
|