-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); | ||
}; |