1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
|
"use server";
import { getVendorBasicInfo } from "@/lib/vendors/service";
import { VendorFormData } from "./types";
import { getPQDataByVendorId } from "@/lib/pq/service";
import db from "@/db/db"
import { vendorPQSubmissions, vendorPqCriteriaAnswers, pqCriterias, vendorCriteriaAttachments, vendorAdditionalInfo } from "@/db/schema"
import { vendorBusinessContacts } from "@/db/schema"
import { eq } from "drizzle-orm";
/**
* 벤더 기본정보를 가져오는 서버 액션
*/
export async function getVendorData(vendorId: string) {
try {
const id = parseInt(vendorId);
if (isNaN(id)) {
return null;
}
const vendorData = await getVendorBasicInfo(id);
return vendorData;
} catch (error) {
console.error("Error in getVendorData:", error);
return null;
}
}
/**
* 벤더의 PQ 데이터를 가져오는 서버 액션
*/
export async function getVendorPQData(vendorId: string) {
try {
const id = parseInt(vendorId);
if (isNaN(id)) {
return null;
}
const pqData = await getPQDataByVendorId(id);
return pqData;
} catch (error) {
console.error("Error in getVendorPQData:", error);
return null;
}
}
/**
* 벤더의 PQ 제출 데이터와 답변을 가져오는 서버 액션
*/
export async function getVendorPQSubmissionData(vendorId: string) {
try {
const id = parseInt(vendorId);
if (isNaN(id)) {
return null;
}
// 벤더의 모든 PQ 제출 데이터 조회
const submissions = await db
.select()
.from(vendorPQSubmissions)
.where(eq(vendorPQSubmissions.vendorId, id));
if (submissions.length === 0) {
return null;
}
// 각 제출에 대한 답변 데이터 조회
const submissionData = await Promise.all(
submissions.map(async (submission) => {
const answers = await db
.select({
id: vendorPqCriteriaAnswers.id,
vendorId: vendorPqCriteriaAnswers.vendorId,
criteriaId: vendorPqCriteriaAnswers.criteriaId,
projectId: vendorPqCriteriaAnswers.projectId,
answer: vendorPqCriteriaAnswers.answer,
shiComment: vendorPqCriteriaAnswers.shiComment,
vendorReply: vendorPqCriteriaAnswers.vendorReply,
createdAt: vendorPqCriteriaAnswers.createdAt,
updatedAt: vendorPqCriteriaAnswers.updatedAt,
criteriaCode: pqCriterias.code,
checkPoint: pqCriterias.checkPoint,
description: pqCriterias.description,
groupName: pqCriterias.groupName,
subGroupName: pqCriterias.subGroupName,
inputFormat: pqCriterias.inputFormat
})
.from(vendorPqCriteriaAnswers)
.leftJoin(pqCriterias, eq(vendorPqCriteriaAnswers.criteriaId, pqCriterias.id))
.where(eq(vendorPqCriteriaAnswers.vendorId, id));
// 각 답변에 대한 첨부파일 정보 조회
const answersWithAttachments = await Promise.all(
answers.map(async (answer) => {
const attachments = await db
.select({
id: vendorCriteriaAttachments.id,
fileName: vendorCriteriaAttachments.fileName,
originalFileName: vendorCriteriaAttachments.originalFileName,
filePath: vendorCriteriaAttachments.filePath,
fileType: vendorCriteriaAttachments.fileType,
fileSize: vendorCriteriaAttachments.fileSize
})
.from(vendorCriteriaAttachments)
.where(eq(vendorCriteriaAttachments.vendorCriteriaAnswerId, answer.id));
return {
...answer,
uploadedFiles: attachments
};
})
);
return {
submission,
answers: answersWithAttachments
};
})
);
return submissionData;
} catch (error) {
console.error("Error in getVendorPQSubmissionData:", error);
return null;
}
}
/**
* 벤더의 추가정보를 가져오는 서버 액션
*/
export async function getVendorAdditionalInfo(vendorId: string) {
try {
const id = parseInt(vendorId);
if (isNaN(id)) {
return null;
}
const additionalInfo = await db
.select()
.from(vendorAdditionalInfo)
.where(eq(vendorAdditionalInfo.vendorId, id));
return additionalInfo.length > 0 ? additionalInfo[0] : null;
} catch (error) {
console.error("Error in getVendorAdditionalInfo:", error);
return null;
}
}
/**
* 벤더의 업무담당자 정보를 가져오는 서버 액션
*/
export async function getVendorBusinessContacts(vendorId: string) {
try {
const id = parseInt(vendorId);
if (isNaN(id)) {
return [];
}
const rows = await db
.select()
.from(vendorBusinessContacts)
.where(eq(vendorBusinessContacts.vendorId, id));
return rows;
} catch (error) {
console.error("Error in getVendorBusinessContacts:", error);
return [];
}
}
/**
* 벤더 기본정보를 업데이트하는 서버 액션 (향후 구현)
*/
export async function updateVendorData(vendorId: string, formData: VendorFormData) {
try {
// TODO: 실제 업데이트 로직 구현
console.log("Updating vendor data:", { vendorId, formData });
// 임시로 성공 응답 반환
return {
success: true,
message: "(개발중입니다) 벤더 정보가 성공적으로 업데이트되었습니다.",
};
} catch (error) {
console.error("Error in updateVendorData:", error);
return {
success: false,
message: "업데이트 중 오류가 발생했습니다.",
};
}
}
|