Skip to content
Snippets Groups Projects
Commit 62e1f8bf authored by Moreau Elise's avatar Moreau Elise
Browse files

[api][users routes] code typo

parent c1852701
Branches
No related tags found
No related merge requests found
...@@ -16,7 +16,7 @@ const userSchema = Joi.object({ ...@@ -16,7 +16,7 @@ const userSchema = Joi.object({
}); });
// Créer un nouvel utilisateur // Créer un nouvel utilisateur
router.post('/', validator.body(userSchema), async function(req, res){ router.post('/', validator.body(userSchema), async function(req, res, next){
if (req.body.confirm !== req.body.password){ if (req.body.confirm !== req.body.password){
return res.status(400).json({ return res.status(400).json({
...@@ -31,7 +31,7 @@ router.post('/', validator.body(userSchema), async function(req, res){ ...@@ -31,7 +31,7 @@ router.post('/', validator.body(userSchema), async function(req, res){
if(user){ if(user){
return res.status(409).json({ return res.status(409).json({
error: 'Username already exists.' error: 'Username already exists.'
}) });
} }
} catch(err) { } catch(err) {
return next(err); return next(err);
...@@ -50,7 +50,7 @@ router.post('/', validator.body(userSchema), async function(req, res){ ...@@ -50,7 +50,7 @@ router.post('/', validator.body(userSchema), async function(req, res){
} }
res.json(newUser); res.json(newUser);
}) });
const userSchemaLogin = Joi.object({ const userSchemaLogin = Joi.object({
username: Joi.string().required().trim().min(1), username: Joi.string().required().trim().min(1),
...@@ -70,7 +70,7 @@ router.post('/login', validator.body(userSchemaLogin), async function(req, res, ...@@ -70,7 +70,7 @@ router.post('/login', validator.body(userSchemaLogin), async function(req, res,
if (!user){ if (!user){
return res.status(401).json({ return res.status(401).json({
error: 'Fail to authenticate with given credentials.' error: 'Fail to authenticate with given credentials.'
}) });
} }
const password = crypto.createHash('md5').update(req.body.password).digest("hex"); const password = crypto.createHash('md5').update(req.body.password).digest("hex");
...@@ -91,7 +91,7 @@ router.post('/login', validator.body(userSchemaLogin), async function(req, res, ...@@ -91,7 +91,7 @@ router.post('/login', validator.body(userSchemaLogin), async function(req, res,
} }
); );
return res.json({token, user: {username: user.username, id: user._id}}); return res.json({token, user: {username: user.username, id: user._id}});
}) });
//Récupérer la liste des utilisateurs //Récupérer la liste des utilisateurs
router.get('/', async function (req, res, next){ router.get('/', async function (req, res, next){
...@@ -109,6 +109,6 @@ router.get('/', async function (req, res, next){ ...@@ -109,6 +109,6 @@ router.get('/', async function (req, res, next){
} }
return res.json(users); return res.json(users);
}) });
export default router; export default router;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment