open-nomad/ui/mirage/serializers/job-version.js
2023-04-10 15:36:59 +00:00

34 lines
805 B
JavaScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: MPL-2.0
*/
import ApplicationSerializer from './application';
export default ApplicationSerializer.extend({
serialize() {
var json = ApplicationSerializer.prototype.serialize.apply(this, arguments);
if (!(json instanceof Array)) {
json = [json];
}
return json
.sortBy('SubmitTime')
.reverse()
.reduce(
(hash, version) => {
hash.Diffs.push(version.Diff);
delete version.Diff;
// ID is used for record tracking within Mirage,
// but Nomad uses the JobID as the version ID.
version.ID = version.TempVersionID;
hash.Versions.push(version);
return hash;
},
{ Versions: [], Diffs: [] }
);
},
});