1 | |
2 | |
3 | * Delete body metrics for a given user ID |
4 | * Used to delete Body metrics the user has registered on their account |
5 | */ |
6 | export async function main(auth: RT.Terra, user_id: string | undefined, body: Body) { |
7 | const url = new URL(`https://api.tryterra.co/v2/body`) |
8 | for (const [k, v] of [['user_id', user_id]]) { |
9 | if (v !== undefined && v !== '') { |
10 | url.searchParams.append(k, v) |
11 | } |
12 | } |
13 | const response = await fetch(url, { |
14 | method: 'DELETE', |
15 | headers: { |
16 | 'dev-id': auth.devId, |
17 | 'Content-Type': 'application/json', |
18 | 'X-api-key': auth.apiKey |
19 | }, |
20 | body: JSON.stringify(body) |
21 | }) |
22 | if (!response.ok) { |
23 | const text = await response.text() |
24 | throw new Error(`${response.status} ${text}`) |
25 | } |
26 | return await response.json() |
27 | } |
28 |
|
29 | |
30 | |
31 | * This file was automatically generated by json-schema-to-typescript. |
32 | * DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file, |
33 | * and run json-schema-to-typescript to regenerate this file. |
34 | */ |
35 |
|
36 | export interface Body { |
37 | |
38 | * List of identifiers for body metrics entries to be deleted |
39 | */ |
40 | log_ids?: string[] |
41 | [k: string]: unknown |
42 | } |
43 |
|