mercredi 20 novembre 2019

EmberJS: queryRecord - adapter returns a JSON object but the call ultimately returns null

I am dumbfounded and have a hard time debugging this.

This is my adapter, it returns a settings object.

import DS from "ember-data";
import * as authServer from "doodledocs-app/config/auth-ms";
import DataAdapterMixin from "ember-simple-auth/mixins/data-adapter-mixin";

export default DS.RESTAdapter.extend(DataAdapterMixin, {
  authorizer: "authorizer:devise",
  async queryRecord(store, type, data) {
    const response = await fetch(`${authServer.HOST}/settings`, {
      method: "GET",
      headers: { Authorization: data.token }
    });
    const json = await response.json();
    console.log("res settings", json); //this works
    return json; //it doesn't matter what I return, queryRecord ultimately returns null
  }
});

It returns: settings {id: 1, pencil_thickness: 1, pencil_pressure_sensitivity: 1, eraser_thickness: 20, annotation_options: true, …}

The model is straightforward:

import DS from "ember-data";

export default DS.Model.extend({
  user: DS.belongsTo("user"),
  pencil_thickness: DS.attr("number"),
  pencil_pressure_sensitivity: DS.attr("number"),
  eraser_thickness: DS.attr("number"),
  annotation_options: DS.attr("boolean")
});

This is my route of settings.js

import Route from "@ember/routing/route";
import { inject as service } from "@ember/service";

export default Route.extend({
  session: service(),
  async model() {
    const session = this.session.data.authenticated;
    const result = await this.store.queryRecord("settings", session);
    console.log("result", result); //this returns null...
  }
});

How come that it returns null and not the settings record?




Aucun commentaire:

Enregistrer un commentaire