From 9ceed79cf32c896f8a998399bf1b296506b2cd4a Mon Sep 17 00:00:00 2001 From: dujinkim Date: Tue, 8 Apr 2025 03:08:19 +0000 Subject: 로그인 및 미들웨어 처리. 구조 변경 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/form-list/repository.ts | 58 +++++++++++++++++++++++++++++---------------- 1 file changed, 38 insertions(+), 20 deletions(-) (limited to 'lib/form-list/repository.ts') diff --git a/lib/form-list/repository.ts b/lib/form-list/repository.ts index ced320db..d3c555bf 100644 --- a/lib/form-list/repository.ts +++ b/lib/form-list/repository.ts @@ -1,4 +1,5 @@ import db from "@/db/db"; +import { projects } from "@/db/schema"; import { Item, items } from "@/db/schema/items"; import { tagTypeClassFormMappings } from "@/db/schema/vendorData"; import { @@ -17,30 +18,47 @@ import { import { PgTransaction } from "drizzle-orm/pg-core"; export async function selectFormLists( - tx: PgTransaction, - params: { - where?: any; // drizzle-orm의 조건식 (and, eq...) 등 - orderBy?: (ReturnType | ReturnType)[]; - offset?: number; - limit?: number; - } - ) { - const { where, orderBy, offset = 0, limit = 10 } = params; - - return tx - .select() - .from(tagTypeClassFormMappings) - .where(where) - .orderBy(...(orderBy ?? [])) - .offset(offset) - .limit(limit); + tx: PgTransaction, + params: { + where?: any; + orderBy?: (ReturnType | ReturnType)[]; + offset?: number; + limit?: number; } +) { + const { where, orderBy, offset = 0, limit = 10 } = params; + + return tx + .select({ + id: tagTypeClassFormMappings.id, + projectId: tagTypeClassFormMappings.projectId, + tagTypeLabel: tagTypeClassFormMappings.tagTypeLabel, + classLabel: tagTypeClassFormMappings.classLabel, + formCode: tagTypeClassFormMappings.formCode, + formName: tagTypeClassFormMappings.formName, + createdAt: tagTypeClassFormMappings.createdAt, + updatedAt: tagTypeClassFormMappings.updatedAt, + // 프로젝트 정보 추가 + projectCode: projects.code, + projectName: projects.name + }) + .from(tagTypeClassFormMappings) + .innerJoin(projects, eq(tagTypeClassFormMappings.projectId, projects.id)) + .where(where) + .orderBy(...(orderBy ?? [])) + .offset(offset) + .limit(limit); +} + /** 총 개수 count */ export async function countFormLists( tx: PgTransaction, where?: any ) { - const res = await tx.select({ count: count() }).from(tagTypeClassFormMappings).where(where); + const res = await tx + .select({ count: count() }) + .from(tagTypeClassFormMappings) + .leftJoin(projects, eq(tagTypeClassFormMappings.projectId, projects.id)) + .where(where); return res[0]?.count ?? 0; - } - \ No newline at end of file + } \ No newline at end of file -- cgit v1.2.3