summaryrefslogtreecommitdiff
path: root/lib/vendor-document-list/service.ts
diff options
context:
space:
mode:
authordujinkim <dujin.kim@dtsolution.co.kr>2025-06-02 06:06:01 +0000
committerdujinkim <dujin.kim@dtsolution.co.kr>2025-06-02 06:06:01 +0000
commit5d14a673d9ad9223a5b5a8f87bbdf6e1594d7751 (patch)
tree0528e6510add7f12fbcff97f694487f48773b183 /lib/vendor-document-list/service.ts
parente5f4a774fabc17b5b18d50c96f5695d89dcabc86 (diff)
(대표님) 20250602 오후 개발사항
Diffstat (limited to 'lib/vendor-document-list/service.ts')
-rw-r--r--lib/vendor-document-list/service.ts47
1 files changed, 29 insertions, 18 deletions
diff --git a/lib/vendor-document-list/service.ts b/lib/vendor-document-list/service.ts
index 356bc792..f3b2b633 100644
--- a/lib/vendor-document-list/service.ts
+++ b/lib/vendor-document-list/service.ts
@@ -81,11 +81,22 @@ export async function getVendorDocuments(input: GetVendorDcoumentsSchema, id: nu
// 입력 스키마 정의
const createDocumentSchema = z.object({
+ contractId: z.number(),
docNumber: z.string().min(1, "Document number is required"),
title: z.string().min(1, "Title is required"),
status: z.string(),
- stages: z.array(z.string()).min(1, "At least one stage is required"),
- contractId: z.number().positive("Contract ID is required")
+ stages: z.array(z.object({
+ name: z.string().min(1, "Stage name cannot be empty"),
+ order: z.number().int().positive("Order must be a positive integer")
+ }))
+ .min(1, "At least one stage is required")
+ .refine(stages => {
+ // 중복된 order 값이 없는지 확인
+ const orders = stages.map(s => s.order);
+ return orders.length === new Set(orders).size;
+ }, {
+ message: "Stage orders must be unique"
+ })
});
export type CreateDocumentInputType = z.infer<typeof createDocumentSchema>;
@@ -104,26 +115,26 @@ export async function createDocument(input: CreateDocumentInputType) {
contractId: validatedData.contractId,
docNumber: validatedData.docNumber,
title: validatedData.title,
- status: validatedData.status,
- // issuedDate는 선택적으로 추가 가능
+ status: validatedData.status,
})
.returning({ id: documents.id });
- // 2. 스테이지 생성 (문서 ID 연결)
- const stageValues = validatedData.stages.map(stageName => ({
+ // 2. 스테이지 생성 (순서와 함께)
+ const stageValues = validatedData.stages.map(stage => ({
documentId: newDocument.id,
- stageName: stageName,
- // planDate, actualDate는 나중에 설정 가능
+ stageName: stage.name,
+ stageOrder: stage.order,
+ stageStatus: "PLANNED", // 기본 상태 설정
}));
// 스테이지 배열 삽입
await tx.insert(issueStages).values(stageValues);
// 성공 결과 반환
- return {
- success: true,
+ return {
+ success: true,
documentId: newDocument.id,
- message: "Document and stages created successfully"
+ message: "Document and stages created successfully"
};
});
} catch (error) {
@@ -131,17 +142,17 @@ export async function createDocument(input: CreateDocumentInputType) {
// Zod 유효성 검사 에러 처리
if (error instanceof z.ZodError) {
- return {
- success: false,
- message: "Validation failed",
- errors: error.errors
+ return {
+ success: false,
+ message: "Validation failed",
+ errors: error.errors
};
}
// 기타 에러 처리
- return {
- success: false,
- message: "Failed to create document"
+ return {
+ success: false,
+ message: "Failed to create document"
};
}
}