1 | |
2 | |
3 | * Fetch Start Date for EOR Contracts |
4 | * Returns the earliest allowed start date for a new EOR contract quote based on employment parameters. |
5 | **Token scopes**: `contracts:read` |
6 | */ |
7 | export async function main( |
8 | auth: RT.Deel, |
9 | employment_country: string | undefined, |
10 | team_id: string | undefined, |
11 | employee_nationality?: string | undefined, |
12 | work_visa?: string | undefined, |
13 | legal_entity_id?: string | undefined, |
14 | employment_state?: string | undefined, |
15 | special_job_id?: string | undefined |
16 | ) { |
17 | const url = new URL(`https://api.letsdeel.com/rest/v2/eor/start-date`) |
18 | for (const [k, v] of [ |
19 | ['employment_country', employment_country], |
20 | ['employee_nationality', employee_nationality], |
21 | ['work_visa', work_visa], |
22 | ['team_id', team_id], |
23 | ['legal_entity_id', legal_entity_id], |
24 | ['employment_state', employment_state], |
25 | ['special_job_id', special_job_id] |
26 | ]) { |
27 | if (v !== undefined && v !== '') { |
28 | url.searchParams.append(k, v) |
29 | } |
30 | } |
31 | const response = await fetch(url, { |
32 | method: 'GET', |
33 | headers: { |
34 | Authorization: 'Bearer ' + auth.apiKey |
35 | }, |
36 | body: undefined |
37 | }) |
38 | if (!response.ok) { |
39 | const text = await response.text() |
40 | throw new Error(`${response.status} ${text}`) |
41 | } |
42 | return await response.json() |
43 | } |
44 |
|