2023-04-10 15:36:59 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) HashiCorp, Inc.
|
|
|
|
* SPDX-License-Identifier: MPL-2.0
|
|
|
|
*/
|
|
|
|
|
2020-10-29 12:46:42 +00:00
|
|
|
import { assign } from '@ember/polyfills';
|
|
|
|
import ApplicationSerializer from './application';
|
|
|
|
import classic from 'ember-classic-decorator';
|
|
|
|
import queryString from 'query-string';
|
|
|
|
|
|
|
|
@classic
|
|
|
|
export default class RecommendationSerializer extends ApplicationSerializer {
|
|
|
|
attrs = {
|
|
|
|
taskName: 'Task',
|
|
|
|
};
|
|
|
|
|
|
|
|
separateNanos = ['SubmitTime'];
|
|
|
|
|
|
|
|
extractRelationships(modelClass, hash) {
|
2021-12-28 16:08:12 +00:00
|
|
|
const namespace =
|
|
|
|
!hash.Namespace || hash.Namespace === 'default'
|
|
|
|
? undefined
|
|
|
|
: hash.Namespace;
|
2020-10-29 12:46:42 +00:00
|
|
|
|
|
|
|
const [jobURL] = this.store
|
|
|
|
.adapterFor('job')
|
|
|
|
.buildURL('job', JSON.stringify([hash.JobID]), hash, 'findRecord')
|
|
|
|
.split('?');
|
|
|
|
|
|
|
|
return assign(super.extractRelationships(...arguments), {
|
|
|
|
job: {
|
|
|
|
links: {
|
|
|
|
related: buildURL(jobURL, { namespace }),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function buildURL(path, queryParams) {
|
|
|
|
const qpString = queryString.stringify(queryParams);
|
|
|
|
if (qpString) {
|
|
|
|
return `${path}?${qpString}`;
|
|
|
|
}
|
|
|
|
return path;
|
|
|
|
}
|