User Login finished
This commit is contained in:
parent
4f936aaa42
commit
c52f6018a6
6 changed files with 311 additions and 67 deletions
|
|
@ -84,3 +84,30 @@ userRoute.get('/:userId/scores',
|
|||
}
|
||||
}
|
||||
)
|
||||
|
||||
userRoute.get('/:name',
|
||||
param('name')
|
||||
.isString()
|
||||
.isLength({min: 3, max: 32})
|
||||
.matches(USERNAME_VALIDATION_REGEX),
|
||||
|
||||
async (req, res) => {
|
||||
const errors = validationResult(req);
|
||||
if (!errors.isEmpty()) {
|
||||
return res.status(400).json({ errors: errors.array() });
|
||||
}
|
||||
|
||||
const name: string = req.params.name;
|
||||
console.log(name)
|
||||
|
||||
try {
|
||||
// get & return data
|
||||
const userRepo: UserPgPromiseRepository = new UserPgPromiseRepository();
|
||||
const user = await userRepo.getByName(name);
|
||||
res.json(user);
|
||||
} catch (error) {
|
||||
// handle errors
|
||||
console.log(error)
|
||||
res.status(500).json({ errors: [{msg: "Internal server error"}]})
|
||||
}
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue