first commit

This commit is contained in:
Akhil Gupta
2021-05-29 15:20:50 +05:30
commit d25c30a7b2
194 changed files with 49873 additions and 0 deletions

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