From 8001a027efe345b772958da270778ce545b507a6 Mon Sep 17 00:00:00 2001
From: keyy1315
Date: Tue, 8 Jul 2025 14:16:44 +0900
Subject: [PATCH] fix: delete PDF download links at submit mail and added PDF
download defense handling
---
src/app/api/survey-sales/service.ts | 11 ++++----
.../popup/SurveySaleSubmitPopup.tsx | 12 ---------
src/libs/mailer.ts | 27 ++++++++++++++++---
3 files changed, 30 insertions(+), 20 deletions(-)
diff --git a/src/app/api/survey-sales/service.ts b/src/app/api/survey-sales/service.ts
index b9bfbd8..6619e7c 100644
--- a/src/app/api/survey-sales/service.ts
+++ b/src/app/api/survey-sales/service.ts
@@ -277,9 +277,12 @@ export class SurveySalesService {
* @returns {Promise} PDF Blob
*/
async createSurveyPdf(survey: SurveyBasicInfo): Promise {
- const convertedSurvey = convertToCamelCase(survey) as SurveyBasicInfo
- const content = React.createElement(Document, null, React.createElement(SurveySalePdf, { survey: convertedSurvey }))
+ if (!survey) {
+ return new ApiError(HttpStatusCode.NotFound, ERROR_MESSAGE.NOT_FOUND)
+ }
try {
+ const convertedSurvey = convertToCamelCase(survey) as SurveyBasicInfo
+ const content = React.createElement(Document, null, React.createElement(SurveySalePdf, { survey: convertedSurvey }))
const pdfBlob = await pdf(content).toBlob()
const arrayBuffer = await pdfBlob.arrayBuffer()
return new Blob([arrayBuffer], { type: 'application/pdf' })
@@ -427,9 +430,7 @@ export class SurveySalesService {
private checkAdminSubRole(survey: any, storeId: string | null, storeNm: string | null): boolean {
if (!storeId) return false
return survey.SUBMISSION_STATUS
- ? survey.SUBMISSION_TARGET_ID === storeId ||
- survey.SUBMISSION_TARGET_NM === storeNm ||
- survey.STORE_ID === storeId
+ ? survey.SUBMISSION_TARGET_ID === storeId || survey.SUBMISSION_TARGET_NM === storeNm || survey.STORE_ID === storeId
: survey.STORE_ID === storeId
}
diff --git a/src/components/popup/SurveySaleSubmitPopup.tsx b/src/components/popup/SurveySaleSubmitPopup.tsx
index db5cbe3..4c8b4fa 100644
--- a/src/components/popup/SurveySaleSubmitPopup.tsx
+++ b/src/components/popup/SurveySaleSubmitPopup.tsx
@@ -183,18 +183,6 @@ export default function SurveySaleSubmitPopup() {
-施工店名:
${surveyDetail?.constructionPoint ?? ' - '}
-
-
- 現地調査結果PDFダウンロード
-
-
-
- ※リンクをクリックしてローカル調査結果PDFをダウンロードできます。
-
`
diff --git a/src/libs/mailer.ts b/src/libs/mailer.ts
index 10baec3..67bab86 100644
--- a/src/libs/mailer.ts
+++ b/src/libs/mailer.ts
@@ -31,17 +31,38 @@ export async function sendEmail({ from, to, cc, subject, content, attachments, s
*/
let surveyPdfBuffer: Buffer | null = null
if (surveyPdf) {
- const resp = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/api/survey-sales/${surveyPdf.id}?isPdf=true`, {
+ const resp = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/api/survey-sales/${0}?isPdf=true`, {
method: 'GET',
headers: {
'Content-Type': 'application/pdf',
},
})
- const pdfBlob = await resp.blob()
- surveyPdfBuffer = Buffer.from(await pdfBlob.arrayBuffer())
+ if (resp.status == 200) {
+ const pdfBlob = await resp.blob()
+ surveyPdfBuffer = Buffer.from(await pdfBlob.arrayBuffer())
+ }
}
const surveyPdfAttachment = surveyPdfBuffer ? [{ filename: '[HANASYS現地調査]' + surveyPdf?.filename + '.pdf', content: surveyPdfBuffer }] : []
+ if (!surveyPdfBuffer && surveyPdf) {
+ content += `
+
+ `
+ }
+
/**
* @description SMTP 트랜스포터 생성
*/