@@ -325,7 +325,8 @@ export async function validateAoiOnOhsome(
325325 featureCollection : GeoJSON . GeoJSON | string | undefined | null ,
326326 filter : string | undefined | null ,
327327) : (
328- Promise < { errored : true , error : string } | { errored : false , message : string } >
328+ Promise < { errored : true , error : string }
329+ | { errored : false , message : string } >
329330) {
330331 if ( isNotDefined ( featureCollection ) ) {
331332 return { errored : true , error : 'AOI is not defined' } ;
@@ -352,12 +353,13 @@ export async function validateAoiOnOhsome(
352353 return { errored : true , error : 'Could not find the no. of objects in given AOI' } ;
353354 }
354355
355- const answer = await response . json ( ) as {
356+ interface OhsomeResonse {
356357 result : {
357358 value : number | null | undefined ,
358359 timestamp : string | null | undefined ,
359360 } [ ] | undefined ;
360- } ;
361+ }
362+ const answer = await response . json ( ) as OhsomeResonse ;
361363
362364 const count = answer . result ?. [ 0 ] . value ;
363365
@@ -380,7 +382,7 @@ export async function validateAoiOnOhsome(
380382
381383async function fetchAoiFromHotTaskingManager ( projectId : number | string ) : (
382384 Promise < { errored : true , error : string }
383- | { errored : false , response : GeoJSON . GeoJSON } >
385+ | { errored : false , response : GeoJSON . Geometry } >
384386) {
385387 type Res = GeoJSON . Geometry ;
386388 type Err = { Error : string , SubCode : string } ;
@@ -414,18 +416,16 @@ async function fetchAoiFromHotTaskingManager(projectId: number | string): (
414416 }
415417 return {
416418 errored : false ,
417- response : {
418- type : 'FeatureCollection' ,
419- features : [ { type : 'Feature' , geometry : answer , properties : { } } ] ,
420- } ,
419+ response : answer ,
421420 } ;
422421}
423422
424423export async function validateProjectIdOnHotTaskingManager (
425424 projectId : number | string | undefined | null ,
426425 filter : string | undefined | null ,
427426) : (
428- Promise < { errored : true , error : string } | { errored : false , message : string } >
427+ Promise < { errored : true , error : string }
428+ | { errored : false , message : string , geometry : GeoJSON . Geometry } >
429429) {
430430 if ( isNotDefined ( projectId ) ) {
431431 return {
@@ -438,6 +438,23 @@ export async function validateProjectIdOnHotTaskingManager(
438438 return aoi ;
439439 }
440440
441- const res = await validateAoiOnOhsome ( aoi . response , filter ) ;
442- return res ;
441+ const res = await validateAoiOnOhsome (
442+ {
443+ type : 'FeatureCollection' as const ,
444+ features : [ {
445+ type : 'Feature' as const ,
446+ geometry : aoi . response ,
447+ properties : { } ,
448+ } ] ,
449+ } ,
450+ filter ,
451+ ) ;
452+ if ( res . errored ) {
453+ return res ;
454+ }
455+ return {
456+ errored : false ,
457+ message : res . message ,
458+ geometry : aoi . response ,
459+ } ;
443460}
0 commit comments