From 5c0c9bda0a0f7dcda41f21450c827b02eb016f56 Mon Sep 17 00:00:00 2001 From: Shamzic Date: Thu, 16 Nov 2023 14:51:21 +0100 Subject: [PATCH] =?UTF-8?q?refactor:=20d=C3=A9place=20m=C3=A9thode=20follo?= =?UTF-8?q?wup=20dans=20email-service?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/lib/messaging/email/email-service.ts | 8 +++++++- backend/models/followup.ts | 13 +------------ lib/types/followup.d.ts | 1 - 3 files changed, 8 insertions(+), 14 deletions(-) diff --git a/backend/lib/messaging/email/email-service.ts b/backend/lib/messaging/email/email-service.ts index 8285c906aa..a5639fce8b 100644 --- a/backend/lib/messaging/email/email-service.ts +++ b/backend/lib/messaging/email/email-service.ts @@ -12,7 +12,13 @@ export async function sendEmail(category: EmailCategory, followup) { html: render.html, tags: [category], }) - return response.messageId + followup.sentAt = Date.now() + followup.messageId = response.messageId + if (!followup.surveyOptin) { + followup.email = undefined + } + followup.error = undefined + return followup.save() } catch (err) { console.error("error", err) throw err diff --git a/backend/models/followup.ts b/backend/models/followup.ts index 8672631e78..6a2475560e 100644 --- a/backend/models/followup.ts +++ b/backend/models/followup.ts @@ -16,16 +16,6 @@ FollowupSchema.static("findByEmail", function (email: string) { return this.find({ email }) }) -FollowupSchema.method("postSimulationResultsEmail", function (messageId) { - this.sentAt = Date.now() - this.messageId = messageId - if (!this.surveyOptin) { - this.email = undefined - } - this.error = undefined - return this.save() -}) - FollowupSchema.method("postSimulationResultsSms", function (messageId) { this.smsSentAt = Date.now() this.smsMessageId = messageId @@ -42,8 +32,7 @@ FollowupSchema.method("renderSimulationResultsEmail", function () { FollowupSchema.method("sendSimulationResultsEmail", async function () { try { - const messageId = await sendEmail(EmailCategory.SimulationResults, this) - return this.postSimulationResultsEmail(messageId) + return await sendEmail(EmailCategory.SimulationResults, this) } catch (err) { console.log("error", err) this.error = JSON.stringify(err, null, 2) diff --git a/lib/types/followup.d.ts b/lib/types/followup.d.ts index b1024181db..840fff1c4f 100644 --- a/lib/types/followup.d.ts +++ b/lib/types/followup.d.ts @@ -25,7 +25,6 @@ interface FollowupAttributes { } interface FollowupMethods { - postSimulationResultsEmail(messageId: string): void postSimulationResultsSms(messageId: string): void renderSimulationResultsEmail(): any renderSimulationResultsSms(): any