lundi 2 octobre 2017

undefined has no properties - Ember Store

I have created my own custom adapter in Ember in order to work with Passport for Express.

The code that I have for the adapter is as follows:

import Ember from 'ember';
import DS from 'ember-data';


$.ajaxSetup({
  xhrFields: {
    withCredentials: true
  },
  headers: {
           'connect.sid': this.get('cookies').read('connect.sid'),
           'AuthToken': this.get('cookies').read('connect.sid')
         },
  });

export default DS.RESTAdapter.extend({

  config: Ember.inject.service(),
  namespace: 'api',
  host: 'http://localhost:3000',
  headers: {
           'connect.sid': this.get('cookies').read('connect.sid'),
        },
  ajax(url, method, hash) {
    headers: headers,
    crossDomain = true;
    xhrFields = {
      withCredentials: true
    };
    return this._super(url, method, hash);
  },
});

I am trying to send data to express whilst creating a local record in Ember. The error that I keep on recieving is:

undefined has no properties

This is the code where I am trying to create a new record

//Return the promise
  return promise.then((result) => {
    //debugging
    var obj = result;
    console.log(obj);
    var message
    if(result.error){
      console.log("error exists - let's reject")
      message = promise["error"];
      return Promise.reject(message);
    } else {
      console.log("promise accepted")
      console.log(obj.sensor)
      console.log(obj.sensor.name)
      const newPost = this.get('store').createRecord('sensor', {name: 'title', identification: 'content'});
      console.log('done')
      message = promise;
      return Promise.resolve(message);
    }
  })

I have defined the store with

store: Ember.inject.service(),

and,

var store = this.get('store');

I am unsure why it is stating that the store is undefined and have been stuck on this for a few hours now.

Any help is appreciated thanks!




Aucun commentaire:

Enregistrer un commentaire