Skip to content

Commit

Permalink
SIMSBIOHUB-379: Add records to table
Browse files Browse the repository at this point in the history
  • Loading branch information
curtisupshall committed Dec 11, 2023
1 parent eb023bd commit b5953dd
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions api/src/services/search-index-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand All @@ -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);
}
}
}

0 comments on commit b5953dd

Please sign in to comment.