refactor: 💡 serialize scope_id by default

This commit is contained in:
Randall Morey committed 2020-09-10 18:32:17 -04:00
1 parent 974b557ae2
commit ab608c7544
21 files changed
+7 -266

No files matched your search

+5 -16
View File
@@ -8,18 +8,6 @@ import { copy } from 'ember-copy';
*/
export default class ApplicationSerializer extends RESTSerializer {
// =attributes
attrs = {
scope: { serialize: false }
};
/**
* Whether or not to serialize the scope ID into scope_id.
* @type {boolean}
*/
serializeScopeID = false;
// =methods
/**
@@ -81,10 +69,11 @@ export default class ApplicationSerializer extends RESTSerializer {
*/
serialize(snapshot) {
const serialized = super.serialize(...arguments);
if (this.serializeScopeID) {
const scope_id = snapshot?.attr('scope')?.attr('scope_id');
if (scope_id) serialized.scope_id = scope_id;
}
// Delete `scope` field
delete serialized.scope;
// And serialize `scope_id`
const scope_id = snapshot?.attr('scope')?.attr('scope_id');
if (scope_id) serialized.scope_id = scope_id;
return serialized;
}