static async getList()

in ui/models/job.js [17:65]


  static async getList(options, config = {}) {
    // The `uri` config allows to fetch a list of jobs from an arbitrary
    // endpoint e.g. the similar jobs endpoint. It defaults to the job
    // list endpoint.
    const { fetchAll, uri: configUri } = config;
    const jobUri = configUri || getApiUrl(uri);
    const { data, failureStatus } = await getData(
      `${jobUri}${options ? createQueryParams(options) : ''}`,
    );

    if (!failureStatus) {
      const {
        results,
        job_property_names: jobPropertyNames,
        next: nextUrl,
      } = data;
      let itemList;
      let nextPagesJobs = [];

      if (fetchAll && nextUrl) {
        const page = new URLSearchParams(nextUrl.split('?')[1]).get('page');
        const newOptions = { ...options, page };
        const {
          data: nextData,
          failureStatus: nextFailureStatus,
        } = await JobModel.getList(newOptions, config);

        if (!nextFailureStatus) {
          nextPagesJobs = nextData;
        }
      }
      if (jobPropertyNames) {
        // the results came as list of fields
        // we need to convert them to objects
        itemList = results.map((elem) =>
          addAggregateFields(
            jobPropertyNames.reduce(
              (prev, prop, i) => ({ ...prev, [prop]: elem[i] }),
              {},
            ),
          ),
        );
      } else {
        itemList = results.map((jobObj) => addAggregateFields(jobObj));
      }
      return { data: [...itemList, ...nextPagesJobs], failureStatus: null };
    }
    return { data, failureStatus };
  }