1 | |
2 | |
3 | * List of timesheets by contract |
4 | * Retrieve a list of timesheets found for a contract. |
5 | **Token scopes**: `timesheets:read` |
6 | */ |
7 | export async function main( |
8 | auth: RT.Deel, |
9 | contract_id: string, |
10 | contract_types?: string | undefined, |
11 | statuses?: string | undefined, |
12 | reporter_id?: string | undefined, |
13 | date_from?: string | undefined, |
14 | date_to?: string | undefined, |
15 | limit?: string | undefined, |
16 | offset?: string | undefined |
17 | ) { |
18 | const url = new URL(`https://api.letsdeel.com/rest/v2/contracts/${contract_id}/timesheets`) |
19 | for (const [k, v] of [ |
20 | ['contract_types', contract_types], |
21 | ['statuses', statuses], |
22 | ['reporter_id', reporter_id], |
23 | ['date_from', date_from], |
24 | ['date_to', date_to], |
25 | ['limit', limit], |
26 | ['offset', offset] |
27 | ]) { |
28 | if (v !== undefined && v !== '') { |
29 | url.searchParams.append(k, v) |
30 | } |
31 | } |
32 | const response = await fetch(url, { |
33 | method: 'GET', |
34 | headers: { |
35 | Authorization: 'Bearer ' + auth.apiKey |
36 | }, |
37 | body: undefined |
38 | }) |
39 | if (!response.ok) { |
40 | const text = await response.text() |
41 | throw new Error(`${response.status} ${text}`) |
42 | } |
43 | return await response.json() |
44 | } |
45 |
|