diff --git a/src/structures/services/structures-search.service.ts b/src/structures/services/structures-search.service.ts index 16c44f18d53f3702ec1863d3148d00aab18f4636..1e787d36c8e54210cbeab5e4b7c639a31cf8f9b8 100644 --- a/src/structures/services/structures-search.service.ts +++ b/src/structures/services/structures-search.service.ts @@ -1,9 +1,9 @@ import { Injectable, Logger } from '@nestjs/common'; import { ElasticsearchService } from '@nestjs/elasticsearch'; -import { Structure, StructureDocument } from '../schemas/structure.schema'; +import { es_settings_homemade_french } from '../../shared/utils'; import { StructureSearchBody } from '../interfaces/structure-search-body.interface'; import { StructureSearchResult } from '../interfaces/structure-search-response.interface'; -import { es_settings_homemade_french } from '../../shared/utils'; +import { StructureDocument } from '../schemas/structure.schema'; @Injectable() export class StructuresSearchService { @@ -17,17 +17,21 @@ export class StructuresSearchService { this.elasticsearchService.index<StructureSearchResult, StructureSearchBody>({ index: this.index, id: structure._id, - body: { - structureName: structure.structureName, - structureType: structure.structureType.value, - structureId: structure._id, - address: structure.address, - description: structure.description, - }, + body: this.formatIndexBody(structure), }); return structure; } + private formatIndexBody(structure: StructureDocument): StructureSearchBody { + return { + structureName: structure.structureName, + structureType: structure.structureType.value, + structureId: structure._id, + address: structure.address, + description: structure.description, + }; + } + public async createStructureIndex(): Promise<any> { this.logger.debug(`createStructureIndex`); // use custom analyzer with minimal_french stemmer to avoid default light_french stemmer problems (oullins -> oulin, "oull" not found) @@ -116,19 +120,13 @@ export class StructuresSearchService { return sortedHits.map((item) => item._source); } - public async update(structure: Structure, id: string): Promise<any> { + public async update(structure: StructureDocument, id: string): Promise<any> { this.logger.debug('update'); return this.elasticsearchService.update({ index: this.index, id: id, body: { - doc: { - structureName: structure.structureName, - structureType: structure.structureType, - structureId: id, - address: structure.address, - description: structure.description, - }, + doc: this.formatIndexBody(structure), }, }); } diff --git a/src/structures/services/structures.service.ts b/src/structures/services/structures.service.ts index 50373dfa971370352134bdc5844e790497c1a6e1..b9ed2b7d12c2a76fa0e43b3c869350008b0279b8 100644 --- a/src/structures/services/structures.service.ts +++ b/src/structures/services/structures.service.ts @@ -353,7 +353,7 @@ export class StructuresService { } public async update(idStructure: string, updatedFields: UpdateStructureDto): Promise<Structure> { - this.logger.debug(`Updating structure with id: ${idStructure}`); + this.logger.debug(`Updating structure ${idStructure}`); const oldStructure = await this.findOne(idStructure); let deepClone: StructureDocument; // Update structure categories in order to not override it