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

36 lines
944 B
JavaScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: MPL-2.0
*/
import ApplicationSerializer from './application';
export default ApplicationSerializer.extend({
embed: true,
include: ['task', 'task.task-group'],
serialize() {
var json = ApplicationSerializer.prototype.serialize.apply(this, arguments);
if (json instanceof Array) {
json.forEach(recommendationJson => serializeRecommendation(recommendationJson, this.schema));
} else {
serializeRecommendation(json, this.schema);
}
return json;
},
});
function serializeRecommendation(recommendation, schema) {
const taskJson = recommendation.Task;
recommendation.Task = taskJson.Name;
const taskGroup = schema.taskGroups.find(taskJson.TaskGroupID);
recommendation.Group = taskGroup.name;
recommendation.JobID = taskGroup.job.id;
recommendation.Namespace = taskGroup.job.namespace || 'default';
return recommendation;
}