diff options
| author | dujinkim <dujin.kim@dtsolution.co.kr> | 2025-07-25 07:51:15 +0000 |
|---|---|---|
| committer | dujinkim <dujin.kim@dtsolution.co.kr> | 2025-07-25 07:51:15 +0000 |
| commit | 2650b7c0bb0ea12b68a58c0439f72d61df04b2f1 (patch) | |
| tree | 17156183fd74b69d78178065388ac61a18ac07b4 /lib/evaluation-target-list/service.ts | |
| parent | d32acea05915bd6c1ed4b95e56c41ef9204347bc (diff) | |
(대표님) 정기평가 대상, 미들웨어 수정, nextauth 토큰 처리 개선, GTC 등
(최겸) 기술영업
Diffstat (limited to 'lib/evaluation-target-list/service.ts')
| -rw-r--r-- | lib/evaluation-target-list/service.ts | 62 |
1 files changed, 44 insertions, 18 deletions
diff --git a/lib/evaluation-target-list/service.ts b/lib/evaluation-target-list/service.ts index 8d890604..36251c2d 100644 --- a/lib/evaluation-target-list/service.ts +++ b/lib/evaluation-target-list/service.ts @@ -35,7 +35,7 @@ import { authOptions } from "@/app/api/auth/[...nextauth]/route" import { sendEmail } from "../mail/sendEmail"; import type { SQL } from "drizzle-orm" import { DEPARTMENT_CODE_LABELS } from "@/types/evaluation"; -import { revalidatePath } from "next/cache"; +import { revalidatePath,unstable_noStore } from "next/cache"; export async function selectEvaluationTargetsFromView( tx: PgTransaction<any, any, any>, @@ -72,11 +72,8 @@ export async function countEvaluationTargetsFromView( // ============= 메인 서버 액션도 함께 수정 ============= export async function getEvaluationTargets(input: GetEvaluationTargetsSchema) { + unstable_noStore() try { - console.log("=== 서버 액션 호출 ==="); - console.log("필터 수:", input.filters?.length || 0); - console.log("조인 연산자:", input.joinOperator); - const offset = (input.page - 1) * input.perPage; // ✅ 단순화된 필터 처리 @@ -297,6 +294,8 @@ export async function createEvaluationTarget( ) .limit(1); + console.log(existing,input ) + if (existing.length > 0) { throw new Error("이미 동일한 평가 대상이 존재합니다."); } @@ -434,6 +433,8 @@ export async function updateEvaluationTarget(input: UpdateEvaluationTargetInput) throw new Error("인증이 필요합니다.") } + console.log(input,"input") + return await db.transaction(async (tx) => { // 평가 대상 존재 확인 const existing = await tx @@ -533,6 +534,9 @@ export async function updateEvaluationTarget(input: UpdateEvaluationTargetInput) for (const review of reviewUpdates) { if (review.isApproved !== undefined) { + + console.log(review.departmentCode,"review.departmentCode"); + // 해당 부서의 담당자 조회 const reviewer = await tx .select({ @@ -547,6 +551,8 @@ export async function updateEvaluationTarget(input: UpdateEvaluationTargetInput) ) .limit(1) + console.log(reviewer,"reviewer") + if (reviewer.length > 0) { // 기존 평가 결과 삭제 await tx @@ -554,21 +560,33 @@ export async function updateEvaluationTarget(input: UpdateEvaluationTargetInput) .where( and( eq(evaluationTargetReviews.evaluationTargetId, input.id), - eq(evaluationTargetReviews.reviewerUserId, reviewer[0].reviewerUserId) + eq(evaluationTargetReviews.reviewerUserId, reviewer[0].reviewerUserId), + eq(evaluationTargetReviews.departmentCode, review.departmentCode) // 추가 + ) ) // 새 평가 결과 추가 (null이 아닌 경우만) if (review.isApproved !== null) { - await tx - .insert(evaluationTargetReviews) - .values({ - evaluationTargetId: input.id, - reviewerUserId: reviewer[0].reviewerUserId, - departmentCode: review.departmentCode, - isApproved: review.isApproved, - reviewedAt: new Date(), - }) + console.log("INSERT 시도:", review.departmentCode, review.isApproved); + + try { + const insertResult = await tx + .insert(evaluationTargetReviews) + .values({ + evaluationTargetId: input.id, + reviewerUserId: reviewer[0].reviewerUserId, + departmentCode: review.departmentCode, + isApproved: review.isApproved, + reviewedAt: new Date(), + }) + .returning({ id: evaluationTargetReviews.id }); // returning 추가 + + console.log("INSERT 성공:", insertResult); + } catch (insertError) { + console.error("INSERT 에러:", insertError); + throw insertError; + } } } } @@ -599,8 +617,12 @@ export async function updateEvaluationTarget(input: UpdateEvaluationTargetInput) reviewedDepartments.includes(dept) ) + console.log(allRequiredDepartmentsReviewed,"allRequiredDepartmentsReviewed") + + if (allRequiredDepartmentsReviewed) { const approvals = currentReviews.map(r => r.isApproved) + console.log(approvals,"approvals") const allApproved = approvals.every(approval => approval === true) const allRejected = approvals.every(approval => approval === false) const hasConsensus = allApproved || allRejected @@ -621,7 +643,11 @@ export async function updateEvaluationTarget(input: UpdateEvaluationTargetInput) updatedAt: new Date() }) .where(eq(evaluationTargets.id, input.id)) - } + } + + + revalidatePath('/evcp/evaluation-target-list') + revalidatePath('/procurement/evaluation-target-list') return { success: true, @@ -649,7 +675,7 @@ export async function getAvailableReviewers(departmentCode?: string) { }) .from(users) .orderBy(users.name) - .limit(100); + // .limit(100); return reviewers; } catch (error) { @@ -683,7 +709,7 @@ export async function getAvailableVendors(search?: string) { ) ) .orderBy(vendors.vendorName) - .limit(100); + // .limit(100); return await query; } catch (error) { |
