refactor: Delete unused utility files

Remove queryBuilder.js and pagination.js — zero imports anywhere in codebase.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
richardtekula
2026-01-28 07:19:39 +01:00
parent 883d3fa533
commit 938a8d1478
2 changed files with 0 additions and 88 deletions

View File

@@ -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,
},
});

View File

@@ -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;
};