Ignore:
Timestamp:
12/27/25 02:27:36 (7 months ago)
Author:
Tome <gjorgievtome@…>
Branches:
main
Children:
ad311c3
Parents:
82aa6ae
Message:

implement components query and filtering

File:
1 edited

Legend:

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

    r82aa6ae r9854393  
    108108export async function getApprovedBuilds(db: Database, limit?: number, sort?: string, q?: string) {
    109109    let queryConditions = [eq(buildsTable.isApproved, true)];
    110     let sortConditions = [];
     110    let sortCondition:any;
    111111
    112112    if (q) {
     
    118118    switch(sort) {
    119119        case 'price_asc':
    120             sortConditions.push(
    121                 asc(buildsTable.totalPrice)
    122             );
     120            sortCondition = asc(buildsTable.totalPrice)
    123121            break;
    124122        case 'price_desc':
    125             sortConditions.push(
    126                 desc(buildsTable.totalPrice)
    127             );
     123            sortCondition = desc(buildsTable.totalPrice)
    128124            break;
    129125        case 'rating_desc':
    130             sortConditions.push(
    131                 desc(sql<number>`COALESCE(AVG(${ratingBuildsTable.value}::float),0)`)
    132             );
     126            sortCondition = desc(sql<number>`COALESCE(AVG(${ratingBuildsTable.value}::float),0)`)
    133127            break;
    134128        case 'oldest':
    135             sortConditions.push(
    136                 asc(buildsTable.createdAt)
    137             );
     129            sortCondition = asc(buildsTable.createdAt)
    138130            break;
    139131        case 'newest':
    140             sortConditions.push(
    141                 desc(buildsTable.createdAt)
    142             );
     132            sortCondition = desc(buildsTable.createdAt)
    143133            break;
    144134        default:
    145             sortConditions.push(
    146                 desc(buildsTable.createdAt)
    147             );
     135            sortCondition = desc(buildsTable.createdAt)
    148136            break;
    149137        }
     
    176164        )
    177165        .orderBy(
    178             ...sortConditions
     166            sortCondition
    179167        )
    180168        .limit(limit || 100); // 100 placeholder
Note: See TracChangeset for help on using the changeset viewer.