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

22 lines
534 B
CoffeeScript
Raw Normal View History

2014-02-12 05:23:40 -05:00
mongojs = require("../../infrastructure/mongojs")
metrics = require("metrics-sharelatex")
2014-02-12 05:23:40 -05:00
db = mongojs.db
ObjectId = mongojs.ObjectId
2017-03-16 06:59:18 -04:00
logger = require('logger-sharelatex')
2014-02-12 05:23:40 -05:00
2017-03-16 06:59:18 -04:00
module.exports = UserLocator =
2014-02-12 05:23:40 -05:00
findByEmail: (email, callback)->
email = email.trim()
db.users.findOne email:email, (err, user)->
callback(err, user)
findById: (_id, callback)->
2017-03-16 06:59:18 -04:00
db.users.findOne _id:ObjectId(_id+""), callback
2017-03-17 10:55:41 -04:00
[
'findById',
'findByEmail'
].map (method) ->
metrics.timeAsyncMethod UserLocator, method, 'mongo.UserLocator', logger