Skip to content

Commit

Permalink
Add: notifyEmailFailureToReportChannel
Browse files Browse the repository at this point in the history
  • Loading branch information
MinjaeKimmm committed Oct 8, 2024
1 parent e541fc0 commit a526443
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/modules/email.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const nodemailer = require("nodemailer");
const logger = require("./logger");
const { nodeEnv } = require("../../loadenv");
const { notifyEmailFailureToReportChannel } = require("../modules/slackNotification");

/**
* production 환경에서 메일을 전송하기 위해 사용되는 agent입니다.
Expand Down Expand Up @@ -32,7 +33,7 @@ class NodemailerTransport {
return true;
} catch (err) {
logger.error(`Failed to send email: ${err}`);
return false;
return err;
}
}
}
Expand Down Expand Up @@ -103,7 +104,7 @@ class MockNodemailerTransport {
return true;
} catch (err) {
logger.error(`Failed to send email: ${err}`);
return false;
return err;
}
}
}
Expand All @@ -129,15 +130,21 @@ const sendReportEmail = async (reportedEmail, report, html) => {
"etc-reason": "기타 사유",
};

return transporter.sendMail({
const mailOptions = {
from: "[email protected]",
to: reportedEmail,
subject: `[SPARCS TAXI] 신고가 접수되었습니다 (사유: ${
reportTypeMap[report.type]
})`,
html,
});
};
}

const result = await transporter.sendMail(mailOptions);

if (result instanceof Error) {
notifyEmailFailureToReportChannel(mailOptions, report, result);
}
}

module.exports = {
sendReportEmail,
Expand Down
20 changes: 20 additions & 0 deletions src/modules/slackNotification.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,28 @@ const notifyRoomCreationAbuseToReportChannel = (
);
};

const notifyEmailFailureToReportChannel = (
mailOption,
report,
error
) => {
sendTextToReportChannel(
`${mailOption.to}님께 보내려는 신고 메일이 실패했습니다.
신고자 ID: ${report.creatorId}
신고 ID: ${report.reportedId}
방 ID: ${report.roomId ?? ""}
사유: ${report.type}
기타: ${report.etcDetail}
문제 원인: ${error.message}
`
)
}

module.exports = {
sendTextToReportChannel,
notifyReportToReportChannel,
notifyRoomCreationAbuseToReportChannel,
notifyEmailFailureToReportChannel
};

0 comments on commit a526443

Please sign in to comment.