From 5068f3573340b57c5d62a4699bd16e9dbd711b31 Mon Sep 17 00:00:00 2001 From: dujinkim Date: Thu, 18 Sep 2025 05:37:24 +0000 Subject: (최겸) 구매 실사 재의뢰 기능 추가 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/pq/service.ts | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'lib/pq/service.ts') diff --git a/lib/pq/service.ts b/lib/pq/service.ts index 40d81302..5870a77f 100644 --- a/lib/pq/service.ts +++ b/lib/pq/service.ts @@ -2527,6 +2527,53 @@ export async function cancelInvestigationAction(investigationIds: number[]) { } } +// 실사 재의뢰 서버 액션 +export async function reRequestInvestigationAction(investigationIds: number[]) { + try { + const session = await getServerSession(authOptions) + const userId = session?.user?.id ? Number(session.user.id) : null + + if (!userId) { + return { success: false, error: "인증된 사용자만 실사를 재의뢰할 수 있습니다." } + } + + const result = await db.transaction(async (tx) => { + // CANCELED 상태인 실사만 재의뢰 가능 + const updatedInvestigations = await tx + .update(vendorInvestigations) + .set({ + investigationStatus: "PLANNED", + updatedAt: new Date(), + }) + .where( + and( + inArray(vendorInvestigations.id, investigationIds), + eq(vendorInvestigations.investigationStatus, "CANCELED") + ) + ) + .returning() + + return updatedInvestigations + }) + + // 캐시 무효화 + revalidateTag("vendor-investigations") + revalidateTag("pq-submissions") + + return { + success: true, + count: result.length, + data: result + } + } catch (err) { + console.error("실사 재의뢰 중 오류 발생:", err) + return { + success: false, + error: err instanceof Error ? err.message : "알 수 없는 오류가 발생했습니다." + } + } +} + // 실사 결과 발송 서버 액션 export async function sendInvestigationResultsAction(input: { investigationIds: number[]; -- cgit v1.2.3