diff options
| author | dujinkim <dujin.kim@dtsolution.co.kr> | 2025-09-18 05:37:24 +0000 |
|---|---|---|
| committer | dujinkim <dujin.kim@dtsolution.co.kr> | 2025-09-18 05:37:24 +0000 |
| commit | 5068f3573340b57c5d62a4699bd16e9dbd711b31 (patch) | |
| tree | 17a7b5c6da7e7c49fa2ca26bd4ac20f1835384cc /lib/pq/service.ts | |
| parent | 6a8d6cda345d13352961d40abd44cfa5daf81591 (diff) | |
(최겸) 구매 실사 재의뢰 기능 추가
Diffstat (limited to 'lib/pq/service.ts')
| -rw-r--r-- | lib/pq/service.ts | 47 |
1 files changed, 47 insertions, 0 deletions
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[];
|
