summaryrefslogtreecommitdiff
path: root/server/lib
diff options
context:
space:
mode:
authorJulie Lala <jules@okfoc.us>2015-01-30 01:53:32 -0500
committerJulie Lala <jules@okfoc.us>2015-01-30 01:53:32 -0500
commitbc2b23459714fbdde6b990b3f9d574b3d7224f03 (patch)
tree1618f37e21fade1b6b5fccb0d81af982df194b9d /server/lib
parent1d88890a988b255c915d0472297b18a2635f6433 (diff)
subscription routage & middleware
Diffstat (limited to 'server/lib')
-rw-r--r--server/lib/api/subscription.js17
-rw-r--r--server/lib/schemas/Subscription.js2
2 files changed, 17 insertions, 2 deletions
diff --git a/server/lib/api/subscription.js b/server/lib/api/subscription.js
index e7cd8f4..9478d78 100644
--- a/server/lib/api/subscription.js
+++ b/server/lib/api/subscription.js
@@ -24,10 +24,17 @@ var subscription = module.exports = {
next()
})
},
+ ensurePlans: function(req, res, next){
+ Plan.find({}).sort({ 'level': -1 }).exec(function (err, plans) {
+ res.locals.plans = (plans || [])
+ next()
+ })
+ },
},
// synchronise an account with recurly..
// useful when testing locally (where webhooks cannot be received)
+ // parses the XML from the subscription API into something usable
sync: function(req, res){
var subscriber = req.subscription || new Subscription ()
var user = req.user
@@ -84,7 +91,15 @@ var subscription = module.exports = {
},
show: function(req, res){
- res.json(req.subscription || { error: "no subscription" })
+ if (req.subscription) {
+ res.json({
+ subscription: req.subscription,
+ plans: res.locals.plans
+ })
+ }
+ else {
+ res.json({ error: "no subscription" })
+ }
},
update: function(req, res){
diff --git a/server/lib/schemas/Subscription.js b/server/lib/schemas/Subscription.js
index 24c5096..44455a9 100644
--- a/server/lib/schemas/Subscription.js
+++ b/server/lib/schemas/Subscription.js
@@ -18,7 +18,7 @@ var SubscriptionSchema = new mongoose.Schema({
history: [{
action: { type: String },
- plan_id: { type: String },
+ data: { type: String },
created_at: { type: Date, default: Date.now },
}],