Skip to content

Commit

Permalink
chore: 누락된 메일 알림 복귀
Browse files Browse the repository at this point in the history
  • Loading branch information
potados99 committed Sep 17, 2021
1 parent 94dc6da commit d82c99e
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@

## 업데이트 로그

### 2021.9.17 v2.0.20
- 누락된 메일 알림 복귀.

### 2021.9.13 v2.0.19
- 관리자에게 보내는 메일에서, 사용자 질문에 답변하는 링크 수정.

Expand Down
9 changes: 9 additions & 0 deletions lib/application/qna/Ask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import UseCase from '../../common/base/UseCase';
import {Question} from '@inu-cafeteria/backend-core';
import {UserIdentifier} from '../user/common/types';
import MailSender from '../../external/mail/MailSender';
import NotifyNewQuestion from './NotifyNewQuestion';

export type AskParams = {
deviceInfo: string;
Expand All @@ -38,6 +40,13 @@ class Ask extends UseCase<AskParams, void> {
});

await question.save();

await NotifyNewQuestion.run({
userId,
deviceInfo,
appVersion,
content,
});
}
}

Expand Down
13 changes: 9 additions & 4 deletions lib/application/qna/NotifyNewQuestion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@
import UseCase from '../../common/base/UseCase';
import config from '../../../config';
import MailSender from '../../external/mail/MailSender';
import {User} from '@inu-cafeteria/backend-core';

export type NotifyNewQuestionParams = {
studentId: string;
userId: number;
deviceInfo: string;
appVersion: string;
content: string;
Expand All @@ -34,13 +35,15 @@ class NotifyNewQuestion extends UseCase<NotifyNewQuestionParams, void> {
from: config.application.notify.sender,
to: config.application.notify.adminEmail,
title: '새로운 문의가 등록되었습니다.',
body: this.composeNotificationMailBody(params),
body: await this.composeNotificationMailBody(params),
};

await new MailSender(emailParams).send();
}

private composeNotificationMailBody(params: NotifyNewQuestionParams) {
private async composeNotificationMailBody(params: NotifyNewQuestionParams) {
const user = await User.findOne(params.userId);

// https://html5-editor.net
return `
<!-- ####### THIS IS A COMMENT - Visible only in the source editor #########-->
Expand All @@ -50,7 +53,9 @@ class NotifyNewQuestion extends UseCase<NotifyNewQuestionParams, void> {
<tbody>
<tr style="height: 23px;">
<td style="width: 133.203125px; height: 23px; border: 0px;"><span style="color: #808080;">작성자</span></td>
<td style="width: 212.8125px; height: 23px; border: 0px;">${params.studentId}</td>
<td style="width: 212.8125px; height: 23px; border: 0px;">${
user?.identifier() ?? `userId: ${params.userId}`
}</td>
</tr>
<tr style="height: 23px;">
<td style="width: 133.203125px; height: 23px; border: 0px;"><span style="color: #808080;">문의 시각</span></td>
Expand Down
7 changes: 6 additions & 1 deletion lib/external/mail/MailSender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,12 @@ export default class MailSender {

async send(): Promise<void> {
try {
const result = await this.transport.sendMail(this.params);
const result = await this.transport.sendMail({
from: this.params.from,
to: this.params.to,
subject: this.params.title,
html: this.params.body,
});

logger.info(`${this.params.to}에게 메일 전송 완료: ${result.response}`);
} catch (e) {
Expand Down

0 comments on commit d82c99e

Please sign in to comment.