Skip to content

Commit

Permalink
Added get user by ID in getAllUsers route
Browse files Browse the repository at this point in the history
  • Loading branch information
Adityapnn811 committed Aug 1, 2022
1 parent a3f793a commit 5e7ab2d
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions routes/getAllUsers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,24 @@ router.get('/', cors(), async (req, res) => {
}
})

// return user berdasarkan ID
router.get('/:id', cors(), async (req, res) => {
const token = req.headers.authorization.split(" ")[1];
if (!token) {
res.status(400).json({error: "No token provided"});
} else {
const decoded = jwt.verify(token, "dondraforbinomo");
console.log(decoded.username)
if (decoded) {
const userRepo = AppDataSource.getRepository(User);
const user = await userRepo.findOneBy({
id: req.params.id
})
res.status(200).json(user);
} else {
res.status(400).json({error: "Invalid token"});
}
}
})

module.exports = router;

0 comments on commit 5e7ab2d

Please sign in to comment.