2014-02-12 05:23:40 -05:00
|
|
|
Subscription = require('../../models/Subscription').Subscription
|
|
|
|
logger = require("logger-sharelatex")
|
2017-05-10 10:31:17 -04:00
|
|
|
ObjectId = require('mongoose').Types.ObjectId
|
2014-02-12 05:23:40 -05:00
|
|
|
|
2018-06-29 12:01:34 -04:00
|
|
|
module.exports = SubscriptionLocator =
|
2014-02-12 05:23:40 -05:00
|
|
|
|
|
|
|
getUsersSubscription: (user_or_id, callback)->
|
2018-11-20 05:48:21 -05:00
|
|
|
user_id = @_getUserId(user_or_id)
|
2014-02-12 05:23:40 -05:00
|
|
|
logger.log user_id:user_id, "getting users subscription"
|
2015-07-22 05:38:28 -04:00
|
|
|
Subscription.findOne admin_id:user_id, (err, subscription)->
|
|
|
|
logger.log user_id:user_id, "got users subscription"
|
|
|
|
callback(err, subscription)
|
2014-02-12 05:23:40 -05:00
|
|
|
|
2018-06-29 12:01:34 -04:00
|
|
|
findManagedSubscription: (managerId, callback)->
|
|
|
|
logger.log managerId: managerId, "finding managed subscription"
|
|
|
|
Subscription.findOne manager_ids: managerId, callback
|
2018-07-11 04:31:57 -04:00
|
|
|
|
2018-11-20 05:48:21 -05:00
|
|
|
getManagedGroupSubscriptions: (user_or_id, callback = (error, managedSubscriptions) ->) ->
|
|
|
|
user_id = @_getUserId(user_or_id)
|
|
|
|
Subscription.find({
|
|
|
|
manager_ids: user_or_id,
|
|
|
|
groupPlan: true
|
|
|
|
}).populate("admin_id").exec callback
|
|
|
|
|
2016-08-30 09:26:57 -04:00
|
|
|
getMemberSubscriptions: (user_or_id, callback) ->
|
2018-11-20 05:48:21 -05:00
|
|
|
user_id = @_getUserId(user_or_id)
|
2014-08-07 10:29:06 -04:00
|
|
|
logger.log user_id: user_id, "getting users group subscriptions"
|
2015-05-22 08:57:15 -04:00
|
|
|
Subscription.find(member_ids: user_id).populate("admin_id").exec callback
|
|
|
|
|
|
|
|
getSubscription: (subscription_id, callback)->
|
|
|
|
Subscription.findOne _id:subscription_id, callback
|
2015-05-27 11:33:47 -04:00
|
|
|
|
|
|
|
getSubscriptionByMemberIdAndId: (user_id, subscription_id, callback)->
|
2016-03-22 12:04:33 -04:00
|
|
|
Subscription.findOne {member_ids: user_id, _id:subscription_id}, {_id:1}, callback
|
|
|
|
|
2018-05-16 11:31:28 -04:00
|
|
|
getGroupSubscriptionsMemberOf: (user_id, callback)->
|
|
|
|
Subscription.find {member_ids: user_id}, {_id:1, planCode:1}, callback
|
2017-06-08 07:12:08 -04:00
|
|
|
|
|
|
|
getGroupsWithEmailInvite: (email, callback) ->
|
2018-06-27 07:09:58 -04:00
|
|
|
Subscription.find { invited_emails: email }, callback
|
|
|
|
|
|
|
|
getGroupWithV1Id: (v1TeamId, callback) ->
|
|
|
|
Subscription.findOne { "overleaf.id": v1TeamId }, callback
|
2018-11-20 05:48:21 -05:00
|
|
|
|
|
|
|
_getUserId: (user_or_id) ->
|
|
|
|
if user_or_id? and user_or_id._id?
|
|
|
|
return user_or_id._id
|
|
|
|
else if user_or_id?
|
|
|
|
return user_or_id
|