From e6fec184283a393339fd5a97fe892e27f83a3442 Mon Sep 17 00:00:00 2001 From: "{authemail@qq.com}" Date: Wed, 21 Dec 2022 10:42:44 +0800 Subject: [PATCH] fix(tencent-email): fix typo and variable name --- packages/connector-tencent-email/src/index.ts | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/packages/connector-tencent-email/src/index.ts b/packages/connector-tencent-email/src/index.ts index c4c0da31..8704883c 100644 --- a/packages/connector-tencent-email/src/index.ts +++ b/packages/connector-tencent-email/src/index.ts @@ -50,12 +50,9 @@ function buildTemplatePayload( }, {}); } -function transformString(...values: Array): string { - return values.find((item) => item && item.length > 0) ?? ''; -} - const sendMessage = (getConfig: GetConnectorConfig): SendMessageFunction => + // eslint-disable-next-line complexity async (data, inputConfig) => { const { to, type, payload } = data; const config = inputConfig ?? (await getConfig(defaultMetadata.id)); @@ -65,7 +62,7 @@ const sendMessage = const mailTemplate: MailTemplateType = getTemplate(templates, type); - const fromAddressValue = transformString(mailTemplate.fromAddress, fromAddress); + const fromAddressValue = mailTemplate.fromAddress ?? fromAddress ?? ''; assert( fromAddressValue.length > 0, @@ -75,14 +72,14 @@ const sendMessage = ) ); - const fromNameValue = transformString(mailTemplate.fromName, fromName); + const fromNameValue = mailTemplate.fromName ?? fromName ?? ''; const templateParameters: Record = { code: payload.code, toAddress: to, fromAddress: fromAddressValue, - fromName: fromNameValue, - replyAddress: transformString(mailTemplate.replyAddress, replyAddress), + fromName: buildFromName(fromNameValue, fromAddressValue), + replyAddress: mailTemplate.replyAddress ?? replyAddress ?? '', subject: mailTemplate.subject ?? type, }; @@ -91,9 +88,9 @@ const sendMessage = try { const response = await request( { - fromEmailAddress: buildFromName(fromNameValue, fromAddressValue), + fromEmailAddress: templateParameters.fromAddress, replyAddress: templateParameters.replyAddress, - destination: to, + destination: templateParameters.toAddress, subject: templateParameters.subject, template: { templateData: JSON.stringify(emailTemplateParametersPayload),