github.com/aminovpavel/nomad@v0.11.8/ui/mirage/serializers/csi-volume.js (about)

     1  import ApplicationSerializer from './application';
     2  
     3  const groupBy = (list, attr) => {
     4    return list.reduce((group, item) => {
     5      group[item[attr]] = item;
     6      return group;
     7    }, {});
     8  };
     9  
    10  export default ApplicationSerializer.extend({
    11    embed: true,
    12    include: ['writeAllocs', 'readAllocs'],
    13  
    14    serialize() {
    15      var json = ApplicationSerializer.prototype.serialize.apply(this, arguments);
    16      if (json instanceof Array) {
    17        json.forEach(serializeVolume);
    18      } else {
    19        serializeVolume(json);
    20      }
    21      return json;
    22    },
    23  });
    24  
    25  function serializeVolume(volume) {
    26    volume.WriteAllocs = groupBy(volume.WriteAllocs, 'ID');
    27    volume.ReadAllocs = groupBy(volume.ReadAllocs, 'ID');
    28  }