diff --git a/src/migrations/scripts/1678284373613-remove-unknown-emails.ts b/src/migrations/scripts/1678284373613-remove-unknown-emails.ts new file mode 100644 index 0000000000000000000000000000000000000000..01788483221e65b5d376c123ba97cec9dbac0ee9 --- /dev/null +++ b/src/migrations/scripts/1678284373613-remove-unknown-emails.ts @@ -0,0 +1,26 @@ +import { Db } from 'mongodb'; +import { StructureDocument } from '../../structures/schemas/structure.schema'; +import { getDb } from '../migrations-utils/db'; + +export const up = async () => { + const db: Db = await getDb(); + const cursor = db.collection('structures').find({}); + let document; + while ((document = await cursor.next())) { + const newDoc: StructureDocument = removeUnknownContactMail(document); + await db.collection('structures').updateOne({ _id: document._id }, [{ $set: newDoc }]); + } + console.log('Update done: Contact emails unknown@unknown.com emptied'); +}; + +export const down = async () => { + // Nothing can be done since we can't know which null contactMail fields were previously filled with unknow@unknown.com + console.log('Downgrade done'); +}; + +function removeUnknownContactMail(doc: StructureDocument): StructureDocument { + if (doc.contactMail && doc.contactMail === 'unknown@unknown.com') { + doc.contactMail = null; + } + return doc; +} diff --git a/src/structures/services/aptic-structures.service.ts b/src/structures/services/aptic-structures.service.ts index 2174076315baefd2b917a8c3d3e1716ff8b9a0ec..d98ab942afe3877bcb7a7380221dee2f5be034ed 100644 --- a/src/structures/services/aptic-structures.service.ts +++ b/src/structures/services/aptic-structures.service.ts @@ -80,7 +80,7 @@ export class ApticStructuresService { createdStructure.structureName = structure.name; createdStructure.contactPhone = structure.phone; // Unkown fields (but mandatory) - createdStructure.contactMail = 'unknown@unknown.com'; + createdStructure.contactMail = null; createdStructure.categories.labelsQualifications = ['passNumerique']; createdStructure.structureType = await this.structureTypeService.findByValue('autre'); createdStructure.pmrAccess = false; diff --git a/src/structures/services/structures.service.ts b/src/structures/services/structures.service.ts index 2b8e21dd8eb63007a4f5fa5b8d830e3cd0389c78..74a26dcbff83bb3e7c771765679e56950c825d6d 100644 --- a/src/structures/services/structures.service.ts +++ b/src/structures/services/structures.service.ts @@ -275,10 +275,6 @@ export class StructuresService { .select('-_id -accountVerified -otherDescription -dataShareConsentDate') .exec() ).map((structure) => { - // If structure has temp email, hide it - if (this.hasTempMail(structure)) { - structure.contactMail = null; - } const repositoryKeys = categories.map((category) => category.id); repositoryKeys.forEach((el) => { // Add referentiel @@ -937,10 +933,6 @@ export class StructuresService { this.mailerService.send(emailsObject, jsonConfig.subject, html); } - private hasTempMail(structure: Structure): boolean { - return structure.contactMail === 'unknown@unknown.com'; - } - public async getAllUserCompletedStructures(users: IUser[]) { return Promise.all( users.map(async (user) => {