1 | |
2 | type Motimate = { |
3 | token: string |
4 | } |
5 |
|
6 | export async function main( |
7 | auth: Motimate, |
8 | position_id: string, |
9 | force: string | undefined, |
10 | identifier_type: 'id' | 'external_id' | undefined |
11 | ) { |
12 | const url = new URL(`https://motimateapp.com/public_api/positions/${position_id}`) |
13 | for (const [k, v] of [ |
14 | ['force', force], |
15 | ['identifier_type', identifier_type] |
16 | ]) { |
17 | if (v !== undefined && v !== '' && k !== undefined) { |
18 | url.searchParams.append(k, v) |
19 | } |
20 | } |
21 | const response = await fetch(url, { |
22 | method: 'DELETE', |
23 | headers: { |
24 | Authorization: 'Bearer ' + auth.token |
25 | }, |
26 | body: undefined |
27 | }) |
28 | if (!response.ok) { |
29 | const text = await response.text() |
30 | throw new Error(`${response.status} ${text}`) |
31 | } |
32 | return await response.text() |
33 | } |
34 |
|