feat: add sample endpoint to test JWT
This commit is contained in:
@@ -188,3 +188,43 @@ export async function createUserHandler(
|
||||
return res.status(201)
|
||||
.send(userResponse);
|
||||
}
|
||||
|
||||
/**
|
||||
* `GET /api/v1/user/account`
|
||||
*
|
||||
* Handles requests for user info retrieval
|
||||
*
|
||||
* @param {Request} req The Express request
|
||||
* @param {Response} res The Express resource
|
||||
*/
|
||||
export async function getUserHandler(
|
||||
req: Request,
|
||||
res: Response
|
||||
) {
|
||||
|
||||
const userService = new UserService();
|
||||
const user: jwt.JwtDecoded = res.locals.user.decoded;
|
||||
|
||||
// Get detailed data from DB
|
||||
let existingUser: User | null = await userService.findById(user.sub);
|
||||
|
||||
if (existingUser === null) {
|
||||
const error: ms.ErrorDTO = {
|
||||
status: 'error',
|
||||
error: 'User does not exist',
|
||||
code: 'deleted_user'
|
||||
};
|
||||
return res.status(404)
|
||||
.json(error);
|
||||
}
|
||||
|
||||
// Respond with ShortUserInfoDTO
|
||||
const userResponse: as.ShortUserInfoDTO = {
|
||||
status: 'ok',
|
||||
id: existingUser.id!,
|
||||
name: existingUser.name,
|
||||
role: existingUser.role
|
||||
}
|
||||
return res.status(201)
|
||||
.send(userResponse);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user