-
Notifications
You must be signed in to change notification settings - Fork 2
/
updateBox.ts
73 lines (64 loc) · 2.01 KB
/
updateBox.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import axios from 'axios';
import { Coordinates, OpenSenseMapID } from '../globalTypes';
import { BoxDataWithSecrets, MQTT, TTN } from './_boxModels';
/**
* @see https://docs.opensensemap.org/#api-Boxes-updateBox
*/
export async function updateBox(senseBoxId: OpenSenseMapID, authorization: string, options: UpdateBoxOptions): Promise<UpdateBoxResult> {
return (
await axios.put(`https://api.opensensemap.org/boxes/${senseBoxId}`, options, {
headers: {
Authorization: `Bearer ${authorization}`
}
})
).data;
}
export type UpdateBoxOptions = {
name?: string;
grouptag?: string[];
location?: Coordinates;
sensors?: (UpdateBoxSensorNew | UpdateBoxSensorEdited | UpdateBoxSensorDeleted)[];
mqtt?: MQTT;
ttn?: TTN;
description?: string;
image?: string;
addons?: Record<string | number, string | number>;
};
/**
* @linkcode https://github.com/sensebox/openSenseMap-API/blob/2e645bdc4c80e668720b5eaaf384a35d2909569e/packages/api/lib/controllers/boxesController.js#L143
*/
export type UpdateBoxResult = {
code: 'Ok';
data: BoxDataWithSecrets;
};
/**
* @see https://docs.opensensemap.org/#api-Boxes-updateBox
* @linkcode https://github.com/sensebox/openSenseMap-API/blob/2e645bdc4c80e668720b5eaaf384a35d2909569e/packages/models/src/box/box.js#L855C6-L855C6
*/
export type UpdateBoxSensorNew = {
title: string;
unit: string;
sensorType: string;
icon: string;
new: true;
};
/**
* @see https://docs.opensensemap.org/#api-Boxes-updateBox
* @linkcode https://github.com/sensebox/openSenseMap-API/blob/2e645bdc4c80e668720b5eaaf384a35d2909569e/packages/models/src/box/box.js#L857C7-L857C7
*/
export type UpdateBoxSensorEdited = {
_id: OpenSenseMapID;
title: string;
unit: string;
sensorType: string;
icon: string;
edited: true;
};
/**
* @see https://docs.opensensemap.org/#api-Boxes-updateBox
* @linkcode https://github.com/sensebox/openSenseMap-API/blob/2e645bdc4c80e668720b5eaaf384a35d2909569e/packages/models/src/box/box.js#L853
*/
export type UpdateBoxSensorDeleted = {
_id: OpenSenseMapID;
deleted: true;
};