diff options
| author | TheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com> | 2025-11-10 11:25:19 +0900 |
|---|---|---|
| committer | TheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com> | 2025-11-10 11:25:19 +0900 |
| commit | a5501ad1d1cb836d2b2f84e9b0f06049e22c901e (patch) | |
| tree | 667ed8c5d6ec35b109190e9f976d66ae54def4ce /lib/vendor-document-list/service.ts | |
| parent | b0fe980376fcf1a19ff4b90851ca8b01f378fdc0 (diff) | |
| parent | f8a38907911d940cb2e8e6c9aa49488d05b2b578 (diff) | |
Merge remote-tracking branch 'origin/dujinkim' into master_homemaster
Diffstat (limited to 'lib/vendor-document-list/service.ts')
| -rw-r--r-- | lib/vendor-document-list/service.ts | 36 |
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 |
