89136cbf6a
Manual interventions: • decorators on the same line for service and controller injections and most computed property macros • preserving import order when possible, both per-line and intra-line • moving new imports to the bottom • removal of classic decorator for trivial cases • conversion of init to constructor when appropriate
34 lines
1 KiB
JavaScript
34 lines
1 KiB
JavaScript
import ApplicationSerializer from './application';
|
|
|
|
// Convert a map[string]interface{} into an array of objects
|
|
// where the key becomes a property at propKey.
|
|
// This is destructive. The original object is mutated to avoid
|
|
// excessive copies of the originals which would otherwise just
|
|
// be garbage collected.
|
|
const unmap = (hash, propKey) =>
|
|
Object.keys(hash).map(key => {
|
|
const record = hash[key];
|
|
record[propKey] = key;
|
|
return record;
|
|
});
|
|
|
|
export default class Plugin extends ApplicationSerializer {
|
|
normalize(typeHash, hash) {
|
|
hash.PlainId = hash.ID;
|
|
|
|
// TODO This shouldn't hardcode `csi/` as part of the ID,
|
|
// but it is necessary to make the correct find request and the
|
|
// payload does not contain the required information to derive
|
|
// this identifier.
|
|
hash.ID = `csi/${hash.ID}`;
|
|
|
|
const nodes = hash.Nodes || {};
|
|
const controllers = hash.Controllers || {};
|
|
|
|
hash.Nodes = unmap(nodes, 'NodeID');
|
|
hash.Controllers = unmap(controllers, 'NodeID');
|
|
|
|
return super.normalize(typeHash, hash);
|
|
}
|
|
}
|