mirror of
https://github.com/overleaf/overleaf.git
synced 2024-10-31 21:21:03 -04:00
31 lines
957 B
CoffeeScript
31 lines
957 B
CoffeeScript
mongojs = require("../../infrastructure/mongojs")
|
|
metrics = require('../../infrastructure/Metrics')
|
|
logger = require('logger-sharelatex')
|
|
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
|
|
|
|
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
|
|
|
|
metrics.timeAsyncMethod UserGetter, 'getUser', 'UserGetter.getUser', logger
|
|
metrics.timeAsyncMethod UserGetter, 'getUsers', 'UserGetter.getUsers', logger
|