feat: 🎸 add support for custom cancel session method

This commit is contained in:
Randall Morey committed 2020-09-18 10:59:07 -04:00
1 parent 9e482d6434
commit 7a17ff3bfa
5 files changed
+94 -2

No files matched your search

+31
View File
@@ -0,0 +1,31 @@
import ApplicationSerializer from './application';
export default class SessionSerializer extends ApplicationSerializer {
// =methods
/**
* If `adapterOptions.method` is `cancel`, the serialization should
* include the version field only.
* @override
* @param {Snapshot} snapshot
* @return {object}
*/
serialize(snapshot) {
let serialized = super.serialize(...arguments);
if (snapshot?.adapterOptions?.method === 'cancel') {
serialized = this.serializeForCancel(snapshot);
}
return serialized;
}
/**
* Returns a payload containing only version
* @param {Snapshot} snapshot
* @return {object}
*/
serializeForCancel(snapshot) {
return {
version: snapshot.attr('version'),
};
}
}