diff options
| author | dujinkim <dujin.kim@dtsolution.co.kr> | 2025-06-11 12:18:38 +0000 |
|---|---|---|
| committer | dujinkim <dujin.kim@dtsolution.co.kr> | 2025-06-11 12:18:38 +0000 |
| commit | ff902243a658067fae858a615c0629aa2e0a4837 (patch) | |
| tree | 42d30e986d1cbfb282c644c01730cd053b816b7a /lib/welding/repository.ts | |
| parent | 42e38f41cb4c0b4bf9c08b71ed087cd7f0c7fc18 (diff) | |
(대표님) 20250611 21시 15분 OCR 등
Diffstat (limited to 'lib/welding/repository.ts')
| -rw-r--r-- | lib/welding/repository.ts | 59 |
1 files changed, 41 insertions, 18 deletions
diff --git a/lib/welding/repository.ts b/lib/welding/repository.ts index 10e64f58..1e96867b 100644 --- a/lib/welding/repository.ts +++ b/lib/welding/repository.ts @@ -1,6 +1,6 @@ // src/lib/tasks/repository.ts import db from "@/db/db"; -import { ocrRows } from "@/db/schema"; +import { ocrRows, users } from "@/db/schema"; import { eq, inArray, @@ -21,24 +21,47 @@ import { PgTransaction } from "drizzle-orm/pg-core"; * - 트랜잭션(tx)을 받아서 사용하도록 구현 */ export async function selectOcrRows( - 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(ocrRows) - .where(where) - .orderBy(...(orderBy ?? [])) - .offset(offset) - .limit(limit); + 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({ + // ocrRows의 모든 필드 + id: ocrRows.id, + tableId: ocrRows.tableId, + sessionId: ocrRows.sessionId, + rowIndex: ocrRows.rowIndex, + reportNo: ocrRows.reportNo, + no: ocrRows.no, + identificationNo: ocrRows.identificationNo, + tagNo: ocrRows.tagNo, + jointNo: ocrRows.jointNo, + jointType: ocrRows.jointType, + weldingDate: ocrRows.weldingDate, + confidence: ocrRows.confidence, + sourceTable: ocrRows.sourceTable, + sourceRow: ocrRows.sourceRow, + userId: ocrRows.userId, + createdAt: ocrRows.createdAt, + + // users 테이블의 필드 + userName: users.name, + userEmail: users.email, + }) + .from(ocrRows) + .leftJoin(users, eq(ocrRows.userId, users.id)) + .where(where) + .orderBy(...(orderBy ?? [])) + .offset(offset) + .limit(limit); +} /** 총 개수 count */ export async function countOcrRows( tx: PgTransaction<any, any, any>, |
