견적서 복사 -> 이미지 복사 로직 추가

This commit is contained in:
yjnoh 2025-06-02 17:40:38 +09:00
parent 84c18c80f0
commit 639c057e0c
2 changed files with 55 additions and 1 deletions

View File

@ -0,0 +1,42 @@
import { NextResponse } from 'next/server'
import { S3Client, CopyObjectCommand } from '@aws-sdk/client-s3'
import sharp from 'sharp'
import { v4 as uuidv4 } from 'uuid'
const Bucket = process.env.AMPLIFY_BUCKET
const s3 = new S3Client({
region: process.env.AWS_REGION,
credentials: {
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
},
})
export async function POST(req) {
try {
const { objectNo, planNo, newObjectNo, newPlanNo } = await req.json()
const responseArray = []
const copyCommand = new CopyObjectCommand({
Bucket,
CopySource: encodeURI(`${Bucket}/Drawing/${objectNo}_${planNo}_1.png`),
Key: `Drawing/${newObjectNo}_${newPlanNo}_1.png`,
})
const response = await s3.send(copyCommand)
const copyCommand2 = new CopyObjectCommand({
Bucket,
CopySource: encodeURI(`${Bucket}/Drawing/${objectNo}_${planNo}_2.png`),
Key: `Drawing/${newObjectNo}_${newPlanNo}_2.png`,
})
const response2 = await s3.send(copyCommand2)
responseArray.push(response, response2)
return NextResponse.json({ message: '견적서 이미지 복사 성공', responseArray }, { status: 200 })
} catch (error) {
console.error(error)
return NextResponse.json({ message: '견적서 이미지 복사 실패' }, { status: 500 })
}
}

View File

@ -13,6 +13,8 @@ import { useSwal } from '@/hooks/useSwal'
// Constants
const ESTIMATE_API_ENDPOINT = '/api/estimate' // API 엔드포인트 정의
import Config from '@/config/config.export'
// Helper functions
const updateItemInList = (itemList, dispOrder, updates) => {
return itemList.map((item) => (item.dispOrder === dispOrder ? { ...item, ...updates } : item))
@ -464,11 +466,13 @@ export const useEstimateController = (planNo, flag) => {
setIsGlobalLoading(true)
await promisePost({ url: '/api/estimate/save-estimate-copy', data: params })
.then((res) => {
.then(async (res) => {
setIsGlobalLoading(false)
if (res.status === 201) {
if (isObjectNotEmpty(res.data)) {
let newObjectNo = res.data.objectNo
const copyImage = await handleEstimateImageCopy(params.objectNo, params.planNo, newObjectNo, '1')
swalFire({
text: getMessage('estimate.detail.estimateCopyPopup.copy.alertMessage'),
type: 'alert',
@ -489,6 +493,14 @@ export const useEstimateController = (planNo, flag) => {
})
}
const handleEstimateImageCopy = async (objectNo, planNo, newObjectNo, newPlanNo) => {
await promisePost({ url: `${Config().baseUrl}/api/image/estimate-image-copy`, data: { objectNo, planNo, newObjectNo, newPlanNo } }).then(
(res) => {
return res
},
)
}
const handleDeleteEstimate = async (canvasStatus) => {
try {
setIsGlobalLoading(true)