Skip to content

Commit

Permalink
Convert iife to getter
Browse files Browse the repository at this point in the history
  • Loading branch information
Zacqary committed Mar 9, 2020
1 parent 727ce49 commit 5377c91
Showing 1 changed file with 15 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,20 @@ const getCurrentValueFromAggregations = (aggregations: Aggregation) => {
return value;
};

const getParsedFilterQuery: (filterQuery: string) => Record<string, any> = filterQuery => {
if (!filterQuery) return {};
try {
return JSON.parse(filterQuery).bool;
} catch (e) {
return {
query_string: {
query: filterQuery,
analyze_wildcard: true,
},
};
}
};

const getMetric: (
services: AlertServices,
params: MetricExpressionParams,
Expand Down Expand Up @@ -97,20 +111,7 @@ const getMetric: (
}
: baseAggs;

const parsedFilterQuery = filterQuery
? (() => {
try {
return JSON.parse(filterQuery).bool;
} catch (e) {
return {
query_string: {
query: filterQuery,
analyze_wildcard: true,
},
};
}
})()
: {};
const parsedFilterQuery = getParsedFilterQuery(filterQuery);

const searchBody = {
query: {
Expand Down

0 comments on commit 5377c91

Please sign in to comment.