Skip to content

Instantly share code, notes, and snippets.

@EdwardIII
Last active November 17, 2016 15:29
Show Gist options
  • Save EdwardIII/bf5f307266d0a867bcef84d5666f16b4 to your computer and use it in GitHub Desktop.
Save EdwardIII/bf5f307266d0a867bcef84d5666f16b4 to your computer and use it in GitHub Desktop.
import Ember from 'ember';
export default Ember.Route.extend({
'currentOrder': Ember.inject.service(),
model(){
return Ember.Object.create({
// in the template: (subclass of Ember.ArrayProxy) == :)
'invoices': this.get('store').findAll('invoice'),
// in the template: [object Object] == :(
'currentOrders': this.get('currentOrder').current()
});
}
});
import Ember from 'ember';
export default Ember.Service.extend({
currentUser: Ember.inject.service(),
store: Ember.inject.service(),
orderBasket: Ember.inject.service(),
order: function(){
return this.get('currentUser').user()
.then(user => user.get('orders'))
.then(orders => orders.get('firstObject'));
},
past(){
return this._orders_for('past');
},
current(){
return this._orders_for('current');
},
addOption(option, quantity){
return this.order().then((order) => this.get('orderBasket').add(order, option, quantity));
},
_orders_for(type){
return this
.get('currentUser')
.user()
.then(user => this._filter(user, {type: type}));
},
_filter(user, by){
return this
.get('store')
.query('order', {
user_id: user.get('id'),
filters: by
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment