forked from TobitSoftware/chayns-components
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtobitEmployee.js
54 lines (53 loc) · 1.97 KB
/
tobitEmployee.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
let tobitEmployee = null;
/**
* Requests an endpoint to get the information if the user is a Tobit.Software employee.
* @returns {Promise<>} - Promise is resolved when user is a Tobit.Software employee.
*/
export default function isTobitEmployee() {
return new Promise((resolve, reject) => {
if (tobitEmployee === true) {
resolve();
} else if (
tobitEmployee === false ||
!chayns.env.user.isAuthenticated
) {
reject();
} else {
fetch(
`https://chaynssvc.tobit.com/v0.5/${chayns.env.site.locationId}/user/UAC/8255`,
{
headers: {
Authorization: `bearer ${chayns.env.user.tobitAccessToken}`,
},
}
)
.then((response) => {
if (response.status === 200) {
response
.json()
.then((json) => {
if (json.data) {
json.data.forEach((item) => {
if (item.locationId === 1214) {
tobitEmployee = true;
resolve();
}
});
}
if (!tobitEmployee) {
tobitEmployee = false;
reject();
}
})
.catch((e) => {
reject(e);
});
} else {
tobitEmployee = false;
reject(response.statusText);
}
})
.catch(reject);
}
});
}