Unfinished fragment managed groups modeling

This commit is contained in:
Carlos Alcaide Corvo committed 2021-11-05 08:55:37 -07:00
1 parent 6022d7fc36
commit 499432522a
4 files changed
+68 -1

No files matched your search

@@ -0,0 +1,23 @@
import JSONSerializer from '@ember-data/serializer/json';
export default class FragmentManagedGroupsAttributesSerializer extends JSONSerializer {
/**
* If an attribute is annotated as readOnly in the model, don't serialize it.
* Otherwise delegate to default attribute serializer.
* @override
* @method serializeAttribute
* @param {Snapshot} snapshot
* @param {Object} json
* @param {String} key
* @param {Object} attribute
*/
serializeAttribute(snapshot, json, key, attribute) {
const { type, options } = attribute;
let value = super.serializeAttribute(...arguments);
// COnvert empty strin to null.
if (type === 'string' && json[key] === '') json[key] = null;
// Do not serialize read-only attributes.
if (options.readOnly) delete json[key];
return value;
}
}