summaryrefslogtreecommitdiff
path: root/lib/vendors/validations.ts
diff options
context:
space:
mode:
authordujinkim <dujin.kim@dtsolution.co.kr>2025-04-02 09:54:08 +0000
committerdujinkim <dujin.kim@dtsolution.co.kr>2025-04-02 09:54:08 +0000
commitdfdfae3018f8499240f48d28ce634f4a5c56e006 (patch)
tree4493b172c061fa5bf4e94c083788110eb1507f6d /lib/vendors/validations.ts
parent21a72eeddc74cf775e2a76e2c569de970bd62a7f (diff)
벤더 코멘트 처리
Diffstat (limited to 'lib/vendors/validations.ts')
-rw-r--r--lib/vendors/validations.ts103
1 files changed, 101 insertions, 2 deletions
diff --git a/lib/vendors/validations.ts b/lib/vendors/validations.ts
index 14efc8dc..1c08f8ff 100644
--- a/lib/vendors/validations.ts
+++ b/lib/vendors/validations.ts
@@ -1,4 +1,3 @@
-import { tasks, type Task } from "@/db/schema/tasks";
import {
createSearchParamsCache,
parseAsArrayOf,
@@ -9,7 +8,7 @@ import {
import * as z from "zod"
import { getFiltersStateParser, getSortingStateParser } from "@/lib/parsers"
-import { Vendor, VendorContact, VendorItemsView, vendors } from "@/db/schema/vendors";
+import { Vendor, VendorContact, vendorInvestigationsView, VendorItemsView, vendors } from "@/db/schema/vendors";
import { rfqs } from "@/db/schema/rfq"
@@ -339,3 +338,103 @@ export type UpdateVendorContactSchema = z.infer<typeof updateVendorContactSchema
export type CreateVendorItemSchema = z.infer<typeof createVendorItemSchema>
export type UpdateVendorItemSchema = z.infer<typeof updateVendorItemSchema>
export type GetRfqHistorySchema = Awaited<ReturnType<typeof searchParamsRfqHistoryCache.parse>>
+
+
+
+export const updateVendorInfoSchema = z.object({
+ vendorName: z.string().min(1, "업체명은 필수 입력사항입니다."),
+ taxId: z.string(),
+ address: z.string().optional(),
+ country: z.string().min(1, "국가를 선택해 주세요."),
+ phone: z.string().optional(),
+ email: z.string().email("유효한 이메일을 입력해 주세요."),
+ website: z.string().optional(),
+
+ // 한국 사업자 정보 (KR일 경우 필수 항목들)
+ representativeName: z.string().optional(),
+ representativeBirth: z.string().optional(),
+ representativeEmail: z.string().optional(),
+ representativePhone: z.string().optional(),
+ corporateRegistrationNumber: z.string().optional(),
+
+ // 신용평가 정보
+ creditAgency: z.string().optional(),
+ creditRating: z.string().optional(),
+ cashFlowRating: z.string().optional(),
+
+ // 첨부파일
+ attachedFiles: z.any().optional(),
+ creditRatingAttachment: z.any().optional(),
+ cashFlowRatingAttachment: z.any().optional(),
+
+ // 연락처 정보
+ contacts: z.array(contactSchema).min(1, "최소 1명의 담당자가 필요합니다."),
+})
+
+export const updateVendorSchemaWithConditions = updateVendorInfoSchema.superRefine(
+ (data, ctx) => {
+ // 국가가 한국(KR)인 경우, 한국 사업자 정보 필수
+ if (data.country === "KR") {
+ if (!data.representativeName) {
+ ctx.addIssue({
+ code: z.ZodIssueCode.custom,
+ message: "대표자 이름은 필수 입력사항입니다.",
+ path: ["representativeName"],
+ })
+ }
+
+ if (!data.representativeBirth) {
+ ctx.addIssue({
+ code: z.ZodIssueCode.custom,
+ message: "대표자 생년월일은 필수 입력사항입니다.",
+ path: ["representativeBirth"],
+ })
+ }
+
+ if (!data.representativeEmail) {
+ ctx.addIssue({
+ code: z.ZodIssueCode.custom,
+ message: "대표자 이메일은 필수 입력사항입니다.",
+ path: ["representativeEmail"],
+ })
+ }
+
+ if (!data.representativePhone) {
+ ctx.addIssue({
+ code: z.ZodIssueCode.custom,
+ message: "대표자 전화번호는 필수 입력사항입니다.",
+ path: ["representativePhone"],
+ })
+ }
+
+ if (!data.corporateRegistrationNumber) {
+ ctx.addIssue({
+ code: z.ZodIssueCode.custom,
+ message: "법인등록번호는 필수 입력사항입니다.",
+ path: ["corporateRegistrationNumber"],
+ })
+ }
+
+ // 신용평가사가 선택된 경우, 등급 정보 필수
+ if (data.creditAgency) {
+ if (!data.creditRating) {
+ ctx.addIssue({
+ code: z.ZodIssueCode.custom,
+ message: "신용평가등급은 필수 입력사항입니다.",
+ path: ["creditRating"],
+ })
+ }
+
+ if (!data.cashFlowRating) {
+ ctx.addIssue({
+ code: z.ZodIssueCode.custom,
+ message: "현금흐름등급은 필수 입력사항입니다.",
+ path: ["cashFlowRating"],
+ })
+ }
+ }
+ }
+ }
+)
+
+export type UpdateVendorInfoSchema = z.infer<typeof updateVendorInfoSchema> \ No newline at end of file