Skip to content

Commit

Permalink
feat: can query list of users and filter by list of ids
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-bonnel committed Nov 25, 2017
1 parent 54c6535 commit dee18c1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
3 changes: 3 additions & 0 deletions server/storages/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ module.exports = async function(params) {
getUserById: async function(id) {
return users.find(user => user.id === id)
},
getUsersByIds: async function(ids) {
return users.filter(user => ids.find(id => user.id === id))
},
getUserByEmail: async function(email) {
return users.find(user => user.email === email)
},
Expand Down
12 changes: 12 additions & 0 deletions server/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,18 @@ const jwtMiddleware = require('./jwt').jwtMiddleware

let router = express.Router()

// Get the list of users
router.get('', jwtMiddleware, async function(req, res, next) {
let users = []
if (!req.query || req.query['ids']) {
users = await req.app.get('storage').getUsersByIds(req.query['ids'].split(','))
}
res.json({
results: users,
count: users.length
})
})

router.get('/:userId', jwtMiddleware, async (req, res, next) => {
if (req.user.id !== req.params.userId) return res.sendStatus(403)
const user = await req.app.get('storage').getUserById(req.params.userId)
Expand Down

0 comments on commit dee18c1

Please sign in to comment.