From b5953dd937d24d1cfd98000e0538c9d82702649d Mon Sep 17 00:00:00 2001 From: Curtis Upshall Date: Mon, 11 Dec 2023 14:59:35 -0800 Subject: [PATCH] SIMSBIOHUB-379: Add records to table --- api/src/services/search-index-service.ts | 30 ++++++++++++++++++++---- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/api/src/services/search-index-service.ts b/api/src/services/search-index-service.ts index 251afd1f6..458dc7dab 100644 --- a/api/src/services/search-index-service.ts +++ b/api/src/services/search-index-service.ts @@ -25,18 +25,26 @@ export class SearchIndexService extends DBService { const stringRecords: InsertStringSearchableRecord[] = []; const featurePropertyTypeNames = await this.searchIndexRepository.getFeaturePropertiesWithTypeNames(); - - const propertyTypeMap = Object.fromEntries(featurePropertyTypeNames.map((propertyType) => { + + const featurePropertyTypeMap = Object.fromEntries(featurePropertyTypeNames.map((propertyType) => { const { property_name, ...rest } = propertyType; return [property_name, rest]; })) + + defaultLog.debug({ featurePropertyTypeMap }) features.forEach((feature) => { const { submission_feature_id } = feature; Object .entries(feature.data.properties) - .forEach(([property_name, value]) => { - const { property_type, feature_property_id } = propertyTypeMap[property_name]; + .forEach(([property_name, value]) => { + const featureProperty = featurePropertyTypeMap[property_name]; + if (!featureProperty) { + return; + } + + const { property_type, feature_property_id } = featureProperty; + switch (property_type) { case 'datetime': datetimeRecords.push({ submission_feature_id, feature_property_id, value: value as Date }); @@ -57,6 +65,18 @@ export class SearchIndexService extends DBService { }) }); - defaultLog.debug({ label: 'indexFeaturesBySubmissionId', datetimeRecords, numberRecords, spatialRecords, stringRecords }); + + if (datetimeRecords.length) { + this.searchIndexRepository.insertSearchableDatetimeRecords(datetimeRecords); + } + if (numberRecords.length) { + this.searchIndexRepository.insertSearchableNumberRecords(numberRecords); + } + if (spatialRecords.length) { + this.searchIndexRepository.insertSearchableSpatialRecords(spatialRecords); + } + if (stringRecords.length) { + this.searchIndexRepository.insertSearchableStringRecords(stringRecords); + } } }