Skip to content
Snippets Groups Projects
Commit 6209a4c3 authored by Renzo Beux's avatar Renzo Beux
Browse files

Merge remote-tracking branch 'origin/develop' into feature/Audit

parents acde1bea efd91337
No related branches found
No related tags found
No related merge requests found
...@@ -3,5 +3,5 @@ INSTANCE=TEST ...@@ -3,5 +3,5 @@ INSTANCE=TEST
HOST=localhost HOST=localhost
USER=developer USER=developer
PASSWORD=password PASSWORD=password
DB=core_database_test DB=parameter_database
AUTH_BASE_URL=http://localhost:4000/users AUTH_BASE_URL=http://localhost:3000/users
\ No newline at end of file \ No newline at end of file
...@@ -20,7 +20,8 @@ const create: Handler = async (req: Request, res: Response) => { ...@@ -20,7 +20,8 @@ const create: Handler = async (req: Request, res: Response) => {
const listUsers: Handler = async (req: Request, res: Response) => { const listUsers: Handler = async (req: Request, res: Response) => {
try { try {
const userList: any = await UserAPI.listUsers(req.body); const token: any = req.headers.authorization;
const userList: any = await UserAPI.listUsers(req.query.type, token);
return res.status(200).send(userList); return res.status(200).send(userList);
} catch (error) { } catch (error) {
const e = error as Error; const e = error as Error;
...@@ -40,7 +41,8 @@ const login: Handler = async (req: Request, res: Response) => { ...@@ -40,7 +41,8 @@ const login: Handler = async (req: Request, res: Response) => {
const update: Handler = async (req: Request, res: Response) => { const update: Handler = async (req: Request, res: Response) => {
try { try {
const user: any = await UserAPI.update(req.body, req.params.id); const token: any = req.headers.authorization;
const user: any = await UserAPI.update(req.body, req.params.id, token);
return res.status(200).send(user); return res.status(200).send(user);
} catch (error) { } catch (error) {
const e = error as Error; const e = error as Error;
...@@ -50,7 +52,8 @@ const update: Handler = async (req: Request, res: Response) => { ...@@ -50,7 +52,8 @@ const update: Handler = async (req: Request, res: Response) => {
const password: Handler = async (req: Request, res: Response) => { const password: Handler = async (req: Request, res: Response) => {
try { try {
const user: any = await UserAPI.password(req.body, req.params.id); const token: any = req.headers.authorization;
const user: any = await UserAPI.password(req.body, req.params.id, token);
return res.status(200).send(user); return res.status(200).send(user);
} catch (error) { } catch (error) {
const e = error as Error; const e = error as Error;
...@@ -60,7 +63,8 @@ const password: Handler = async (req: Request, res: Response) => { ...@@ -60,7 +63,8 @@ const password: Handler = async (req: Request, res: Response) => {
const approve: Handler = async (req: Request, res: Response) => { const approve: Handler = async (req: Request, res: Response) => {
try { try {
const user: any = await UserAPI.approve(req.params.id); const token: any = req.headers.authorization;
const user: any = await UserAPI.approve(req.params.id, token);
return res.status(200).send(user); return res.status(200).send(user);
} catch (error) { } catch (error) {
const e = error as Error; const e = error as Error;
...@@ -70,7 +74,8 @@ const approve: Handler = async (req: Request, res: Response) => { ...@@ -70,7 +74,8 @@ const approve: Handler = async (req: Request, res: Response) => {
const cancel: Handler = async (req: Request, res: Response) => { const cancel: Handler = async (req: Request, res: Response) => {
try { try {
const user: any = await UserAPI.cancel(req.params.id); const token: any = req.headers.authorization;
const user: any = await UserAPI.cancel(req.params.id, token);
return res.status(200).send(user); return res.status(200).send(user);
} catch (error) { } catch (error) {
const e = error as Error; const e = error as Error;
...@@ -80,7 +85,8 @@ const cancel: Handler = async (req: Request, res: Response) => { ...@@ -80,7 +85,8 @@ const cancel: Handler = async (req: Request, res: Response) => {
const giveAdminPermission: Handler = async (req: Request, res: Response) => { const giveAdminPermission: Handler = async (req: Request, res: Response) => {
try { try {
const user: any = await UserAPI.giveAdminPermission(req.params.id); const token: any = req.headers.authorization;
const user: any = await UserAPI.giveAdminPermission(req.params.id, token);
return res.status(200).send(user); return res.status(200).send(user);
} catch (error) { } catch (error) {
const e = error as Error; const e = error as Error;
...@@ -90,7 +96,8 @@ const giveAdminPermission: Handler = async (req: Request, res: Response) => { ...@@ -90,7 +96,8 @@ const giveAdminPermission: Handler = async (req: Request, res: Response) => {
const removeAdminPermission: Handler = async (req: Request, res: Response) => { const removeAdminPermission: Handler = async (req: Request, res: Response) => {
try { try {
const user: any = await UserAPI.removeAdminPermission(req.params.id); const token: any = req.headers.authorization;
const user: any = await UserAPI.removeAdminPermission(req.params.id, token);
return res.status(200).send(user); return res.status(200).send(user);
} catch (error) { } catch (error) {
const e = error as Error; const e = error as Error;
......
...@@ -30,69 +30,50 @@ const create = (user: any): any => { ...@@ -30,69 +30,50 @@ const create = (user: any): any => {
}); });
}; };
const login = (user: any): any => { const login = async (user: any) => {
instance.post('/login', user) const res = await instance.post('/login', user);
.then((res) => res) return res.data;
.catch((err) => {
throw (err);
});
}; };
const listUsers = (requirements: any): any => { const listUsers = async (userType: any, token: string) => {
instance.get('/', requirements) const res = await instance.get('/', { headers: { authorization: token }, params: { type: userType } });
.then((res) => res) return res.data;
.catch((err) => {
throw (err);
});
}; };
const update = (user: any, idUser: string) => { const update = async (user: any, idUser: string, token: string) => {
const url = `/${idUser}`; const url = `/${idUser}`;
instance.put(url, user) const res = await instance.put(url, user, { headers: { authorization: token } });
.then((res) => res) return res.data;
.catch((err) => {
throw (err);
});
}; };
const password = (user: any, idUser: string) => { const password = async (user: any, idUser: string, token: string) => {
instance.put('/password', user, { params: { id: idUser } }) const url = `/${idUser}/password`;
.then((res) => res) const res = await instance.put(url, user, { headers: { authorization: token } });
.catch((err) => { return res.data;
throw (err);
});
}; };
const approve = (idUser: string) => { const approve = async (idUser: string, token: string) => {
instance.put('/approve', { params: { id: idUser } }) const url = `/${idUser}/approve`;
.then((res) => res) const res = await instance.put(url, {}, { headers: { authorization: token } });
.catch((err) => { return res.data;
throw (err);
});
}; };
const cancel = (idUser: string) => { const cancel = async (idUser: string, token: string) => {
instance.put('/cancel', { params: { id: idUser } }) const url = `/${idUser}/cancel`;
.then((res) => res) const res = await instance.put(url, {}, { headers: { authorization: token } });
.catch((err) => { return res.data;
throw (err);
});
}; };
const giveAdminPermission = (idUser: string) => { const giveAdminPermission = async (idUser: string, token: string) => {
instance.put('/admin', { params: { id: idUser } }) const url = `/${idUser}/admin`;
.then((res) => res) const res = await instance.put(url, {}, { headers: { authorization: token } });
.catch((err) => { return res.data;
throw (err);
});
}; };
const removeAdminPermission = (idUser: string) => { const removeAdminPermission = async (idUser: string, token: string) => {
instance.put('/client', { params: { id: idUser } }) const url = `/${idUser}/client`;
.then((res) => res) const res = await instance.put(url, {}, { headers: { authorization: token } });
.catch((err) => { return res.data;
throw (err);
});
}; };
export default { export default {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment