From d4955c1ed067b0456faf683303f2b1d1975d64dc Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Wed, 2 Dec 2015 12:34:05 +0100 Subject: [PATCH] Fix hooks toggling New ember-data serializers send data without a model key in the payload by default, so instead of what API expects: { "hook": { "id": 1, "active": true } } it would send: { "id": 1, "active": true } Because of that we need to change how hooks are serialized. Furthermore, API V2 returns just "result: true" after a successful request to change a hook, so we need to return something meaningful from the adapter's updateRecord in order to make ember-data happy. --- app/adapters/hook.js | 9 +++++++++ app/serializers/hook.js | 7 +++++++ 2 files changed, 16 insertions(+) create mode 100644 app/adapters/hook.js create mode 100644 app/serializers/hook.js diff --git a/app/adapters/hook.js b/app/adapters/hook.js new file mode 100644 index 00000000..153c036b --- /dev/null +++ b/app/adapters/hook.js @@ -0,0 +1,9 @@ +import ApplicationAdapter from 'travis/adapters/application'; + +export default ApplicationAdapter.extend({ + updateRecord(store, type, snapshot) { + return this._super(...arguments).then( (data) => { + return { hook: { id: snapshot.id } }; + }); + } +}); diff --git a/app/serializers/hook.js b/app/serializers/hook.js new file mode 100644 index 00000000..33df0b84 --- /dev/null +++ b/app/serializers/hook.js @@ -0,0 +1,7 @@ +import ApplicationSerializer from 'travis/serializers/application'; + +export default ApplicationSerializer.extend({ + serialize(snapshot, options) { + return { hook: this._super(...arguments) }; + } +});