Refactor 'sendTransactionReceivedEmail' email to HTML and translatable

This commit is contained in:
Wolfgang Huß 2022-11-28 10:54:10 +01:00
parent 0cccdb56de
commit 3903e29e16
7 changed files with 63 additions and 14 deletions

View File

@ -168,3 +168,29 @@ export const sendTransactionLinkRedeemedEmail = (data: {
},
})
}
export const sendTransactionReceivedEmail = (data: {
firstName: string
lastName: string
email: string
language: string
senderFirstName: string
senderLastName: string
senderEmail: string
transactionAmount: Decimal
}): Promise<Record<string, unknown> | null> => {
return sendEmailTranslated({
receiver: { to: `${data.firstName} ${data.lastName} <${data.email}>` },
template: 'transactionReceived',
locals: {
firstName: data.firstName,
lastName: data.lastName,
locale: data.language,
senderFirstName: data.senderFirstName,
senderLastName: data.senderLastName,
senderEmail: data.senderEmail,
transactionAmount: decimalSeparatorByLanguage(data.transactionAmount, data.language),
overviewURL: CONFIG.EMAIL_LINK_OVERVIEW,
},
})
}

View File

@ -10,7 +10,7 @@ html(lang=locale)
p= t('emails.general.amountGDD', { amountGDD: transactionAmount })
br
span= t('emails.transactionLinkRedeemed.memo', { transactionMemo })
p= t('emails.transactionLinkRedeemed.detailsYouFindOnLinkToYourAccount')
p= t('emails.general.detailsYouFindOnLinkToYourAccount')
span= " "
a(href=overviewURL) #{overviewURL}
p= t('emails.general.pleaseDoNotReply')

View File

@ -0,0 +1,16 @@
doctype html
html(lang=locale)
head
title= t('emails.transactionReceived.subject')
body
h1(style='margin-bottom: 24px;')= t('emails.transactionReceived.subject')
#container.col
p(style='margin-bottom: 24px;')= t('emails.general.helloName', { firstName, lastName })
p= t('emails.transactionReceived.haveReceivedAmountGDDFrom', { transactionAmount, senderFirstName, senderLastName, senderEmail })
p= t('emails.general.detailsYouFindOnLinkToYourAccount')
span= " "
a(href=overviewURL) #{overviewURL}
p= t('emails.general.pleaseDoNotReply')
p(style='margin-top: 24px;')= t('emails.general.sincerelyYours')
br
span= t('emails.general.yourGradidoTeam')

View File

@ -0,0 +1 @@
= t('emails.transactionReceived.subject')

View File

@ -2,14 +2,11 @@
/* eslint-disable @typescript-eslint/no-non-null-assertion */
import { backendLogger as logger } from '@/server/logger'
import CONFIG from '@/config'
import { Context, getUser } from '@/server/context'
import { Resolver, Query, Args, Authorized, Ctx, Mutation } from 'type-graphql'
import { getCustomRepository, getConnection, In } from '@dbTools/typeorm'
import { sendTransactionReceivedEmail } from '@/mailer/sendTransactionReceivedEmail'
import { Transaction } from '@model/Transaction'
import { TransactionList } from '@model/TransactionList'
@ -36,7 +33,10 @@ import Decimal from 'decimal.js-light'
import { BalanceResolver } from './BalanceResolver'
import { MEMO_MAX_CHARS, MEMO_MIN_CHARS } from './const/const'
import { findUserByEmail } from './UserResolver'
import { sendTransactionLinkRedeemedEmail } from '@/emails/sendEmailVariants'
import {
sendTransactionLinkRedeemedEmail,
sendTransactionReceivedEmail,
} from '@/emails/sendEmailVariants'
import { Event, EventTransactionReceive, EventTransactionSend } from '@/event/Event'
import { eventProtocol } from '@/event/EventProtocolEmitter'
import { Decay } from '../model/Decay'
@ -168,17 +168,15 @@ export const executeTransaction = async (
await queryRunner.release()
}
logger.debug(`prepare Email for transaction received...`)
// send notification email
// TODO: translate
await sendTransactionReceivedEmail({
firstName: recipient.firstName,
lastName: recipient.lastName,
email: recipient.emailContact.email,
language: recipient.language,
senderFirstName: sender.firstName,
senderLastName: sender.lastName,
recipientFirstName: recipient.firstName,
recipientLastName: recipient.lastName,
email: recipient.emailContact.email,
senderEmail: sender.emailContact.email,
amount,
overviewURL: CONFIG.EMAIL_LINK_OVERVIEW,
transactionAmount: amount,
})
if (transactionLink) {
await sendTransactionLinkRedeemedEmail({

View File

@ -30,6 +30,7 @@
},
"general": {
"amountGDD": "Betrag: {amountGDD} GDD",
"detailsYouFindOnLinkToYourAccount": "Details zur Transaktion findest du in deinem Gradido-Konto:",
"helloName": "Hallo {firstName} {lastName},",
"linkToYourAccount": "Link zu deinem Konto:",
"orCopyLink": "oder kopiere den obigen Link in dein Browserfenster.",
@ -44,10 +45,13 @@
"youOrSomeoneResetPassword": "du, oder jemand anderes, hast für dieses Konto ein Zurücksetzen des Passworts angefordert."
},
"transactionLinkRedeemed": {
"detailsYouFindOnLinkToYourAccount": "Details zur Transaktion findest du in deinem Gradido-Konto:",
"hasRedeemedYourLink": "{senderFirstName} {senderLastName} ({senderEmail}) hat soeben deinen Link eingelöst.",
"memo": "Memo: {transactionMemo}",
"subject": "Gradido: Dein Gradido-Link wurde eingelöst"
},
"transactionReceived": {
"haveReceivedAmountGDDFrom": "du hast soeben {transactionAmount} GDD von {senderFirstName} {senderLastName} ({senderEmail}) erhalten.",
"subject": "Gradido: Du hast Gradidos erhalten"
}
},
"general": {

View File

@ -30,6 +30,7 @@
},
"general": {
"amountGDD": "Amount: {amountGDD} GDD",
"detailsYouFindOnLinkToYourAccount": "You can find transaction details in your Gradido account:",
"helloName": "Hello {firstName} {lastName}",
"linkToYourAccount": "Link to your account:",
"orCopyLink": "or copy the link above into your browser window.",
@ -44,10 +45,13 @@
"youOrSomeoneResetPassword": "You, or someone else, requested a password reset for this account."
},
"transactionLinkRedeemed": {
"detailsYouFindOnLinkToYourAccount": "You can find transaction details in your Gradido account:",
"hasRedeemedYourLink": "{senderFirstName} {senderLastName} ({senderEmail}) has just redeemed your link.",
"memo": "Memo: {transactionMemo}",
"subject": "Gradido: Your Gradido link has been redeemed"
},
"transactionReceived": {
"haveReceivedAmountGDDFrom": "You have just received {transactionAmount} GDD from {senderFirstName} {senderLastName} ({senderEmail}).",
"subject": "Gradido: You have received Gradidos"
}
},
"general": {