diff options
Diffstat (limited to 'lib/projects/service.ts')
| -rw-r--r-- | lib/projects/service.ts | 37 |
1 files changed, 30 insertions, 7 deletions
diff --git a/lib/projects/service.ts b/lib/projects/service.ts index aad1856e..ba6e730a 100644 --- a/lib/projects/service.ts +++ b/lib/projects/service.ts @@ -1,13 +1,11 @@ "use server"; // Next.js 서버 액션에서 직접 import하려면 (선택) -import { revalidateTag, unstable_noStore } from "next/cache"; -import db from "@/db/db"; -import { unstable_cache } from "@/lib/unstable-cache"; +import db from "@/db/db"; +import { projects, type Project } from "@/db/schema"; import { filterColumns } from "@/lib/filter-columns"; -import { tagTypeClassFormMappings } from "@/db/schema/vendorData"; -import { asc, desc, ilike, inArray, and, gte, lte, not, or, eq } from "drizzle-orm"; +import { unstable_cache } from "@/lib/unstable-cache"; +import { and, asc, desc, eq, ilike, or } from "drizzle-orm"; import { countProjectLists, selectProjectLists } from "./repository"; -import { projects } from "@/db/schema"; import { GetProjectListsSchema } from "./validation"; export async function getProjectLists(input: GetProjectListsSchema) { @@ -132,4 +130,29 @@ export async function getProjectCode(projectId: number): Promise<string | null> console.error("Error fetching project code:", error) return null } -}
\ No newline at end of file +} + +export async function getProjects(): Promise<Project[]> { + try { + // 트랜잭션을 사용하여 프로젝트 데이터 조회 + const projectList = await db.transaction(async (tx) => { + // 모든 프로젝트 조회 + const results = await tx + .select({ + id: projects.id, + projectCode: projects.code, // 테이블의 실제 컬럼명에 맞게 조정 + projectName: projects.name, // 테이블의 실제 컬럼명에 맞게 조정 + type: projects.type, // 테이블의 실제 컬럼명에 맞게 조정 + }) + .from(projects) + .orderBy(projects.code); + + return results; + }); + + return projectList; + } catch (error) { + console.error("프로젝트 목록 가져오기 실패:", error); + return []; // 오류 발생 시 빈 배열 반환 + } +} |
