I am using ember 2.18, in this the update requests are PATCH. However, the backend is in SAILS and it does not support PATCH. Hence, I have to convert patch request to PUT.
I saw this issue and people seems to have solved it there. But it does not work for me. The code is as follows:
import App from './../app';
import DS from "ember-data";
import { computed } from "@ember/object";
import { camelize } from '@ember/string';
import JSONAPIAdapter from "ember-data/adapters/json-api";
export default DS.JSONAPIAdapter.extend({
coalesceFindRequests: true,
host: App.GPT.Configuration.restServer,
methodForRequest: ({ requestType }) => {
console.log('Log')
if (requestType === "updateRecord") {
return "PUT";
}
return this._super(...arguments);
},
pathForType(type) {
return camelize(type) + 's';
},
headers: computed(function () {
if (!App.StoreUtil.getSessionId()) {
if (App.GPT.ApplicationController) {
App.GPT.ApplicationController.set("hasMessages", [
{
message: "Session expired."
}
]);
App.GPT.ApplicationController.transitionToRoute("/");
} else {
window.location = "/";
}
}
return {
sid: App.StoreUtil.getSessionId()
};
}).volatile()
});
The code added to convert the request to PUT is :
methodForRequest: ({ requestType }) => {
console.log('Log')
if (requestType === "updateRecord") {
return "PUT";
}
return this._super(...arguments);
}
However, the method is not called at all. The funny part is pathForType is called for every request.
Aucun commentaire:
Enregistrer un commentaire