Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 44 additions & 21 deletions src/services/exportUserDataToCsv.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,20 @@

/**
* 사용자 데이터를 CSV로 추출
* @param {{ exportAll?: boolean }} reqDto 요청 본문.
* @param {{ is_admin: boolean, id: string }} user 인증 정보.
* @param {{ exportAll?: boolean }} body 요청 본문.
* @returns {Promise<import('@frolog/frolog-api').ExportUserDataToCsvRes>} 응답 DTO.
*/
export default async function exportUserDataToCsv(user, body = {}) {
export default async function exportUserDataToCsv(reqDto = {}, user) {
// (1) 관리자 권한 체크
if (!user.is_admin) {
if (!user || !user.is_admin) {
return {
result: false,
message: 'Access denied. Admin permission required.',
};
}

const { exportAll = true } = body;
const { exportAll = true } = reqDto;

try {
serviceLogger.info({
Expand Down Expand Up @@ -63,7 +63,7 @@
}
}

/**

Check warning on line 66 in src/services/exportUserDataToCsv.js

View workflow job for this annotation

GitHub Actions / test

Missing JSDoc @returns declaration
* 모든 사용자 데이터를 하나의 CSV 파일로 생성
*/
async function createCombinedCsv() {
Expand Down Expand Up @@ -159,7 +159,7 @@
reviews.forEach((review) => {
const book = review.Book || {};
csvData.push({
email: email,

Check warning on line 162 in src/services/exportUserDataToCsv.js

View workflow job for this annotation

GitHub Actions / test

Expected property shorthand
user_id: targetUser.user_id,
종류: '리뷰',
책_제목: book.title || '',
Expand Down Expand Up @@ -192,7 +192,7 @@
? memo.image_urls
: [];
csvData.push({
email: email,

Check warning on line 195 in src/services/exportUserDataToCsv.js

View workflow job for this annotation

GitHub Actions / test

Expected property shorthand
user_id: targetUser.user_id,
종류: '메모',
책_제목: book.title || '',
Expand Down Expand Up @@ -221,7 +221,7 @@
? firstMemo.image_urls
: [];
csvData.push({
email: email,

Check warning on line 224 in src/services/exportUserDataToCsv.js

View workflow job for this annotation

GitHub Actions / test

Expected property shorthand
user_id: targetUser.user_id,
종류: '첫메모',
책_제목: book.title || '',
Expand Down Expand Up @@ -315,7 +315,7 @@
};
}

/**

Check warning on line 318 in src/services/exportUserDataToCsv.js

View workflow job for this annotation

GitHub Actions / test

Missing JSDoc @returns declaration
* 각 사용자별로 개별 CSV 생성 및 이메일 발송
*/
async function createIndividualCsvsAndSendEmails() {
Expand Down Expand Up @@ -416,7 +416,7 @@
};
}

/**

Check warning on line 419 in src/services/exportUserDataToCsv.js

View workflow job for this annotation

GitHub Actions / test

Missing JSDoc @param "email" declaration

Check warning on line 419 in src/services/exportUserDataToCsv.js

View workflow job for this annotation

GitHub Actions / test

Missing JSDoc @param "user" declaration
* 특정 사용자의 CSV 데이터 생성
*/
async function createUserCsvData(user, email) {
Expand Down Expand Up @@ -560,26 +560,49 @@
*/
async function sendCsvEmail(email, userId, csvFilePath, recordCount) {
const csvContent = fs.readFileSync(csvFilePath);
const fileName = path.basename(csvFilePath);

// Raw email with attachment
const boundary = `----=_NextPart_${Date.now()}`;
const rawEmail = [
`From: no-reply@frolog.kr`,
`To: ${email}`,
`Subject: =?UTF-8?B?${Buffer.from('[프롤로그] 서비스 종료 안내').toString('base64')}?=`,
`MIME-Version: 1.0`,
`Content-Type: multipart/mixed; boundary="${boundary}"`,
``,
`--${boundary}`,
`Content-Type: text/plain; charset=UTF-8`,
`Content-Transfer-Encoding: 8bit`,
``,
`안녕하세요. 프롤로그입니다.`,
``,
`프롤로그가 2025년 ㅇ월ㅇ일까지만 서비스를 제공하고 서비스를 종료하게 되었습니다.`,
`저희에게 주신 많은 사랑 감사합니다.`,
``,
`• 총 ${recordCount}개의 글이 포함되어 있습니다.`,
`• 첨부된 CSV 파일을 다운로드하여 확인하실 수 있습니다.`,
``,
`지금까지 적은 기록들은 첨부파일로 보내드렸으니 확인 바랍니다.`,
`감사합니다.`,
``,
`프롤로그 팀 드림`,
``,
`--${boundary}`,
`Content-Type: text/csv; charset=UTF-8; name="${fileName}"`,
`Content-Disposition: attachment; filename="${fileName}"`,
`Content-Transfer-Encoding: base64`,
``,
csvContent.toString('base64'),
``,
`--${boundary}--`,
].join('\r\n');

await ses
.sendEmail({
Destination: {
ToAddresses: [email],
.sendRawEmail({
RawMessage: {
Data: rawEmail,
},
Message: {
Body: {
Text: {
Charset: 'UTF-8',
Data: `안녕하세요. 프롤로그입니다.
프롤로그가 2025년 ㅇ월ㅇ일까지만 서비스를 제공하고 서비스를 종료하게 되었습니다. 저희에게 주신 많은 사랑 감사합니다. 지금까지 적은 기록들은 첨부파일로 보내드렸으니 확인 바랍니다. 감사합니다.`,
},
},
Subject: {
Charset: 'UTF-8',
Data: '[프롤로그] 서비스 종료 안내',
},
},
Source: 'no-reply@frolog.kr',
})
.promise();
}
Expand Down
Loading