diff options
| author | joonhoekim <26rote@gmail.com> | 2025-09-29 16:32:01 +0900 |
|---|---|---|
| committer | joonhoekim <26rote@gmail.com> | 2025-09-29 16:32:01 +0900 |
| commit | 82a2ce067c9b690cdf7775dfb0be94583f51ca29 (patch) | |
| tree | a449c5b82bd41cd28571729cdbb06c5a70a1a8fe /lib | |
| parent | 921a7672bfb46fb6ed1c6157da3302d31f360139 (diff) | |
(김준회) SWP Document/Drawing List Management 스케줄노트, 보내기 오류 수정
Diffstat (limited to 'lib')
3 files changed, 22 insertions, 17 deletions
diff --git a/lib/vendor-document-list/plant/document-stage-dialogs.tsx b/lib/vendor-document-list/plant/document-stage-dialogs.tsx index 779d31e1..d40af4c3 100644 --- a/lib/vendor-document-list/plant/document-stage-dialogs.tsx +++ b/lib/vendor-document-list/plant/document-stage-dialogs.tsx @@ -65,6 +65,7 @@ import { Controller, useForm, useWatch } from "react-hook-form" import { zodResolver } from "@hookform/resolvers/zod" import { z } from "zod" import { Card, CardContent, CardHeader, CardTitle, CardDescription } from "@/components/ui/card" +import { cn, formatDate } from "@/lib/utils" const getStatusVariant = (status: string) => { switch (status) { @@ -979,12 +980,12 @@ export function EditStageDialog({ const canEditPlanDate = currentStage?.stageStatus === 'PLANNED' const handleSubmit = async () => { - if (!stageId) return + if (!stageId || !currentStage) return setIsLoading(true) try { const result = await updateStage({ - stageId, + id: stageId, planDate: formData.planDate, notes: formData.notes }) diff --git a/lib/vendor-document-list/plant/document-stages-service.ts b/lib/vendor-document-list/plant/document-stages-service.ts index 77a03aae..98eb6f8b 100644 --- a/lib/vendor-document-list/plant/document-stages-service.ts +++ b/lib/vendor-document-list/plant/document-stages-service.ts @@ -295,12 +295,11 @@ export async function updateStage(input: UpdateStageInput) { const validatedData = updateStageSchema.parse(input) // 스테이지 존재 확인 - const existingStage = await db.query.stageIssueStages.findFirst({ - where: eq(stageIssueStages.id, validatedData.id), - with: { - document: true - } - }) + const existingStage = await db.select() + .from(stageIssueStages) + .where(eq(stageIssueStages.id, validatedData.id)) + .limit(1) + .then(rows => rows[0]) if (!existingStage) { throw new Error("스테이지를 찾을 수 없습니다") @@ -320,14 +319,15 @@ export async function updateStage(input: UpdateStageInput) { } } - // 스테이지 업데이트 + // 스테이지 업데이트 (id 제외) + const { id, ...updateData } = validatedData const [updatedStage] = await db .update(stageIssueStages) .set({ - ...validatedData, + ...updateData, updatedAt: new Date(), }) - .where(eq(stageIssueStages.id, validatedData.id)) + .where(eq(stageIssueStages.id, id)) .returning() @@ -1156,7 +1156,7 @@ export async function getDocumentsByStageStats(contractId: number) { } } - +// Send to SHI 버튼 핸들러가 이 함수 호출 export async function sendDocumentsToSHI(contractId: number) { try { const api = new ShiBuyerSystemAPI() diff --git a/lib/vendor-document-list/plant/shi-buyer-system-api.ts b/lib/vendor-document-list/plant/shi-buyer-system-api.ts index 582490af..80575810 100644 --- a/lib/vendor-document-list/plant/shi-buyer-system-api.ts +++ b/lib/vendor-document-list/plant/shi-buyer-system-api.ts @@ -1,7 +1,7 @@ // app/lib/shi-buyer-system-api.ts import db from "@/db/db" import { stageDocuments, stageIssueStages, contracts, vendors, projects, stageSubmissions, stageSubmissionAttachments } from "@/db/schema" -import { eq, and, sql, ne } from "drizzle-orm" +import { eq, and, sql, ne, or, isNull, inArray } from "drizzle-orm" import fs from 'fs/promises' import path from 'path' @@ -174,7 +174,11 @@ export class ShiBuyerSystemAPI { and( eq(stageDocuments.contractId, contractId), eq(stageDocuments.status, 'ACTIVE'), - ne(stageDocuments.buyerSystemStatus, "승인(DC)") + // ne는 null을 포함하지 않음 + or( + isNull(stageDocuments.buyerSystemStatus), + ne(stageDocuments.buyerSystemStatus, "승인(DC)") + ) ) ) @@ -284,7 +288,7 @@ export class ShiBuyerSystemAPI { syncVersion: sql`sync_version + 1`, lastModifiedBy: 'EVCP' }) - .where(sql`id = ANY(${documentIds})`) + .where(inArray(stageDocuments.id, documentIds)) } private async updateSyncError(contractId: number, errorMessage: string) { @@ -823,7 +827,7 @@ export class ShiBuyerSystemAPI { buyerSystemStatus: status === 'synced' ? 'UPLOADED' : 'PENDING', lastModifiedBy: 'EVCP' }) - .where(sql`id = ANY(${attachmentIds})`) + .where(inArray(stageSubmissionAttachments.id, attachmentIds)) } /** @@ -843,7 +847,7 @@ export class ShiBuyerSystemAPI { if (documentIds.length > 0) { conditions.push( - sql`document_id = ANY(${documentIds.map(d => d.id)})` + inArray(stageSubmissions.documentId, documentIds.map(d => d.id)) ) } } |
