added new endpoint
This commit is contained in:
parent
c34cd7f809
commit
3858a3c06e
|
@ -66,6 +66,14 @@ class UserController {
|
||||||
|
|
||||||
return res.status(200).send(result);
|
return res.status(200).send(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async getById(req, res) {
|
||||||
|
const userId = req.params.userId
|
||||||
|
|
||||||
|
let result = (await UserService.getById(userId)).username;
|
||||||
|
|
||||||
|
return res.status(200).send(result);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default new UserController()
|
export default new UserController()
|
|
@ -11,5 +11,7 @@ UserRouter.get('/synchronize/:groupId', tryHandler(auth.authenticate), tryHandle
|
||||||
UserRouter.post('/changeUsername', tryHandler(auth.authenticate), tryHandler(auth.requireUsername), tryHandler(UserController.changeUsername));
|
UserRouter.post('/changeUsername', tryHandler(auth.authenticate), tryHandler(auth.requireUsername), tryHandler(UserController.changeUsername));
|
||||||
UserRouter.post('/changePassword', tryHandler(auth.authenticate), tryHandler(auth.requirePassword), tryHandler(UserController.changePassword));
|
UserRouter.post('/changePassword', tryHandler(auth.authenticate), tryHandler(auth.requirePassword), tryHandler(UserController.changePassword));
|
||||||
UserRouter.get('/myGroups', tryHandler(auth.authenticate), tryHandler(UserController.getAllGroupsForUser));
|
UserRouter.get('/myGroups', tryHandler(auth.authenticate), tryHandler(UserController.getAllGroupsForUser));
|
||||||
|
//Maybe I should add a middleware like "auth.usersShareGroups"
|
||||||
|
UserRouter.get('/byId/:userId', tryHandler(auth.authenticate), tryHandler(UserController.getById))
|
||||||
|
|
||||||
export default UserRouter;
|
export default UserRouter;
|
|
@ -43,6 +43,12 @@ class UserService {
|
||||||
async getAllGroupsForUser(userId) {
|
async getAllGroupsForUser(userId) {
|
||||||
return (await db.query("SELECT groups FROM users WHERE id = $1", [userId])).rows[0].groups
|
return (await db.query("SELECT groups FROM users WHERE id = $1", [userId])).rows[0].groups
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async getById(userId) {
|
||||||
|
let res = (await db.query("SELECT * FROM users WHERE id = $1", [userId]))
|
||||||
|
if (res.rowCount == 0) throw new customError(`getById no user found`, responseCodes.responses.user.not_found)
|
||||||
|
return res.rows[0]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default new UserService();
|
export default new UserService();
|
Loading…
Reference in New Issue