summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/jobs/components/filtered_search/utils.js
blob: 696cd8d4706dd9a2ae11d848ca6a2f3547ebbe9c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import { jobStatusValues } from './constants';

// validates query string used for filtered search
// on jobs table to ensure GraphQL query is called correctly
export const validateQueryString = (queryStringObj) => {
  // currently only one token is supported `statuses`
  // this code will need to be expanded as more tokens
  // are introduced

  const filters = Object.keys(queryStringObj);

  if (filters.includes('statuses')) {
    const queryStringStatus = {
      statuses: queryStringObj.statuses.toUpperCase(),
    };

    const found = jobStatusValues.find((status) => status === queryStringStatus.statuses);

    if (found) {
      return queryStringStatus;
    }

    return null;
  }

  return null;
};