summaryrefslogtreecommitdiff
path: root/lib/vendor-document-list/service.ts
diff options
context:
space:
mode:
Diffstat (limited to 'lib/vendor-document-list/service.ts')
-rw-r--r--lib/vendor-document-list/service.ts36
1 files changed, 36 insertions, 0 deletions
diff --git a/lib/vendor-document-list/service.ts b/lib/vendor-document-list/service.ts
index 76bdac49..502d9352 100644
--- a/lib/vendor-document-list/service.ts
+++ b/lib/vendor-document-list/service.ts
@@ -4,6 +4,7 @@ import { eq, SQL } from "drizzle-orm"
import db from "@/db/db"
import { documents, documentStagesView, issueStages } from "@/db/schema/vendorDocu"
import { contracts } from "@/db/schema"
+import { projects } from "@/db/schema/projects"
import { GetVendorDcoumentsSchema } from "./validations"
import { unstable_cache } from "@/lib/unstable-cache";
import { filterColumns } from "@/lib/filter-columns";
@@ -323,4 +324,39 @@ export async function getProjectIdsByVendor(vendorId: number): Promise<number[]>
console.error('Error fetching contract IDs by vendor:', error)
return []
}
+}
+
+/**
+ * 프로젝트 ID 배열로 프로젝트 정보를 조회하는 서버 액션
+ * @param projectIds - 프로젝트 ID 배열
+ * @returns 프로젝트 정보 배열 [{ id, code, name }]
+ */
+export async function getProjectsByIds(projectIds: number[]): Promise<Array<{ id: number; code: string; name: string }>> {
+ try {
+ if (projectIds.length === 0) {
+ return []
+ }
+
+ // null 값 제거
+ const validProjectIds = projectIds.filter((id): id is number => id !== null && !isNaN(id))
+
+ if (validProjectIds.length === 0) {
+ return []
+ }
+
+ const projectsData = await db
+ .select({
+ id: projects.id,
+ code: projects.code,
+ name: projects.name,
+ })
+ .from(projects)
+ .where(inArray(projects.id, validProjectIds))
+ .orderBy(projects.code)
+
+ return projectsData
+ } catch (error) {
+ console.error('프로젝트 정보 조회 중 오류:', error)
+ return []
+ }
} \ No newline at end of file