Skip to content
Snippets Groups Projects
Commit 8df4d350 authored by Ignacio Bengoa Nion's avatar Ignacio Bengoa Nion
Browse files

Users handling in Backend implemented

parent 88d580f0
No related branches found
No related tags found
No related merge requests found
......@@ -20,7 +20,8 @@ const create: Handler = async (req: Request, res: Response) => {
const listUsers: Handler = async (req: Request, res: Response) => {
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);
} catch (error) {
const e = error as Error;
......@@ -40,7 +41,8 @@ const login: Handler = async (req: Request, res: Response) => {
const update: Handler = async (req: Request, res: Response) => {
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);
} catch (error) {
const e = error as Error;
......@@ -50,7 +52,8 @@ const update: Handler = async (req: Request, res: Response) => {
const password: Handler = async (req: Request, res: Response) => {
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);
} catch (error) {
const e = error as Error;
......@@ -60,7 +63,8 @@ const password: Handler = async (req: Request, res: Response) => {
const approve: Handler = async (req: Request, res: Response) => {
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);
} catch (error) {
const e = error as Error;
......@@ -70,7 +74,8 @@ const approve: Handler = async (req: Request, res: Response) => {
const cancel: Handler = async (req: Request, res: Response) => {
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);
} catch (error) {
const e = error as Error;
......@@ -80,7 +85,8 @@ const cancel: Handler = async (req: Request, res: Response) => {
const giveAdminPermission: Handler = async (req: Request, res: Response) => {
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);
} catch (error) {
const e = error as Error;
......@@ -90,7 +96,8 @@ const giveAdminPermission: Handler = async (req: Request, res: Response) => {
const removeAdminPermission: Handler = async (req: Request, res: Response) => {
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);
} catch (error) {
const e = error as Error;
......
......@@ -30,69 +30,50 @@ const create = (user: any): any => {
});
};
const login = (user: any): any => {
instance.post('/login', user)
.then((res) => res)
.catch((err) => {
throw (err);
});
const login = async (user: any) => {
const res = await instance.post('/login', user);
return res.data;
};
const listUsers = (requirements: any): any => {
instance.get('/', requirements)
.then((res) => res)
.catch((err) => {
throw (err);
});
const listUsers = async (userType: any, token: string) => {
const res = await instance.get('/', { headers: { authorization: token }, params: { type: userType } });
return res.data;
};
const update = (user: any, idUser: string) => {
const update = async (user: any, idUser: string, token: string) => {
const url = `/${idUser}`;
instance.put(url, user)
.then((res) => res)
.catch((err) => {
throw (err);
});
const res = await instance.put(url, user, { headers: { authorization: token } });
return res.data;
};
const password = (user: any, idUser: string) => {
instance.put('/password', user, { params: { id: idUser } })
.then((res) => res)
.catch((err) => {
throw (err);
});
const password = async (user: any, idUser: string, token: string) => {
const url = `/${idUser}/password`;
const res = await instance.put(url, user, { headers: { authorization: token } });
return res.data;
};
const approve = (idUser: string) => {
instance.put('/approve', { params: { id: idUser } })
.then((res) => res)
.catch((err) => {
throw (err);
});
const approve = async (idUser: string, token: string) => {
const url = `/${idUser}/approve`;
const res = await instance.put(url, {}, { headers: { authorization: token } });
return res.data;
};
const cancel = (idUser: string) => {
instance.put('/cancel', { params: { id: idUser } })
.then((res) => res)
.catch((err) => {
throw (err);
});
const cancel = async (idUser: string, token: string) => {
const url = `/${idUser}/cancel`;
const res = await instance.put(url, {}, { headers: { authorization: token } });
return res.data;
};
const giveAdminPermission = (idUser: string) => {
instance.put('/admin', { params: { id: idUser } })
.then((res) => res)
.catch((err) => {
throw (err);
});
const giveAdminPermission = async (idUser: string, token: string) => {
const url = `/${idUser}/admin`;
const res = await instance.put(url, {}, { headers: { authorization: token } });
return res.data;
};
const removeAdminPermission = (idUser: string) => {
instance.put('/client', { params: { id: idUser } })
.then((res) => res)
.catch((err) => {
throw (err);
});
const removeAdminPermission = async (idUser: string, token: string) => {
const url = `/${idUser}/client`;
const res = await instance.put(url, {}, { headers: { authorization: token } });
return res.data;
};
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