diff --git a/src/structures/services/structures-import.service.ts b/src/structures/services/structures-import.service.ts index 82cae599452ad24534940e195118ab6b3842c3a3..b68955ade3c0ecf12f695a9dc5cf0caac7a8ad6d 100644 --- a/src/structures/services/structures-import.service.ts +++ b/src/structures/services/structures-import.service.ts @@ -11,11 +11,12 @@ import { Week } from '../../shared/schemas/week.schema'; import { Day } from '../schemas/day.schema'; import { Time } from '../schemas/time.schema'; import { DataGouvStructure } from '../interfaces/data-gouv-structure.interface'; - interface Condition { address?: { street?: string; numero?: string }; contactMail?: string; } +// historically, contactMail has been set to an empty string when a structure is deleted +type ContactMailCondition = string | { $in: (string | null)[] }; @Injectable() export class StructuresImportService { @@ -87,8 +88,15 @@ export class StructuresImportService { addressCondition = { 'address.street': structure.adresse }; } - const conditions: Condition[] = [addressCondition, { contactMail: structure.courriel }]; + const contactMailCondition: { contactMail: ContactMailCondition } = { contactMail: structure.courriel }; + + if (!structure.courriel) { + contactMailCondition.contactMail = { $in: [null, ''] }; + } + + const conditions: Condition[] = [addressCondition, contactMailCondition]; const count = await this.structureModel.countDocuments({ $and: conditions }).exec(); + return count > 0; } diff --git a/src/structures/services/structures.service.ts b/src/structures/services/structures.service.ts index 180005f6fadaa47179d7d5b0fbe266c513e4712d..69ad57271435a42fa40c2dbaa9f3c270df27b815 100644 --- a/src/structures/services/structures.service.ts +++ b/src/structures/services/structures.service.ts @@ -745,7 +745,7 @@ export class StructuresService { structure.structureType = null; if (structure.toBeDeletedAt) structure.toBeDeletedAt = null; structure.deletedAt = DateTime.local().setZone('Europe/Paris').toString(); - this.anonymizeStructure(structure).save(); + structure.save(); this.logger.debug(`delete structure : ${structure.structureName} (${structure._id})`); // Remove structure from owners (and check if there is a newly unattached user) @@ -789,16 +789,6 @@ export class StructuresService { this.mailerService.send(uniqueAdminEmails, jsonConfig.subject, html); } - private anonymizeStructure(structure: StructureDocument): StructureDocument { - structure.contactPhone = ''; - structure.contactMail = ''; - structure.facebook = null; - structure.twitter = null; - structure.instagram = null; - structure.website = ''; - return structure; - } - @Cron(CronExpression.EVERY_DAY_AT_4AM) public async structuresTasksProcess(): Promise<void> { this.logger.log('structuresTasksProcess');