1 | |
2 | |
3 | * Fetch EOR Contract form |
4 | * Returns a formulary for creating EOR Contracts |
5 | **Token scopes**: `forms:read` |
6 | */ |
7 | export async function main( |
8 | auth: RT.Deel, |
9 | country_code: string, |
10 | state?: string | undefined, |
11 | start_date?: string | undefined, |
12 | work_hours_per_week?: string | undefined, |
13 | contract_duration_in_days?: string | undefined |
14 | ) { |
15 | const url = new URL(`https://api.letsdeel.com/rest/v2/forms/eor/create-contract/${country_code}`) |
16 | for (const [k, v] of [ |
17 | ['state', state], |
18 | ['start_date', start_date], |
19 | ['work_hours_per_week', work_hours_per_week], |
20 | ['contract_duration_in_days', contract_duration_in_days] |
21 | ]) { |
22 | if (v !== undefined && v !== '') { |
23 | url.searchParams.append(k, v) |
24 | } |
25 | } |
26 | const response = await fetch(url, { |
27 | method: 'GET', |
28 | headers: { |
29 | Authorization: 'Bearer ' + auth.apiKey |
30 | }, |
31 | body: undefined |
32 | }) |
33 | if (!response.ok) { |
34 | const text = await response.text() |
35 | throw new Error(`${response.status} ${text}`) |
36 | } |
37 | return await response.json() |
38 | } |
39 |
|