mirror of
https://github.com/HackPlan/RootPanel.git
synced 2026-03-28 07:28:57 +08:00
plan/unsubscribe
This commit is contained in:
@@ -25,3 +25,7 @@ Request:
|
||||
}
|
||||
|
||||
No Response.
|
||||
|
||||
Exception:
|
||||
|
||||
* not_in_plan
|
||||
|
||||
@@ -40,3 +40,30 @@ module.exports =
|
||||
return res.json {}
|
||||
|
||||
unsubscribe: (req, res) ->
|
||||
mAccount.authenticate req.token, (account) ->
|
||||
unless account
|
||||
return res.json 400, error: 'auth_failed'
|
||||
|
||||
unless req.body.plan in account.attribute.plans
|
||||
return res.json 400, error: 'not_in_plan'
|
||||
|
||||
billing.calcBiling account, (account) ->
|
||||
async.each config.plans[req.body.plan].service, (serviceName, callback) ->
|
||||
stillInService = do ->
|
||||
for item in account.attribute.plans
|
||||
if serviceName in config.plans[req.body.plan].service
|
||||
return true
|
||||
|
||||
return false
|
||||
|
||||
if stillInService
|
||||
callback()
|
||||
else
|
||||
mAccount.uodate _id: account._id,
|
||||
$pull:
|
||||
'attribute.service': serviceName
|
||||
, {}, ->
|
||||
(plugin.get serviceName).service.delete account, ->
|
||||
callback()
|
||||
, ->
|
||||
return res.json {}
|
||||
|
||||
Reference in New Issue
Block a user