diff --git a/src/mailer/mail-templates/structureOutdatedInfo.ejs b/src/mailer/mail-templates/structureOutdatedInfo.ejs index a5caf60e0c7cff65131144da363bfb58bcfecc38..72e04b9f8e45c191faf2c2a574421179577a1f02 100644 --- a/src/mailer/mail-templates/structureOutdatedInfo.ejs +++ b/src/mailer/mail-templates/structureOutdatedInfo.ejs @@ -3,6 +3,7 @@ Bonjour,<br /> Vous recevez ce message car votre structure <strong><%= name %></strong> est référencée sur RES'in, le réseau des acteurs de l'inclusion numérique de la Métropole de Lyon. Pouvez-vous nous aider en vérifiant que vos données sont bien à jour en -<a href="<%= config.protocol %>://<%= config.host %><%= config.port ? ':' + config.port : '' %>/acteurs?id=<%= id %>" +<a + href="<%= config.protocol %>://<%= config.host %><%= config.port ? ':' + config.port : '' %>/profile/edit-structure/<%= id %>" >cliquant ici</a >. diff --git a/src/migrations/scripts/1662718686174-reset-outdatedStructure-mail.ts b/src/migrations/scripts/1662718686174-reset-outdatedStructure-mail.ts new file mode 100644 index 0000000000000000000000000000000000000000..f223280024bf135b8396f0626a250eda449ca8d1 --- /dev/null +++ b/src/migrations/scripts/1662718686174-reset-outdatedStructure-mail.ts @@ -0,0 +1,17 @@ +import { Db } from 'mongodb'; +import { getDb } from '../migrations-utils/db'; + +export const up = async () => { + const db: Db = await getDb(); + const cursor = db.collection('users').find({}); + let document; + while ((document = await cursor.next())) { + await db.collection('users').updateOne({ _id: document._id }, [{ $set: { structureOutdatedMailSent: [] } }]); + } + console.log(`Update done : 'structureOutdatedMailSent' emptied in 'users' collection`); +}; + +export const down = async () => { + // Nothing can be done since 'structureOutdatedMailSent' cannot be filled again with previously deleted values + console.log(`Downgrade done`); +}; diff --git a/src/structures/services/structures-search.service.ts b/src/structures/services/structures-search.service.ts index cdd3575d031b51c4b4f62ec2f96d19b19ce3de9d..2bac91fe10710cceda2d97811cc602fe5bac4e7f 100644 --- a/src/structures/services/structures-search.service.ts +++ b/src/structures/services/structures-search.service.ts @@ -1,4 +1,4 @@ -import { Injectable } from '@nestjs/common'; +import { Injectable, Logger } from '@nestjs/common'; import { ElasticsearchService } from '@nestjs/elasticsearch'; import { StructureDto } from '../dto/structure.dto'; import { StructureDocument } from '../schemas/structure.schema'; @@ -8,10 +8,12 @@ import { StructureSearchResult } from '../interfaces/structure-search-response.i @Injectable() export class StructuresSearchService { private index = 'structures'; + private readonly logger = new Logger(StructuresSearchService.name); constructor(private readonly elasticsearchService: ElasticsearchService) {} public async indexStructure(structure: StructureDocument): Promise<StructureDocument> { + this.logger.debug(`indexStructure`); this.elasticsearchService.index<StructureSearchResult, StructureSearchBody>({ index: this.index, id: structure._id, @@ -27,6 +29,7 @@ export class StructuresSearchService { } 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) // don't use stopwords (le, la, de, son, etc.) for structureName (to find "maison de la", "le son du clic", etc.) return this.elasticsearchService.indices.create({ @@ -87,6 +90,7 @@ export class StructuresSearchService { } public async dropIndex(): Promise<any> { + this.logger.debug(`dropIndex`); if ( ( await this.elasticsearchService.indices.exists({ @@ -101,6 +105,7 @@ export class StructuresSearchService { } public async deleteIndexStructure(structure: StructureDocument): Promise<StructureDocument> { + this.logger.debug(`deleteIndexStructure`); this.elasticsearchService.delete<StructureSearchResult, StructureSearchBody>({ index: this.index, id: structure._id, @@ -109,12 +114,14 @@ export class StructuresSearchService { } public async refreshIndexStructure(): Promise<any> { + this.logger.debug(`refreshIndexStructure`); return this.elasticsearchService.indices.refresh({ index: this.index, }); } public async search(searchString: string, fields?: string[]): Promise<StructureSearchBody[]> { + this.logger.debug(`search ${searchString} | fields : ${fields}`); searchString = searchString ? searchString + '*' : '*'; const { body } = await this.elasticsearchService.search<StructureSearchResult>({ index: this.index, @@ -138,6 +145,7 @@ export class StructuresSearchService { } public async update(structure: StructureDto, id: string): Promise<any> { + this.logger.debug('update'); return this.elasticsearchService.update({ index: this.index, id: id, diff --git a/src/structures/services/structures.service.ts b/src/structures/services/structures.service.ts index 14bf1e2859859e3aa7196d8319ec0be22ac46ce1..d3f092e499a1b41725dafe791db252fc9c7fb6cd 100644 --- a/src/structures/services/structures.service.ts +++ b/src/structures/services/structures.service.ts @@ -15,7 +15,6 @@ import { CategoriesFormationsModule } from '../../categories/schemas/categoriesF import { CategoriesOthers } from '../../categories/schemas/categoriesOthers.schema'; import { CategoriesFormationsService } from '../../categories/services/categories-formations.service'; import { MailerService } from '../../mailer/mailer.service'; -import { ParametersService } from '../../parameters/parameters.service'; import { PersonalOfferDocument } from '../../personal-offers/schemas/personal-offer.schema'; import { IUser } from '../../users/interfaces/user.interface'; import { User } from '../../users/schemas/user.schema'; @@ -34,7 +33,6 @@ export class StructuresService { private readonly mailerService: MailerService, private structuresSearchService: StructuresSearchService, private categoriesFormationsService: CategoriesFormationsService, - private parametersService: ParametersService, @InjectModel(Structure.name) private structureModel: Model<StructureDocument> ) {} @@ -625,7 +623,6 @@ export class StructuresService { this.logger.debug('checkOutdatedStructuresInfo'); const OUTDATED_MONTH_TO_CHECK = 6; const structureList = await this.findAll(); - // const local = DateTime.now().toObject(); // Get outdated structures const filteredList = structureList.filter((structure) => { const updatedDate = DateTime.fromISO(structure.updatedAt.toISOString()); diff --git a/src/users/services/users.service.ts b/src/users/services/users.service.ts index 5a69d7e701f4f6aa765ae41e6f5e089e01aa1741..e729f45f3a1a575371cb2c9cce33e67a39b1c401 100644 --- a/src/users/services/users.service.ts +++ b/src/users/services/users.service.ts @@ -621,10 +621,11 @@ export class UsersService { } public async removeOutdatedStructureFromArray(structureId: string): Promise<void> { + this.logger.debug(`removeOutdatedStructureFromArray for structure : ${structureId}`); const users = await this.userModel.find({ structureOutdatedMailSent: Types.ObjectId(structureId) }).exec(); users.forEach((user) => { - user.structureOutdatedMailSent = user.structureOutdatedMailSent.filter((item) => - Types.ObjectId(structureId).equals(item) + user.structureOutdatedMailSent = user.structureOutdatedMailSent.filter( + (item) => !Types.ObjectId(structureId).equals(item) ); user.save(); });