ducky/web
ducky/web/src/models/profiles.js
Make production builds possible. Our production builds were erroring out, making it hard to deploy. This fixes things so that our production builds succeed, though I'm lying if I say I understand all the reasoning behind it. The major reasoning seems to be "BUGS".
1 import Collection from 'ampersand-rest-collection'
2 import Sync from 'ampersand-sync'
3 import Profile from './profile'
4 import config from '../config'
5 import isObject from 'lodash.isobject'
6 import refresh from '../helpers/oauth-refresh'
7 import app from 'ampersand-app'
9 export default Collection.extend({
10 model: Profile,
11 url: config.urlBase + '/profiles',
12 ajaxConfig () {
13 return {
14 headers: {
15 'Authorization': 'Bearer '+app.me.access_token,
16 'Accept': 'application/json',
17 }
18 }
19 },
21 sync: refresh.Sync,
23 register (email, passphrase) {
24 let options = {
25 data: JSON.stringify({
26 'email': email,
27 'passphrase': passphrase,
28 })
29 }
30 let moc = this
31 options.success = function(resp) {
32 if (!resp.profiles || resp.profiles.length < 1) {
33 return false
34 }
35 let serverAttrs = moc.parse(resp.profiles[0], options)
36 if (options.wait) serverAttrs = assign({}, serverAttrs)
37 if (isObject(serverAttrs) && !moc.add(serverAttrs, options)) {
38 return false
39 }
40 moc.trigger('sync', moc, resp, options)
41 }
42 options.error = function(resp) {
43 moc.trigger('error', moc, resp, options)
44 }
45 let sync = Sync('create', moc, options)
46 return sync
47 },
48 })