Files
hammond/ui/tests/mock-api/routes/users.js
Akhil Gupta d25c30a7b2 first commit
2021-05-29 15:20:50 +05:30

25 lines
634 B
JavaScript

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)
})
}