Skip to content

Commit

Permalink
refactor: déplace méthode followup dans email-service
Browse files Browse the repository at this point in the history
  • Loading branch information
Shamzic committed Nov 16, 2023
1 parent 99730aa commit 5c0c9bd
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 14 deletions.
8 changes: 7 additions & 1 deletion backend/lib/messaging/email/email-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 1 addition & 12 deletions backend/models/followup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
1 change: 0 additions & 1 deletion lib/types/followup.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ interface FollowupAttributes {
}

interface FollowupMethods {
postSimulationResultsEmail(messageId: string): void
postSimulationResultsSms(messageId: string): void
renderSimulationResultsEmail(): any
renderSimulationResultsSms(): any
Expand Down

0 comments on commit 5c0c9bd

Please sign in to comment.