overleaf/services/web/app/coffee/Features/User/UserGetter.coffee
2014-11-09 23:08:23 +00:00

18 lines
477 B
CoffeeScript

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"
try
query = _id: ObjectId(query)
catch e
return callback(null, null)
else if query instanceof ObjectId
query = _id: query
db.users.findOne query, projection, callback