@@ -14,7 +14,6 @@ import { ActionGroupId, GEO_CONTAINMENT_ID, GeoContainmentParams } from './alert
1414interface LatestEntityLocation {
1515 location : number [ ] ;
1616 shapeLocationId : string ;
17- entityName : string ;
1817 dateInShape : string | null ;
1918 docId : string ;
2019}
@@ -24,13 +23,11 @@ export function transformResults(
2423 results : SearchResponse < unknown > | undefined ,
2524 dateField : string ,
2625 geoField : string
27- ) : Map < string , EntityLocation > {
26+ ) : Map < string , LatestEntityLocation > {
2827 if ( ! results ) {
29- return [ ] ;
28+ return new Map ( ) ;
3029 }
31- // For the latest of all results, get most recent
3230 const buckets = _ . get ( results , 'aggregations.shapes.buckets' , { } ) ;
33- // @ts -expect-error
3431 const arrResults = _ . flatMap ( buckets , ( bucket : unknown , bucketKey : string ) => {
3532 const subBuckets = _ . get ( bucket , 'entitySplit.buckets' , [ ] ) ;
3633 return _ . map ( subBuckets , ( subBucket ) => {
@@ -45,7 +42,7 @@ export function transformResults(
4542 . map ( ( coordString ) => + coordString )
4643 . reverse ( )
4744 . value ( )
48- : null ;
45+ : [ ] ;
4946 const dateInShape = _ . get (
5047 subBucket ,
5148 `entityHits.hits.hits[0].fields["${ dateField } "][0]` ,
@@ -64,13 +61,19 @@ export function transformResults(
6461 } ) ;
6562 const orderedResults = _ . orderBy ( arrResults , [ 'entityName' , 'dateInShape' ] , [ 'asc' , 'desc' ] )
6663 // Get unique
67- . reduce ( ( accu : Map < string , EntityLocation > , el : LatestEntityLocation ) => {
68- const { entityName, ...locationData } = el ;
69- if ( ! accu . has ( entityName ) ) {
70- accu . set ( entityName , locationData ) ;
71- }
72- return accu ;
73- } , new Map ( ) ) ;
64+ . reduce (
65+ (
66+ accu : Map < string , LatestEntityLocation > ,
67+ el : LatestEntityLocation & { entityName : string }
68+ ) => {
69+ const { entityName, ...locationData } = el ;
70+ if ( ! accu . has ( entityName ) ) {
71+ accu . set ( entityName , locationData ) ;
72+ }
73+ return accu ;
74+ } ,
75+ new Map ( )
76+ ) ;
7477 return orderedResults ;
7578}
7679
@@ -144,7 +147,7 @@ export const getGeoContainmentExecutor = (log: Logger) =>
144147 currentIntervalResults = await executeEsQuery ( currIntervalStartTime , currIntervalEndTime ) ;
145148 }
146149
147- const currLocationMap : Map < string , EntityLocation > = transformResults (
150+ const currLocationMap : Map < string , LatestEntityLocation > = transformResults (
148151 currentIntervalResults ,
149152 params . dateField ,
150153 params . geoField
0 commit comments