mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-08 22:42:54 +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 {Bulk} from '../bulk-storage';
|
||||||
import {Database} from '../database';
|
import {Database} from '../database';
|
||||||
import {buildAggregations, parseAggregations} from './aggregations';
|
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 * as Monitoring from './monitoring';
|
||||||
import {buildQuery, buildSort} from './query';
|
import {buildQuery, buildSort} from './query';
|
||||||
import {putTemplate} from './templating';
|
import {putTemplate} from './templating';
|
||||||
@@ -167,11 +173,13 @@ export class Elasticsearch implements Database {
|
|||||||
*/
|
*/
|
||||||
constructor(private readonly config: SCConfigFile, mailQueue?: MailQueue) {
|
constructor(private readonly config: SCConfigFile, mailQueue?: MailQueue) {
|
||||||
|
|
||||||
if (typeof config.internal.database === 'undefined' || typeof config.internal.database.version === 'undefined') {
|
if (typeof config.internal.database === 'undefined'
|
||||||
throw new Error('Database version is undefined. Check you config file');
|
|| 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,
|
apiVersion: config.internal.database.version,
|
||||||
host: Elasticsearch.getElasticsearchUrl(),
|
host: Elasticsearch.getElasticsearchUrl(),
|
||||||
log: 'error',
|
log: 'error',
|
||||||
@@ -545,10 +553,27 @@ export class Elasticsearch implements Database {
|
|||||||
throw new Error('Database is undefined. You have to configure the query build');
|
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 = {
|
const searchRequest: ES.SearchParams = {
|
||||||
body: {
|
body: {
|
||||||
aggs: this.aggregationsSchema, // use cached version of aggregations (they only change if config changes)
|
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,
|
from: params.from,
|
||||||
index: Elasticsearch.getListOfAllIndices(),
|
index: Elasticsearch.getListOfAllIndices(),
|
||||||
|
|||||||
@@ -122,7 +122,7 @@ export function setUp(monitoringConfig: SCMonitoringConfiguration, esClient: ES.
|
|||||||
|
|
||||||
cron.schedule(trigger.executionTime, async () => {
|
cron.schedule(trigger.executionTime, async () => {
|
||||||
// execute watch (search->condition->action)
|
// execute watch (search->condition->action)
|
||||||
const result = await esClient.search(watcher.query);
|
const result = await esClient.search(watcher.query as ES.SearchParams);
|
||||||
|
|
||||||
// check conditions
|
// check conditions
|
||||||
const total = result.hits.total;
|
const total = result.hits.total;
|
||||||
|
|||||||
@@ -147,8 +147,8 @@ export function buildFilter(filter: SCSearchFilter): ESTermFilter | ESGeoDistanc
|
|||||||
distance: `${filter.arguments.distanceInM}m`,
|
distance: `${filter.arguments.distanceInM}m`,
|
||||||
};
|
};
|
||||||
geoObject[filter.arguments.field] = {
|
geoObject[filter.arguments.field] = {
|
||||||
lat: filter.arguments.lat,
|
lat: filter.arguments.position[1],
|
||||||
lon: filter.arguments.lon,
|
lon: filter.arguments.position[0],
|
||||||
};
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@@ -401,8 +401,8 @@ export function buildSort(
|
|||||||
};
|
};
|
||||||
|
|
||||||
args[sort.arguments.field] = {
|
args[sort.arguments.field] = {
|
||||||
lat: sort.arguments.lat,
|
lat: sort.arguments.position[1],
|
||||||
lon: sort.arguments.lon,
|
lon: sort.arguments.position[0],
|
||||||
};
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
Reference in New Issue
Block a user