Skip to content

Commit

Permalink
Merge pull request #42 from synapsestudios/find-endpoint
Browse files Browse the repository at this point in the history
Find endpoint
  • Loading branch information
spruce-bruce authored Apr 10, 2017
2 parents fc8f3c9 + 52c8d84 commit 458e5ab
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
3 changes: 2 additions & 1 deletion api/src/application/api/api-routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ module.exports = (userService, mixedValidation, rowNotExists, rowExists) => [
method: 'GET',
path: '/api/users',
handler: (request, reply) => {
reply(userService.getUsers(request.query.ids));
reply(userService.getUsers(request.query));
},
config: {
auth: {
Expand All @@ -77,6 +77,7 @@ module.exports = (userService, mixedValidation, rowNotExists, rowExists) => [
validate: {
query: {
ids: Joi.array().items(Joi.string()).single(),
email: Joi.string().email()
}
}
}
Expand Down
13 changes: 11 additions & 2 deletions api/src/application/user/user-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,17 @@ module.exports = (bookshelf, emailService, renderTemplate) => {
});
},

getUsers(ids) {
return bookshelf.model('user').query(qb => qb.whereIn('id', ids)).fetchAll();
getUsers(query) {
let model = bookshelf.model('user');
if (query.ids) {
model = model.where('id', 'in', query.ids);
}

if (query.email) {
model = model.where('email', query.email);
}

return model.fetchAll();
},

sendInvite(user, appName, hoursTillExpiration) {
Expand Down

0 comments on commit 458e5ab

Please sign in to comment.