mirror of
https://github.com/HackPlan/RootPanel.git
synced 2026-03-26 22:16:28 +08:00
43 lines
1.1 KiB
CoffeeScript
43 lines
1.1 KiB
CoffeeScript
plugin = require './plugin'
|
|
|
|
mAccount = require './model/account'
|
|
|
|
exports.joinPlan = (account, plan, callback) ->
|
|
mAccount.joinPlan account, plan, ->
|
|
async.each config.plans[plan].services, (serviceName, callback) ->
|
|
if serviceName in account.attribute.services
|
|
return callback()
|
|
|
|
mAccount.update _id: account._id,
|
|
$addToSet:
|
|
'attribute.services': serviceName
|
|
, ->
|
|
(plugin.get serviceName).service.enable account, ->
|
|
callback()
|
|
|
|
, ->
|
|
callback()
|
|
|
|
exports.leavePlan = (account, plan, callback) ->
|
|
mAccount.leavePlan account, plan, ->
|
|
async.each config.plans[plan].services, (serviceName, callback) ->
|
|
stillInService = do ->
|
|
for item in _.without(account.attribute.plans, plan)
|
|
if serviceName in config.plans[item].services
|
|
return true
|
|
|
|
return false
|
|
|
|
if stillInService
|
|
callback()
|
|
else
|
|
mAccount.update _id: account._id,
|
|
$pull:
|
|
'attribute.services': serviceName
|
|
, ->
|
|
(plugin.get serviceName).service.delete account, ->
|
|
callback()
|
|
|
|
, ->
|
|
callback()
|