Skip to content

Commit

Permalink
Merge c57facf into 8f739dc
Browse files Browse the repository at this point in the history
  • Loading branch information
niekcandaele authored Mar 22, 2019
2 parents 8f739dc + c57facf commit ad5f25a
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 0 deletions.
42 changes: 42 additions & 0 deletions routes/user/deleteUser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/* eslint-disable max-len */
/**
*
* @api {DELETE} /api/user/:id DELETE /api/user/:id
* @apiName DELETE /api/user/:id
* @apiGroup User
*
*
* @apiParam {String} userId UUID of the user to get
*
* @apiSuccess {Number} deletedUsers how many user profiles were deleted
*
* @apiParamExample {String} Request-Example:
* {
* "id" : "0a40cf80-4b2a-11e9-a532-07f768aa6c74"
* }
*
*
*/

module.exports = function deleteUser(app) {
app.delete('/api/user/:id', async (req, res) => {
const {
id,
} = req.params;

const deletedUsers = await app.models.User.destroy({
where: {
id,
},
});

if (deletedUsers === 0) {
res.status(404);
return res.end();
}

res.status(200);
res.json(deletedUsers);
return res.end();
});
};
47 changes: 47 additions & 0 deletions routes/user/getUserById.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/* eslint-disable max-len */
/**
*
* @api {GET} /api/user/:id GET /api/user/:id
* @apiName GET /api/user/:id
* @apiGroup User
*
*
* @apiParam {String} userId UUID of the user to get
*
* @apiSuccess {Object} user
* @apiSuccess {String} user.id UUID
* @apiSuccess {String} user.username Username
* @apiSuccess {String} user.steamId Steam64 ID
* @apiSuccess {Date} user.lastVisited Date the user was last active on the website
*
* @apiParamExample {String} Request-Example:
* {
* "id" : "0a40cf80-4b2a-11e9-a532-07f768aa6c74"
* }
*
*/

module.exports = function getUserById(app) {
app.get('/api/user/:id', (req, res) => {
const {
id,
} = req.params;
return app.models.User.findByPk(id)
.then((user) => {
if (user === null) {
res.status(404);
return res.end();
}
const userData = user.get({
plain: true,
});
const response = {
id: userData.id,
username: userData.username,
steamId: userData.steamId,
lastVisited: userData.lastVisited,
};
return res.json(response);
});
});
};

0 comments on commit ad5f25a

Please sign in to comment.