summaryrefslogtreecommitdiff
path: root/lib/equip-class/repository.ts
diff options
context:
space:
mode:
Diffstat (limited to 'lib/equip-class/repository.ts')
-rw-r--r--lib/equip-class/repository.ts75
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