github.com/hernad/nomad@v1.6.112/ui/app/serializers/recommendation.js (about)

     1  /**
     2   * Copyright (c) HashiCorp, Inc.
     3   * SPDX-License-Identifier: MPL-2.0
     4   */
     5  
     6  import { assign } from '@ember/polyfills';
     7  import ApplicationSerializer from './application';
     8  import classic from 'ember-classic-decorator';
     9  import queryString from 'query-string';
    10  
    11  @classic
    12  export default class RecommendationSerializer extends ApplicationSerializer {
    13    attrs = {
    14      taskName: 'Task',
    15    };
    16  
    17    separateNanos = ['SubmitTime'];
    18  
    19    extractRelationships(modelClass, hash) {
    20      const namespace =
    21        !hash.Namespace || hash.Namespace === 'default'
    22          ? undefined
    23          : hash.Namespace;
    24  
    25      const [jobURL] = this.store
    26        .adapterFor('job')
    27        .buildURL('job', JSON.stringify([hash.JobID]), hash, 'findRecord')
    28        .split('?');
    29  
    30      return assign(super.extractRelationships(...arguments), {
    31        job: {
    32          links: {
    33            related: buildURL(jobURL, { namespace }),
    34          },
    35        },
    36      });
    37    }
    38  }
    39  
    40  function buildURL(path, queryParams) {
    41    const qpString = queryString.stringify(queryParams);
    42    if (qpString) {
    43      return `${path}?${qpString}`;
    44    }
    45    return path;
    46  }