summaryrefslogtreecommitdiff
path: root/app/api
diff options
context:
space:
mode:
Diffstat (limited to 'app/api')
-rw-r--r--app/api/auth/signup-with-vendor/route.ts54
1 files changed, 48 insertions, 6 deletions
diff --git a/app/api/auth/signup-with-vendor/route.ts b/app/api/auth/signup-with-vendor/route.ts
index 1274d59b..fcc06ee8 100644
--- a/app/api/auth/signup-with-vendor/route.ts
+++ b/app/api/auth/signup-with-vendor/route.ts
@@ -15,9 +15,11 @@ import {
consentLogs,
policyVersions
} from '@/db/schema'
+import { vendorPossibleMateirals } from '@/db/schema/vendors'
import { insertVendor } from '@/lib/vendors/repository'
import { getErrorMessage } from '@/lib/handle-error'
import { saveFile, SaveFileResult } from '@/lib/file-stroage'
+import { MaterialSearchItem } from '@/lib/material/material-group-service'
// Types
interface AccountData {
@@ -38,7 +40,7 @@ interface VendorData {
status?: string
taxId: string
vendorTypeId: number
- items?: string
+ items?: MaterialSearchItem[]
representativeName?: string
representativeBirth?: string
representativeEmail?: string
@@ -126,6 +128,42 @@ async function storeVendorFiles(
}
}
+// 벤더 자재 정보 저장 함수
+async function saveVendorMaterials(
+ tx: PgTransaction<any, any, any>,
+ vendorId: number,
+ materials: MaterialSearchItem[],
+ userId: number,
+ userName: string
+) {
+ console.log(`벤더 자재 정보 저장: vendorId=${vendorId}, 자재수=${materials.length}`)
+
+ if (!materials || materials.length === 0) {
+ console.log('저장할 자재 정보가 없습니다.')
+ return
+ }
+
+ for (const material of materials) {
+ await tx.insert(vendorPossibleMateirals).values({
+ vendorId,
+ itemCode: material.materialGroupCode,
+ itemName: material.materialName,
+ registerUserId: userId,
+ registerUserName: userName,
+ isConfirmed: false, // 업체 입력 정보이므로 확정되지 않음
+ // 확정정보가 아니므로 부가정보들은 null
+ recentPoNo: null,
+ recentPoDate: null,
+ recentDeliveryDate: null,
+ recentOrderDate: null,
+ recentOrderUserName: null,
+ purchaseGroupCode: null,
+ })
+ }
+
+ console.log(`벤더 자재 정보 저장 완료: ${materials.length}개 자재`)
+}
+
// 사용자 계정 생성 함수 (승인 대기 상태)
async function createUserAccount(
tx: PgTransaction<any, any, any>,
@@ -245,7 +283,7 @@ function validateVendorData(vendor: VendorData): string[] {
if (!vendor.vendorName?.trim()) errors.push('업체명은 필수입니다.')
if (!vendor.vendorTypeId) errors.push('업체 유형은 필수입니다.')
- if (!vendor.items?.trim()) errors.push('공급품목은 필수입니다.')
+ if (!vendor.items || vendor.items.length === 0) errors.push('공급품목은 필수입니다.')
if (!vendor.taxId?.trim()) errors.push('사업자등록번호는 필수입니다.')
if (!vendor.country?.trim()) errors.push('국가는 필수입니다.')
if (!vendor.phone?.trim()) errors.push('대표 전화번호는 필수입니다.')
@@ -407,7 +445,6 @@ export async function POST(request: NextRequest) {
status: "PENDING_REVIEW", // 관리자 승인 대기
taxId: vendor.taxId,
vendorTypeId: vendor.vendorTypeId,
- items: vendor.items || null,
// 한국 사업자 정보
representativeName: vendor.representativeName || null,
representativeBirth: vendor.representativeBirth || null,
@@ -420,10 +457,15 @@ export async function POST(request: NextRequest) {
// 2. 사용자 계정 생성 (업체 ID와 연결)
newUser = await createUserAccount(tx, account, newVendor.id)
- // 3. 동의 정보 저장
+ // 3. 자재 정보 저장 (vendor와 user 생성 후)
+ if (vendor.items && vendor.items.length > 0) {
+ await saveVendorMaterials(tx, newVendor.id, vendor.items, newUser.id, newUser.name)
+ }
+
+ // 4. 동의 정보 저장
await saveUserConsents(tx, newUser.id, consents, clientIP, userAgent)
- // 4. 파일 저장 (보안 강화된 파일 저장 함수 사용)
+ // 5. 파일 저장 (보안 강화된 파일 저장 함수 사용)
if (businessRegistrationFiles.length > 0) {
await storeVendorFiles(tx, newVendor.id, businessRegistrationFiles, FILE_TYPES.BUSINESS_REGISTRATION, newUser.id)
}
@@ -440,7 +482,7 @@ export async function POST(request: NextRequest) {
await storeVendorFiles(tx, newVendor.id, bankAccountFiles, FILE_TYPES.BANK_ACCOUNT_COPY, newUser.id)
}
- // 5. 담당자 정보 저장
+ // 6. 담당자 정보 저장
for (const [index, contact] of vendor.contacts.entries()) {
await tx.insert(vendorContacts).values({
vendorId: newVendor.id,