Ignore:
Timestamp:
12/20/25 04:03:51 (7 months ago)
Author:
Tome <gjorgievtome@…>
Branches:
main
Children:
5ce5904
Parents:
37bcb87
Message:

update queries

File:
1 edited

Legend:

Unmodified
Added
Removed
  • database/drizzle/queries/components.ts

    r37bcb87 rc4dd17d  
    11import type { Database } from "../db";
    2 import { componentsTable, suggestionsTable } from "../schema";
     2import {buildsTable, componentsTable } from "../schema";
     3import {and, desc, eq, ilike} from "drizzle-orm";
    34
    4 export async function getComponentSuggestions(db: Database) {
     5export async function getAllComponents(db: Database, limit?: number,  q?: string, componentType?: string) {
     6    let queryConditions = [];
    57
     8    if (q) {
     9        queryConditions.push(
     10            ilike(componentsTable.name, `%${q}%`)
     11        );
     12    }
     13
     14    if(componentType && componentType.trim() !== 'all') {
     15        queryConditions.push(
     16            eq(componentsTable.type, componentType.trim().toLowerCase())
     17        );
     18    }
     19
     20    const componentsList = await db
     21        .select({
     22            id: componentsTable.id,
     23            name: componentsTable.name,
     24            brand: componentsTable.brand,
     25            price: componentsTable.price,
     26        })
     27        .from(componentsTable)
     28        .where(
     29            queryConditions.length > 0 ?
     30                and (
     31                    ...queryConditions
     32                )
     33                : undefined
     34        )
     35        .orderBy(
     36            desc(componentsTable.price)
     37        )
     38        .limit(limit || 100); // 100 placeholder
     39
     40    return componentsList;
    641}
    742
    8 export async function setComponentSuggestionStatus(db: Database, suggestionId: number, status: string, adminComment: string) {
     43export async function getComponentDetails(db: Database, componentId: number) {
     44    const [componentDetails] = await db
     45        .select()
     46        .from(componentsTable)
     47        .where(
     48            eq(componentsTable.id, componentId)
     49        )
     50        .limit(1);
    951
     52    return componentDetails ?? null;
    1053}
    11 
    12 export async function getAllComponents(db: Database, componentType?: string, q?: string, page?: number, pageSize?: number) {
    13 
    14 }
Note: See TracChangeset for help on using the changeset viewer.