diff --git a/src/mailer/mail-templates/structureErrorReport.json b/src/mailer/mail-templates/structureErrorReport.json index f828eb7b3c2c8594d81c1bb779cb10ef21d52ef1..3faeacf33799d9891558bedba0a2771ef7344782 100644 --- a/src/mailer/mail-templates/structureErrorReport.json +++ b/src/mailer/mail-templates/structureErrorReport.json @@ -1,3 +1,3 @@ { - "subject": "Une demande de modification a été faite sur votre structure, Réseau des Acteurs de la Médiation Numérique de la Métropole de Lyon" + "subject": "Une erreur a été remontée sur votre structure, Réseau des Acteurs de la Médiation Numérique de la Métropole de Lyon" } diff --git a/src/mailer/mailer.service.ts b/src/mailer/mailer.service.ts index c990b850cc3408f617f74c5390934dd505e91bdd..ff76d5fe2c046f0f53398384f424d51f865d1c67 100644 --- a/src/mailer/mailer.service.ts +++ b/src/mailer/mailer.service.ts @@ -21,53 +21,15 @@ export class MailerService { * @param {string} html * @param {string} text */ - public async send(to: string, subject: string, html: string): Promise<AxiosResponse<any>> { + public async send(to: string | {}[], subject: string, html: string): Promise<AxiosResponse<any>> { + let emailsToSend = typeof to === 'string' ? [{ email: to }] : to; const formData = new FormData(); - - const data = JSON.stringify({ - // eslint-disable-next-line camelcase - from_email: this.config.from, - // eslint-disable-next-line camelcase - from_name: this.config.from_name, - to: [{ email: to }], - reply_to: 'inclusionnumerique@grandlyon.com', - subject: subject, - content: this.addSignature(html), - }); - formData.append('metadata', data); - const contentLength = formData.getLengthSync(); - Logger.log(`Send mail : ${subject}`, 'Mailer'); - return new Promise((resolve, reject) => { - this.httpService - .post(process.env.MAIL_URL, formData, { - headers: { - 'Content-Length': contentLength, - Authorization: 'Bearer ' + process.env.MAIL_TOKEN, - ...formData.getHeaders(), - }, - }) - .subscribe( - (body) => { - Logger.log(`Send mail - success : ${subject}`, 'Mailer'); - return resolve(body); - }, - (err) => { - Logger.error(err, 'Mailer'); - return reject(err); - } - ); - }); - } - - public async sendMultiple(to: {}[], subject: string, html: string): Promise<AxiosResponse<any>> { - const formData = new FormData(); - const data = JSON.stringify({ // eslint-disable-next-line camelcase from_email: this.config.from, // eslint-disable-next-line camelcase from_name: this.config.from_name, - to: to, + to: emailsToSend, reply_to: 'inclusionnumerique@grandlyon.com', subject: subject, content: this.addSignature(html), diff --git a/src/structures/services/structures.service.ts b/src/structures/services/structures.service.ts index a0b0b81e259a9b2e9e370e2f8e9d7272890cec53..14a34afa7d4ffc59ab63d969b9fbd9713d3c09f0 100644 --- a/src/structures/services/structures.service.ts +++ b/src/structures/services/structures.service.ts @@ -355,9 +355,9 @@ export class StructuresService { return admin.email; }) ); - let uniqueEmails = [...new Set(emails)]; + const uniqueEmails = [...new Set(emails)]; - const test = uniqueEmails.map((item) => { + const emailsObject = uniqueEmails.map((item) => { const container = {}; container['email'] = item; return container; @@ -373,6 +373,6 @@ export class StructuresService { id: structure._id, structureName: structure.structureName, }); - this.mailerService.sendMultiple(test, jsonConfig.subject, html); + this.mailerService.send(emailsObject, jsonConfig.subject, html); } } diff --git a/src/structures/structures.controller.ts b/src/structures/structures.controller.ts index 52582b6bb6a921c9f8fc4c4ecd39c40a5d0151d4..a7586a4cf7e882e9b76fc4f180fa671afa48b75b 100644 --- a/src/structures/structures.controller.ts +++ b/src/structures/structures.controller.ts @@ -238,7 +238,6 @@ export class StructuresController { @Post('reportStructureError') public async reportStructureError(@Body() data: { structureId: string; content: string }): Promise<void> { - console.log('report structure error contrller'); return await this.structureService.reportStructureError(data.structureId, data.content); } }