ducky/web

Paddy 2015-07-07

21:bc1478742a50 Go to Latest

ducky/web/src/models/subscription.js

Implement subscriptions. Create a Subscription model and a Subscriptions collection, and attach them to the app context. Add a helper to our Profile model to retrieve the Subscription of that model. Still not sure this should be on the Profile--wouldn't it be better on the Me model? Isn't that generally where we would need it?

History
1 import Model from 'ampersand-model'
2 import refresh from '../helpers/oauth-refresh'
4 export default Model.extend({
5 props: {
6 'userID': 'string',
7 'stripe_subscription': 'string',
8 'plan': 'string',
9 'status': 'string',
10 'canceling': 'boolean',
11 'created': 'date',
12 'trialStart': 'date',
13 'trialEnd': 'date',
14 'periodStart': 'date',
15 'periodEnd': 'date',
16 'canceledAt': 'date',
17 'failedChargeAttempts': 'integer',
18 'lastFailedCharge': 'date',
19 'lastNotified': 'date',
20 },
21 idAttribute: 'userID',
22 sync: refresh.Sync,
23 parse (attrs) {
24 if (attrs.subscriptions && attrs.subscriptions.length == 1) {
25 attrs = attrs.subscriptions[0]
26 }
27 attrs.userID = attrs.user_id
28 attrs.stripeSubscription = attrs.stripeSubscription
29 attrs.trialStart = attrs.trial_start
30 attrs.trialEnd = attrs.trial_end
31 attrs.periodStart = attrs.period_start
32 attrs.periodEnd = attrs.period_end
33 attrs.canceledAt = attrs.canceled_at
34 attrs.failedChargeAttempts = attrs.failed_charge_attempts
35 attrs.lastFailedCharge = attrs.last_failed_charge
36 attrs.lastNotified = attrs.last_notified
37 return attrs
38 },
39 ajaxConfig () {
40 return {
41 headers: {
42 'Authorization': 'Bearer '+app.me.access_token,
43 'Accept': 'application/json',
44 }
45 }
46 },
47 })