메일관리 시스템 구현 완료
This commit is contained in:
@@ -1,6 +1,15 @@
|
||||
import { Request, Response } from 'express';
|
||||
import { mailTemplateFileService } from '../services/mailTemplateFileService';
|
||||
import { mailQueryService } from '../services/mailQueryService';
|
||||
|
||||
// 간단한 변수 치환 함수
|
||||
function replaceVariables(text: string, data: Record<string, any>): string {
|
||||
let result = text;
|
||||
for (const [key, value] of Object.entries(data)) {
|
||||
const regex = new RegExp(`\\{${key}\\}`, 'g');
|
||||
result = result.replace(regex, String(value));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
export class MailTemplateFileController {
|
||||
// 모든 템플릿 조회
|
||||
@@ -172,8 +181,8 @@ export class MailTemplateFileController {
|
||||
|
||||
// 샘플 데이터가 있으면 변수 치환
|
||||
if (sampleData) {
|
||||
html = mailQueryService.replaceVariables(html, sampleData);
|
||||
subject = mailQueryService.replaceVariables(subject, sampleData);
|
||||
html = replaceVariables(html, sampleData);
|
||||
subject = replaceVariables(subject, sampleData);
|
||||
}
|
||||
|
||||
return res.json({
|
||||
@@ -217,31 +226,10 @@ export class MailTemplateFileController {
|
||||
});
|
||||
}
|
||||
|
||||
const queryResult = await mailQueryService.executeQuery(query.sql, parameters || []);
|
||||
if (!queryResult.success || !queryResult.data || queryResult.data.length === 0) {
|
||||
return res.status(400).json({
|
||||
success: false,
|
||||
message: '쿼리 결과가 없습니다.',
|
||||
error: queryResult.error,
|
||||
});
|
||||
}
|
||||
|
||||
// 첫 번째 행으로 미리보기
|
||||
const sampleData = queryResult.data[0];
|
||||
let html = mailTemplateFileService.renderTemplateToHtml(template.components);
|
||||
let subject = template.subject;
|
||||
|
||||
html = mailQueryService.replaceVariables(html, sampleData);
|
||||
subject = mailQueryService.replaceVariables(subject, sampleData);
|
||||
|
||||
return res.json({
|
||||
success: true,
|
||||
data: {
|
||||
subject,
|
||||
html,
|
||||
sampleData,
|
||||
totalRecipients: queryResult.data.length,
|
||||
},
|
||||
// SQL 쿼리 기능은 구현되지 않음
|
||||
return res.status(501).json({
|
||||
success: false,
|
||||
message: 'SQL 쿼리 연동 기능은 현재 지원하지 않습니다.',
|
||||
});
|
||||
} catch (error: unknown) {
|
||||
const err = error as Error;
|
||||
|
||||
Reference in New Issue
Block a user