ducky/web

Paddy 2015-07-07 Parent:791aec3eb17b

21:bc1478742a50 Go to Latest

ducky/web/src/models/profile.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
paddy@0 1 import Model from 'ampersand-model'
paddy@12 2 import refresh from '../helpers/oauth-refresh'
paddy@0 3
paddy@0 4 export default Model.extend({
paddy@0 5 props: {
paddy@0 6 'id': 'string',
paddy@0 7 'name': 'string',
paddy@0 8 'created': 'date',
paddy@0 9 'last_seen': 'date',
paddy@0 10 },
paddy@12 11 sync: refresh.Sync,
paddy@12 12 parse (attrs) {
paddy@12 13 if (attrs.profiles && attrs.profiles.length == 1) {
paddy@12 14 attrs = attrs.profiles[0]
paddy@12 15 }
paddy@12 16 return attrs
paddy@12 17 },
paddy@12 18 ajaxConfig () {
paddy@12 19 return {
paddy@12 20 headers: {
paddy@12 21 'Authorization': 'Bearer '+app.me.access_token,
paddy@12 22 'Accept': 'application/json',
paddy@12 23 }
paddy@12 24 }
paddy@12 25 },
paddy@21 26
paddy@21 27 subscription() {
paddy@21 28 return new Promise((resolve, reject) => {
paddy@21 29 app.subscriptions.getOrFetch(this.id, (err, model) => {
paddy@21 30 if (err) {
paddy@21 31 reject(err)
paddy@21 32 } else {
paddy@21 33 resolve(model)
paddy@21 34 }
paddy@21 35 })
paddy@21 36 })
paddy@21 37 },
paddy@0 38 })