overleaf/services/web/app/coffee/Features/User/UserGetter.coffee

26 lines
713 B
CoffeeScript
Raw Normal View History

2014-02-12 05:23:40 -05:00
mongojs = require("../../infrastructure/mongojs")
db = mongojs.db
ObjectId = mongojs.ObjectId
module.exports = UserGetter =
getUser: (query, projection, callback = (error, user) ->) ->
if arguments.length == 2
callback = projection
projection = {}
if typeof query == "string"
2014-11-09 18:08:23 -05:00
try
query = _id: ObjectId(query)
catch e
return callback(null, null)
2014-02-12 05:23:40 -05:00
else if query instanceof ObjectId
query = _id: query
db.users.findOne query, projection, callback
getUsers: (user_ids, projection, callback = (error, users) ->) ->
try
user_ids = user_ids.map (u) -> ObjectId(u.toString())
catch error
return callback error
db.users.find { _id: { $in: user_ids} }, projection, callback