first commit
This commit is contained in:
24
ui/tests/mock-api/routes/users.js
Normal file
24
ui/tests/mock-api/routes/users.js
Normal file
@@ -0,0 +1,24 @@
|
||||
const Users = require('../resources/users')
|
||||
|
||||
module.exports = (app) => {
|
||||
app.get('/api/users/:username', (request, response) => {
|
||||
const currentUser = Users.findBy('token', request.headers.authorization)
|
||||
|
||||
if (!currentUser) {
|
||||
return response.status(401).json({
|
||||
message:
|
||||
'The token is either invalid or has expired. Please log in again.',
|
||||
})
|
||||
}
|
||||
|
||||
const matchedUser = Users.findBy('username', request.params.username)
|
||||
|
||||
if (!matchedUser) {
|
||||
return response.status(400).json({
|
||||
message: 'No user with this name was found.',
|
||||
})
|
||||
}
|
||||
|
||||
response.json(matchedUser)
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user