I am trying to make a post request using Ember Data and using JSON server in the backend.
I can see a POST /results 201 0.847 ms - 23
in console but in actual JSON file it's just an empty object with just id
{"id": "rkU3UcPRW"}
My Model looks like
import DS from 'ember-data';
export default DS.Model.extend({
quizAttemped: DS.attr('string'),
quizId: DS.attr('string'),
timeAttempedAt: DS.attr('string'),
result: DS.attr(),
attempedBy: DS.attr('string'),
postedBy: DS.attr('string')});
My Adapter Looks like
import DS from 'ember-data';
export default DS.JSONAPIAdapter.extend({
namespace: '',
host: 'http://localhost:3000',
headers: function() {
var headers = {};
headers['Content-Type'] = 'application/vnd.api+json';
return headers;
},
save: function() {
return this._super();
}});
Serializer
import DS from 'ember-data';
export default DS.JSONSerializer.extend({});
And i am calling
postResults() {
let store = this.get('store');
const quizId = this.get('evaluatingQuizId');
store.find('quiz', quizId).then((data) => {
store.createRecord('result', {
quizAttemped: data.data.topic,
quizId: quizId,
timeAttempedAt: new Date().getTime(),
result: this.get('resultArray'),
attempedBy: this.get('userInsession.emailId'),
postedBy: data.data.postedBy
}).save();
});
}
Aucun commentaire:
Enregistrer un commentaire