Newer
Older
// TODO: Set according return types and don't use 'any' explicitly. Nor implicitly.
// Basically don't use 'any' in any context whatsoever. Despite it being the easiest solution.
/* eslint-disable @typescript-eslint/explicit-function-return-type */
/* eslint-disable @typescript-eslint/no-explicit-any */
import axios from 'axios';
const instance = axios.create({
baseURL: process.env.AUTH_BASE_URL,
});
export const validate = (token: string): number => {
let id = -1;
instance.post('/validate', { token })
.then((res) => {
id = (res.data as any).userId as number;
})
.catch((err) => {
throw (err);
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
const create = (user: any): any => {
instance.post('/', user)
.then((res) => res)
.catch((err) => {
throw (err);
});
};
const login = (user: any): any => {
instance.post('/login', user)
.then((res) => res)
.catch((err) => {
throw (err);
});
};
const listUsers = (requirements: any): any => {
instance.get('/', requirements)
.then((res) => res)
.catch((err) => {
throw (err);
});
};
const update = (user: any, idUser: string) => {
const url = `/${idUser}`;
instance.put(url, user)
.then((res) => res)
.catch((err) => {
throw (err);
});
};
const password = (user: any, idUser: string) => {
instance.put('/password', user, { params: { id: idUser } })
.then((res) => res)
.catch((err) => {
throw (err);
});
};
const approve = (idUser: string) => {
instance.put('/approve', { params: { id: idUser } })
.then((res) => res)
.catch((err) => {
throw (err);
});
};
const cancel = (idUser: string) => {
instance.put('/cancel', { params: { id: idUser } })
.then((res) => res)
.catch((err) => {
throw (err);
});
};
const giveAdminPermission = (idUser: string) => {
instance.put('/admin', { params: { id: idUser } })
.then((res) => res)
.catch((err) => {
throw (err);
});
};
const removeAdminPermission = (idUser: string) => {
instance.put('/client', { params: { id: idUser } })
.then((res) => res)
.catch((err) => {
throw (err);
});
};
export default {
create,
login,
listUsers,
update,
password,
approve,
cancel,
giveAdminPermission,
removeAdminPermission,
};