mirror of
https://github.com/kemko/nomad.git
synced 2026-01-03 00:45:43 +03:00
44 lines
1.1 KiB
JavaScript
44 lines
1.1 KiB
JavaScript
import classic from 'ember-classic-decorator';
|
|
import ApplicationSerializer from './application';
|
|
|
|
@classic
|
|
export default class VariableSerializer extends ApplicationSerializer {
|
|
primaryKey = 'Path';
|
|
separateNanos = ['CreateTime', 'ModifyTime'];
|
|
|
|
// Transform API's Items object into an array of a KeyValue objects
|
|
normalizeFindRecordResponse(store, typeClass, hash, id, ...args) {
|
|
// TODO: prevent items-less saving at API layer
|
|
if (!hash.Items) {
|
|
hash.Items = { '': '' };
|
|
}
|
|
hash.KeyValues = Object.entries(hash.Items).map(([key, value]) => {
|
|
return {
|
|
key,
|
|
value,
|
|
};
|
|
});
|
|
delete hash.Items;
|
|
return super.normalizeFindRecordResponse(
|
|
store,
|
|
typeClass,
|
|
hash,
|
|
id,
|
|
...args
|
|
);
|
|
}
|
|
|
|
// Transform our KeyValues array into an Items object
|
|
serialize(snapshot, options) {
|
|
const json = super.serialize(snapshot, options);
|
|
json.Items = json.KeyValues.reduce((acc, { key, value }) => {
|
|
acc[key] = value;
|
|
return acc;
|
|
}, {});
|
|
delete json.KeyValues;
|
|
delete json.ModifyTime;
|
|
delete json.CreateTime;
|
|
return json;
|
|
}
|
|
}
|