feat: implement market page with QueryProvider and dynamic listings
- wrap root layout with QueryProvider for React Query - replace market UnderConstruction placeholder with MarketClient and real data fetching - implement search, pagination, and sort via search params using getActiveListings - add necessary client components and queries - update dependencies (e.g., prisma, pkg-types)
This commit is contained in:
1 parent
55eebde0ba
commit
ab37b477df
106 files changed
+15261
-301
No files matched your search
@@ -231,4 +231,52 @@ export function searchItems<T = any>(params: SearchParams): SearchResult<T> {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Busca um item por ID no banco de dados
|
||||
* Busca em todas as tabelas de categorias até encontrar o item
|
||||
*/
|
||||
export function getItemById(itemId: number, itemName?: string): any | null {
|
||||
const db = getDatabase();
|
||||
if (!db) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
// Buscar em todas as tabelas de categorias
|
||||
const tables = db
|
||||
.prepare("SELECT name FROM sqlite_master WHERE type='table' AND name NOT LIKE 'sqlite_%'")
|
||||
.all() as { name: string }[];
|
||||
|
||||
for (const table of tables) {
|
||||
try {
|
||||
let item: any = null;
|
||||
|
||||
// Se itemName foi fornecido, buscar por ID E NOME (case-insensitive)
|
||||
if (itemName) {
|
||||
item = db.prepare(`SELECT * FROM ${table.name} WHERE id = ? AND LOWER(nome) = LOWER(?)`).get(itemId, itemName);
|
||||
} else {
|
||||
// Se não há nome, buscar apenas por ID (comportamento antigo)
|
||||
item = db.prepare(`SELECT * FROM ${table.name} WHERE id = ?`).get(itemId);
|
||||
}
|
||||
|
||||
if (item) {
|
||||
return item;
|
||||
}
|
||||
} catch (err) {
|
||||
// Ignorar erros de tabelas que não têm coluna 'id' ou 'nome'
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
} catch (error) {
|
||||
console.error("[items-db] Erro ao buscar item por ID:", error);
|
||||
return null;
|
||||
} finally {
|
||||
try {
|
||||
db.close();
|
||||
} catch {
|
||||
// no-op
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user