open-nomad/ui/mirage/serializers/job.js
Mahmood Ali 16f7a3f31b ui: protect against nil services
Protect against case where an alloc has no services and avoid
dereferencing null.

Here, we ensure that the model and test serializers mimic the API by
having nil TaskGroup.Services instead of an empty array.
2019-09-16 16:50:30 -04:00

25 lines
540 B
JavaScript

import ApplicationSerializer from './application';
export default ApplicationSerializer.extend({
embed: true,
include: ['task_groups', 'job_summary'],
serialize() {
var json = ApplicationSerializer.prototype.serialize.apply(this, arguments);
if (json instanceof Array) {
json.forEach(serializeJob);
} else {
serializeJob(json);
}
return json;
},
});
function serializeJob(job) {
job.TaskGroups.forEach(group => {
if (group.Services.length === 0) {
group.Services = null;
}
});
}