overleaf/services/web/app/coffee/Features/Subscription/SubscriptionLocator.coffee

49 lines
1.8 KiB
CoffeeScript
Raw Normal View History

2014-02-12 05:23:40 -05:00
Subscription = require('../../models/Subscription').Subscription
logger = require("logger-sharelatex")
ObjectId = require('mongoose').Types.ObjectId
2014-02-12 05:23:40 -05:00
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 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
getManagedSubscription: (managerId, callback)->
logger.log managerId: managerId, "getting managed subscription"
Subscription.findOne admin_id: managerId, (err, subscription)->
if subscription?
logger.log managerId: managerId, "got managed subscription"
else
err ||= new Error("No subscription found managed by user #{managerId}")
callback(err, subscription)
getMemberSubscriptions: (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 group subscriptions"
Subscription.find(member_ids: user_id).populate("admin_id").exec callback
getSubscription: (subscription_id, callback)->
Subscription.findOne _id:subscription_id, callback
getSubscriptionByMemberIdAndId: (user_id, subscription_id, callback)->
Subscription.findOne {member_ids: user_id, _id:subscription_id}, {_id:1}, callback
getGroupSubscriptionsMemberOf: (user_id, callback)->
Subscription.find {member_ids: user_id}, {_id:1, planCode:1}, callback
getGroupsWithEmailInvite: (email, callback) ->
Subscription.find { invited_emails: email }, callback
getGroupWithV1Id: (v1TeamId, callback) ->
Subscription.findOne { "overleaf.id": v1TeamId }, callback