diff options
| author | dujinkim <dujin.kim@dtsolution.co.kr> | 2025-04-08 03:08:19 +0000 |
|---|---|---|
| committer | dujinkim <dujin.kim@dtsolution.co.kr> | 2025-04-08 03:08:19 +0000 |
| commit | 9ceed79cf32c896f8a998399bf1b296506b2cd4a (patch) | |
| tree | f84750fa6cac954d5e31221fc47a54c655fc06a9 /lib/equip-class/repository.ts | |
| parent | 230ce796836c25df26c130dbcd616ef97d12b2ec (diff) | |
로그인 및 미들웨어 처리. 구조 변경
Diffstat (limited to 'lib/equip-class/repository.ts')
| -rw-r--r-- | lib/equip-class/repository.ts | 75 |
1 files changed, 43 insertions, 32 deletions
diff --git a/lib/equip-class/repository.ts b/lib/equip-class/repository.ts index ddf98dd2..d4d6d58b 100644 --- a/lib/equip-class/repository.ts +++ b/lib/equip-class/repository.ts @@ -1,45 +1,56 @@ import db from "@/db/db"; +import { projects } from "@/db/schema"; import { Item, items } from "@/db/schema/items"; import { tagClasses } from "@/db/schema/vendorData"; import { eq, - inArray, - not, asc, desc, - and, - ilike, - gte, - lte, count, - gt, } from "drizzle-orm"; import { PgTransaction } from "drizzle-orm/pg-core"; export async function selectTagClassLists( - tx: PgTransaction<any, any, any>, - params: { - where?: any; // drizzle-orm의 조건식 (and, eq...) 등 - orderBy?: (ReturnType<typeof asc> | ReturnType<typeof desc>)[]; - offset?: number; - limit?: number; - } - ) { - const { where, orderBy, offset = 0, limit = 10 } = params; - - return tx - .select() - .from(tagClasses) - .where(where) - .orderBy(...(orderBy ?? [])) - .offset(offset) - .limit(limit); + tx: PgTransaction<any, any, any>, + params: { + where?: any; + orderBy?: (ReturnType<typeof asc> | ReturnType<typeof desc>)[]; + offset?: number; + limit?: number; } - /** 총 개수 count */ - export async function countTagClassLists( - tx: PgTransaction<any, any, any>, - where?: any - ) { - const res = await tx.select({ count: count() }).from(tagClasses).where(where); - return res[0]?.count ?? 0; - }
\ No newline at end of file +) { + const { where, orderBy, offset = 0, limit = 10 } = params; + + return tx + .select({ + id: tagClasses.id, + projectId: tagClasses.projectId, + code: tagClasses.code, + label: tagClasses.label, + tagTypeCode: tagClasses.tagTypeCode, + createdAt: tagClasses.createdAt, + updatedAt: tagClasses.updatedAt, + // 프로젝트 정보 추가 + projectCode: projects.code, + projectName: projects.name + }) + .from(tagClasses) + .innerJoin(projects, eq(tagClasses.projectId, projects.id)) + .where(where) + .orderBy(...(orderBy ?? [])) + .offset(offset) + .limit(limit); +} + +/** 총 개수 count */ +export async function countTagClassLists( + tx: PgTransaction<any, any, any>, + where?: any +) { + const res = await tx + .select({ count: count() }) + .from(tagClasses) + .leftJoin(projects, eq(tagClasses.projectId, projects.id)) + .where(where); + return res[0]?.count ?? 0; +}
\ No newline at end of file |
