mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2025-12-18 04:06:19 +00:00
fix: apply correct types and tslint rules
This commit is contained in:
committed by
Rainer Killinger
parent
9db091c26f
commit
0cbf9b26a9
@@ -30,7 +30,13 @@ import {MailQueue} from '../../notification/mail-queue';
|
||||
import {Bulk} from '../bulk-storage';
|
||||
import {Database} from '../database';
|
||||
import {buildAggregations, parseAggregations} from './aggregations';
|
||||
import {AggregationSchema, ElasticsearchConfig, ElasticsearchObject} from './common';
|
||||
import {
|
||||
AggregationSchema,
|
||||
ElasticsearchConfig,
|
||||
ElasticsearchObject,
|
||||
ElasticsearchQueryDisMaxConfig,
|
||||
ElasticsearchQueryQueryStringConfig,
|
||||
} from './common';
|
||||
import * as Monitoring from './monitoring';
|
||||
import {buildQuery, buildSort} from './query';
|
||||
import {putTemplate} from './templating';
|
||||
@@ -167,11 +173,13 @@ export class Elasticsearch implements Database {
|
||||
*/
|
||||
constructor(private readonly config: SCConfigFile, mailQueue?: MailQueue) {
|
||||
|
||||
if (typeof config.internal.database === 'undefined' || typeof config.internal.database.version === 'undefined') {
|
||||
throw new Error('Database version is undefined. Check you config file');
|
||||
if (typeof config.internal.database === 'undefined'
|
||||
|| typeof config.internal.database.version === 'undefined'
|
||||
|| typeof config.internal.database.version !== 'string') {
|
||||
throw new Error('Database version is undefined. Check your config file');
|
||||
}
|
||||
|
||||
const options = {
|
||||
const options: ES.ConfigOptions = {
|
||||
apiVersion: config.internal.database.version,
|
||||
host: Elasticsearch.getElasticsearchUrl(),
|
||||
log: 'error',
|
||||
@@ -545,10 +553,27 @@ export class Elasticsearch implements Database {
|
||||
throw new Error('Database is undefined. You have to configure the query build');
|
||||
}
|
||||
|
||||
if (typeof this.config.internal.database.version === 'undefined'
|
||||
|| typeof this.config.internal.database.version !== 'string') {
|
||||
throw new Error('Database version is malformed. Check your config file');
|
||||
}
|
||||
|
||||
const esConfig: ElasticsearchConfig = {
|
||||
name: 'elasticsearch',
|
||||
version: this.config.internal.database.version,
|
||||
};
|
||||
|
||||
if (typeof this.config.internal.database.query !== 'undefined'
|
||||
&& this.config.internal.database.query !== undefined) {
|
||||
esConfig.query =
|
||||
this.config.internal.database
|
||||
.query as ElasticsearchQueryDisMaxConfig | ElasticsearchQueryQueryStringConfig;
|
||||
}
|
||||
|
||||
const searchRequest: ES.SearchParams = {
|
||||
body: {
|
||||
aggs: this.aggregationsSchema, // use cached version of aggregations (they only change if config changes)
|
||||
query: buildQuery(params, this.config, this.config.internal.database as ElasticsearchConfig),
|
||||
query: buildQuery(params, this.config, esConfig),
|
||||
},
|
||||
from: params.from,
|
||||
index: Elasticsearch.getListOfAllIndices(),
|
||||
|
||||
@@ -122,7 +122,7 @@ export function setUp(monitoringConfig: SCMonitoringConfiguration, esClient: ES.
|
||||
|
||||
cron.schedule(trigger.executionTime, async () => {
|
||||
// execute watch (search->condition->action)
|
||||
const result = await esClient.search(watcher.query);
|
||||
const result = await esClient.search(watcher.query as ES.SearchParams);
|
||||
|
||||
// check conditions
|
||||
const total = result.hits.total;
|
||||
|
||||
@@ -147,8 +147,8 @@ export function buildFilter(filter: SCSearchFilter): ESTermFilter | ESGeoDistanc
|
||||
distance: `${filter.arguments.distanceInM}m`,
|
||||
};
|
||||
geoObject[filter.arguments.field] = {
|
||||
lat: filter.arguments.lat,
|
||||
lon: filter.arguments.lon,
|
||||
lat: filter.arguments.position[1],
|
||||
lon: filter.arguments.position[0],
|
||||
};
|
||||
|
||||
return {
|
||||
@@ -401,8 +401,8 @@ export function buildSort(
|
||||
};
|
||||
|
||||
args[sort.arguments.field] = {
|
||||
lat: sort.arguments.lat,
|
||||
lon: sort.arguments.lon,
|
||||
lat: sort.arguments.position[1],
|
||||
lon: sort.arguments.position[0],
|
||||
};
|
||||
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user