-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
55 lines (43 loc) · 1.25 KB
/
index.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
const LOGIN_URL = 'https://login.eeproperty.com/api/v3/mobile/user/login';
const MACHINES_URL = 'https://vesta.eeproperty.com/api/v3/mobile/machines';
interface MachineData {
costPerCycle: number;
number: number;
pricing: 'INCLUSIVE' | string;
room: string;
state: 'ERROR' | 'ACTIVATED' | 'DEACTIVATED' | string;
type: 'WASHER' | string;
}
export const login = async (codeImmeuble: string, codePersonnel: string) => {
const res = await fetch(LOGIN_URL, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
code: codeImmeuble,
pin: codePersonnel,
})
});
const data = await res.json();
console.log(data);
if (data.message === 'OK') {
return data.token;
} else {
throw new Error(data.message);
}
}
export const fetchMachines = async (token: string) => {
const res = await fetch(MACHINES_URL, {
headers: {
'x-token': token,
'x-app-version': '1.6.6',
}
});
const data = await res.json();
if (Array.isArray(data.machines)) {
return data.machines as MachineData[];
} else {
throw new Error(data.message);
}
}