all files / app/pods/city/ route.js

100% Statements 24/24
75% Branches 9/12
100% Functions 6/6
100% Lines 6/6
6 statements, 1 function, 3 branches Ignored     
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87                                                                                                                                                                   
import Route from 'ember-route'
import RSVP from 'rsvp'
 
 
 
export default Route.extend({
 
  // ----- Services -----
 
 
 
  // ----- Overridden properties -----
 
 
 
  // ----- Static properties -----
 
 
 
  // ----- Computed properties -----
 
 
 
  // ----- Overridden Methods -----
  model ({
    cityId,
    usersURL  = 'https://cdn.rawgit.com/brianw/19896c50afa89ad4dec3/raw/6c11047887a03483c50017c1d451667fd62a53ca/gistfile1.txt',
    citiesURL = 'https://cdn.rawgit.com/lolmaus/d78a75f903b176a488a0e6533e65ca8b/raw/a7919fa7c9b3359a975bdd56a917d26060f7c7fe/cities.json'
  } = {}) {
    const store = this.get('store')
 
    return RSVP
      .hash({
        users:  store.query('user', {url: usersURL}),
        cities: store.query('city', {url: citiesURL}),
      })
 
      .then(model => RSVP.hash({
        ...model,
        currentCity: model.cities.findBy('id', cityId),
      }))
 
      .then(model => RSVP.hash({
        ...model,
        userCityJunctions: this._populateJunctions({
          currentCity: model.currentCity,
          users:       model.users
        })
      }))
  },
 
 
 
  // ----- Custom Methods -----
  _populateJunctions ({currentCity, users}) {
    const store  = this.get('store')
 
    const payload = {
      data: users.map(user => ({
        id: `${user.id}-${currentCity.id}`,
        type: 'user-city-junction',
        relationships: {
          user: {data: {id: user.id,        type: 'user'}},
          city: {data: {id: currentCity.id, type: 'city'}},
        }
      }))
    }
 
    return store.push(payload)
  },
 
 
 
  // ----- Events and observers -----
 
 
 
  // ----- Tasks -----
 
 
 
  // ----- Actions -----
  // actions: {
  // }
})