2014-02-12 10:23:40 +00:00
|
|
|
Subscription = require('../../models/Subscription').Subscription
|
|
|
|
logger = require("logger-sharelatex")
|
|
|
|
ObjectId = require('mongoose').Types.ObjectId
|
|
|
|
|
|
|
|
module.exports =
|
|
|
|
|
|
|
|
getUsersSubscription: (user_or_id, callback)->
|
|
|
|
if user_or_id? and user_or_id._id?
|
|
|
|
user_id = user_or_id._id
|
|
|
|
else if user_or_id?
|
|
|
|
user_id = user_or_id
|
|
|
|
logger.log user_id:user_id, "getting users subscription"
|
2015-07-22 09:38:28 +00:00
|
|
|
Subscription.findOne admin_id:user_id, (err, subscription)->
|
|
|
|
logger.log user_id:user_id, "got users subscription"
|
|
|
|
callback(err, subscription)
|
2014-02-12 10:23:40 +00:00
|
|
|
|
2014-08-07 14:29:06 +00:00
|
|
|
getMemberSubscriptions: (user_id, callback) ->
|
|
|
|
logger.log user_id: user_id, "getting users group subscriptions"
|
2015-05-22 12:57:15 +00: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 15:33:47 +00:00
|
|
|
|
|
|
|
getSubscriptionByMemberIdAndId: (user_id, subscription_id, callback)->
|
2016-03-22 16:04:33 +00:00
|
|
|
Subscription.findOne {member_ids: user_id, _id:subscription_id}, {_id:1}, callback
|
|
|
|
|
|
|
|
getGroupSubscriptionMemberOf: (user_id, callback)->
|
2016-04-05 14:50:15 +00:00
|
|
|
Subscription.findOne {member_ids: user_id}, {_id:1, planCode:1}, callback
|