From 938a8d147886fcd5a7389dec886b5389ff8eb613 Mon Sep 17 00:00:00 2001 From: richardtekula Date: Wed, 28 Jan 2026 07:19:39 +0100 Subject: [PATCH] refactor: Delete unused utility files MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Remove queryBuilder.js and pagination.js — zero imports anywhere in codebase. Co-Authored-By: Claude Opus 4.5 --- src/utils/pagination.js | 25 ---------------- src/utils/queryBuilder.js | 63 --------------------------------------- 2 files changed, 88 deletions(-) delete mode 100644 src/utils/pagination.js delete mode 100644 src/utils/queryBuilder.js diff --git a/src/utils/pagination.js b/src/utils/pagination.js deleted file mode 100644 index f1f3f71..0000000 --- a/src/utils/pagination.js +++ /dev/null @@ -1,25 +0,0 @@ -export const DEFAULT_PAGE_SIZE = 20; -export const MAX_PAGE_SIZE = 100; - -export const parsePagination = (query) => { - const page = Math.max(1, parseInt(query.page) || 1); - const limit = Math.min( - MAX_PAGE_SIZE, - Math.max(1, parseInt(query.limit) || DEFAULT_PAGE_SIZE) - ); - const offset = (page - 1) * limit; - - return { page, limit, offset }; -}; - -export const paginatedResponse = (data, total, { page, limit }) => ({ - data, - pagination: { - page, - limit, - total, - totalPages: Math.ceil(total / limit), - hasNext: page * limit < total, - hasPrev: page > 1, - }, -}); diff --git a/src/utils/queryBuilder.js b/src/utils/queryBuilder.js deleted file mode 100644 index e104e5a..0000000 --- a/src/utils/queryBuilder.js +++ /dev/null @@ -1,63 +0,0 @@ -import { and, or, ilike, eq, desc, asc } from 'drizzle-orm'; -import { NotFoundError } from './errors.js'; - -/** - * Genericky query builder pre list operacie - * @param {object} db - Drizzle db instance - * @param {object} table - Drizzle table - * @param {object} options - Query options - */ -export const buildListQuery = (db, table, options = {}) => { - const { - searchTerm, - searchFields = [], - filters = {}, - orderBy = 'createdAt', - orderDir = 'desc', - limit, - offset, - } = options; - - let query = db.select().from(table); - const conditions = []; - - // Search - if (searchTerm && searchFields.length > 0) { - const searchConditions = searchFields.map((field) => - ilike(table[field], `%${searchTerm}%`) - ); - conditions.push(or(...searchConditions)); - } - - // Filters - Object.entries(filters).forEach(([key, value]) => { - if (value !== undefined && value !== null && value !== '') { - conditions.push(eq(table[key], value)); - } - }); - - if (conditions.length > 0) { - query = query.where(and(...conditions)); - } - - // Order - const orderFn = orderDir === 'desc' ? desc : asc; - query = query.orderBy(orderFn(table[orderBy])); - - // Pagination - if (limit) query = query.limit(limit); - if (offset) query = query.offset(offset); - - return query; -}; - -/** - * Wrapper pre single item fetch s NotFoundError - */ -export const findOneOrThrow = async (db, table, whereClause, errorMessage) => { - const [item] = await db.select().from(table).where(whereClause).limit(1); - if (!item) { - throw new NotFoundError(errorMessage); - } - return item; -};