summaryrefslogtreecommitdiff
path: root/lib/vendor-document/service.ts
diff options
context:
space:
mode:
authordujinkim <dujin.kim@dtsolution.co.kr>2025-05-28 17:23:13 +0000
committerdujinkim <dujin.kim@dtsolution.co.kr>2025-05-28 17:23:13 +0000
commit4bad21ef79fdda5f016e2012ba673d6ee6abb5fc (patch)
tree4a02504cc1e983d7bacdc01442df44f35865b37d /lib/vendor-document/service.ts
parent36dd60ca6fce7712b35e6d7c1b9602710f442ada (diff)
(대표님) lib 파트 개발 0528
Diffstat (limited to 'lib/vendor-document/service.ts')
-rw-r--r--lib/vendor-document/service.ts87
1 files changed, 70 insertions, 17 deletions
diff --git a/lib/vendor-document/service.ts b/lib/vendor-document/service.ts
index d81e703c..a0ae6f76 100644
--- a/lib/vendor-document/service.ts
+++ b/lib/vendor-document/service.ts
@@ -198,6 +198,12 @@ export async function createRevisionAction(formData: FormData) {
const uploaderName = formData.get("uploaderName") as string | null
const comment = formData.get("comment") as string | null
+ // 추가 필드들 (옵션)
+ const uploaderId = formData.get("uploaderId") as string | null
+ const reviewerId = formData.get("reviewerId") as string | null
+ const reviewerName = formData.get("reviewerName") as string | null
+ const reviewComments = formData.get("reviewComments") as string | null
+
if (!docId || Number.isNaN(docId)) {
throw new Error("Invalid or missing documentId")
}
@@ -244,10 +250,14 @@ export async function createRevisionAction(formData: FormData) {
.where(and(eq(revisions.issueStageId, issueStageId), eq(revisions.revision, revision)))
.limit(1)
- // 기본 상태값 설정
- let status = 'submitted';
- if (uploaderType === 'client') status = 'reviewed';
- if (uploaderType === 'shi') status = 'official';
+ // 기본 상태값 설정 (새로운 상태값 사용)
+ let revisionStatus = 'SUBMITTED';
+ if (uploaderType === 'client') revisionStatus = 'UNDER_REVIEW';
+ if (uploaderType === 'shi') revisionStatus = 'APPROVED';
+
+ // 현재 날짜
+ const now = new Date();
+ const today = now.toISOString().split('T')[0]; // YYYY-MM-DD 형식
if (!revisionRecord.length) {
// Revision이 없으면 새로 생성
@@ -257,29 +267,72 @@ export async function createRevisionAction(formData: FormData) {
issueStageId,
revision,
uploaderType,
+ uploaderId: uploaderId ? parseInt(uploaderId, 10) : undefined,
uploaderName: uploaderName || undefined,
+ revisionStatus,
+ uploadedAt: today,
+ // 상태에 따른 날짜 설정
+ reviewStartDate: revisionStatus === 'UNDER_REVIEW' ? today : undefined,
+ approvedDate: revisionStatus === 'APPROVED' ? today : undefined,
+ // 검토자 정보
+ reviewerId: reviewerId ? parseInt(reviewerId, 10) : undefined,
+ reviewerName: reviewerName || undefined,
+ reviewComments: reviewComments || undefined,
comment: comment || undefined,
- status,
- updatedAt: new Date(),
+ updatedAt: now,
})
.returning()
revisionId = newRevision.id
} else {
- // 이미 존재하는 경우, 업로더 타입이 다르면 업데이트
- if (revisionRecord[0].uploaderType !== uploaderType) {
+ // 이미 존재하는 경우, 업로더 타입이 다르거나 다른 정보가 변경되면 업데이트
+ const existingRevision = revisionRecord[0];
+ const needsUpdate =
+ existingRevision.uploaderType !== uploaderType ||
+ existingRevision.uploaderName !== uploaderName ||
+ existingRevision.comment !== comment;
+
+ if (needsUpdate) {
+ // 상태 변경에 따른 날짜 업데이트 로직
+ const updateValues: any = {
+ uploaderType,
+ uploaderId: uploaderId ? parseInt(uploaderId, 10) : undefined,
+ uploaderName: uploaderName || undefined,
+ revisionStatus,
+ reviewerId: reviewerId ? parseInt(reviewerId, 10) : undefined,
+ reviewerName: reviewerName || undefined,
+ reviewComments: reviewComments || undefined,
+ comment: comment || undefined,
+ updatedAt: now,
+ };
+
+ // 상태가 변경된 경우 해당 날짜 필드 업데이트
+ if (existingRevision.revisionStatus !== revisionStatus) {
+ switch (revisionStatus) {
+ case 'UNDER_REVIEW':
+ if (!existingRevision.reviewStartDate) {
+ updateValues.reviewStartDate = today;
+ }
+ break;
+ case 'APPROVED':
+ if (!existingRevision.approvedDate) {
+ updateValues.approvedDate = today;
+ }
+ break;
+ case 'REJECTED':
+ if (!existingRevision.rejectedDate) {
+ updateValues.rejectedDate = today;
+ }
+ break;
+ }
+ }
+
await tx
.update(revisions)
- .set({
- uploaderType,
- uploaderName: uploaderName || undefined,
- comment: comment || undefined,
- status,
- updatedAt: new Date(),
- })
- .where(eq(revisions.id, revisionRecord[0].id))
+ .set(updateValues)
+ .where(eq(revisions.id, existingRevision.id))
}
- revisionId = revisionRecord[0].id
+ revisionId = existingRevision.id
}
// (3) 파일 처리