UserGetter.coffee 426 B

123456789101112131415
  1. mongojs = require("../../infrastructure/mongojs")
  2. db = mongojs.db
  3. ObjectId = mongojs.ObjectId
  4. module.exports = UserGetter =
  5. getUser: (query, projection, callback = (error, user) ->) ->
  6. if arguments.length == 2
  7. callback = projection
  8. projection = {}
  9. if typeof query == "string"
  10. query = _id: ObjectId(query)
  11. else if query instanceof ObjectId
  12. query = _id: query
  13. db.users.findOne query, projection, callback