-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi-request.js
62 lines (60 loc) · 1.88 KB
/
api-request.js
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
import axios from 'axios';
import { getJwt } from '../Config/auth-config';
// Hämtar byggnadsinformation
export const GetBuilding = async () => {
try {
JWT = getJwt();
const response = await axios.get(
'https://api.smarthut.se/BuildingInfo/GetMyBuilding',
{ headers: { Authorization: 'Bearer ' + JWT } }
);
return response.data;
} catch (e) {
console.log('error', e);
}
};
// Hämtar alla givarenheter i byggnaden
export async function getDevices(id) {
try {
JWT = getJwt();
const response = await axios.get(
'https://api.smarthut.se/BuildingInfo/' + id + '/true',
{ headers: { Authorization: 'Bearer ' + JWT } }
);
return response.data;
} catch (e) {
console.log('error', e);
}
}
// Hämtar alla enheter för de olika givarenheterna
export async function getUnit(id) {
try {
JWT = getJwt();
const response = await axios.get('https://api.smarthut.se/Unit/', {
headers: { Authorization: 'Bearer ' + JWT },
});
return response.data;
} catch (e) {
console.log('error', e);
}
}
//Återställer larm för sensor
export async function restoreAlarm(deviceId, user) {
try {
JWT = getJwt();
await axios({
headers: { accept: '*/*', Authorization: `Bearer ${JWT}` },
method: 'post',
url: 'https://smarthut.azurewebsites.net/api/restorealarm',
data: JSON.stringify({ deviceId: `${deviceId}`, userName: `${user}` }),
});
} catch (error) {
const fel = JSON.stringify(error.response);
document.getElementById(`dialogtext-${deviceId}`).style.display = 'none';
document.getElementById(`restoreBtn-${deviceId}`).style.display = 'none';
document.getElementById(`status-${deviceId}`).style.color = 'red';
document.getElementById(
`status-${deviceId}`
).innerHTML = `Något gick fel vid återställning av sensor ${deviceId} med felkoden: <br><br>${fel}.`;
}
}