1 | |
2 | type Motimate = { |
3 | token: string |
4 | } |
5 |
|
6 | export async function main( |
7 | auth: Motimate, |
8 | group_id: string, |
9 | identifier_type: 'id' | 'external_id' | undefined, |
10 | body: { |
11 | external_id?: string |
12 | kind?: 'country' | 'custom' | 'organization' | 'region' | 'store' |
13 | name?: string |
14 | excluded_from_scoreboard?: false | true |
15 | imported?: false | true |
16 | parent_id?: number |
17 | } |
18 | ) { |
19 | const url = new URL(`https://motimateapp.com/public_api/groups/${group_id}`) |
20 |
|
21 | for (const [k, v] of [['identifier_type', identifier_type]]) { |
22 | if (v !== undefined && v !== '' && k !== undefined) { |
23 | url.searchParams.append(k, v) |
24 | } |
25 | } |
26 |
|
27 | const response = await fetch(url, { |
28 | method: 'PATCH', |
29 | headers: { |
30 | 'Content-Type': 'application/json', |
31 | Authorization: 'Bearer ' + auth.token |
32 | }, |
33 | body: JSON.stringify(body) |
34 | }) |
35 |
|
36 | if (!response.ok) { |
37 | const text = await response.text() |
38 | throw new Error(`${response.status} ${text}`) |
39 | } |
40 |
|
41 | return await response.json() |
42 | } |
43 |
|