Changeset adc31ef


Ignore:
Timestamp:
01/28/26 23:16:36 (5 months ago)
Author:
Tome <gjorgievtome@…>
Branches:
main
Children:
be22289
Parents:
1b5c18b
Message:

Add missing compatibility checks

File:
1 edited

Legend:

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

    r1b5c18b radc31ef  
    271271        networkAdapters: existingComponents.filter(c => c.type === 'network_adapter'),
    272272        soundCards: existingComponents.filter(c => c.type === 'sound_card'),
     273        memoryCards: existingComponents.filter(c => c.type === 'memory_card'),
     274        opticalDrives: existingComponents.filter(c => c.type === 'optical_drive'),
     275        cables: existingComponents.filter(c => c.type === 'cables')
    273276    };
    274277
     
    277280        ...existing.networkCards,
    278281        ...existing.networkAdapters,
    279         ...existing.soundCards
     282        ...existing.soundCards,
     283        ...existing.memoryCards
    280284    ].reduce((sum: number, c: any) => {
    281285        if (!c) return sum;
     
    319323        case 'network_adapter':
    320324        case 'sound_card':
     325        case 'memory_card':
    321326            compatibleComponents = await getCompatiblePCIeComponents(db, existing, componentType, pciExpressSlotsUsed, limit, sortCondition);
     327            break;
     328        case 'optical_drive':
     329            compatibleComponents = await getCompatibleOpticalDrives(db, existing, limit, sortCondition);
     330            break;
     331        case 'cables':
     332            compatibleComponents = await getCompatibleCables(db, limit, sortCondition);
    322333            break;
    323334        default:
     
    920931            };
    921932            break;
     933        case 'memory_card':
     934            table = memoryCardsTable;
     935            selectFields = {
     936                ...selectFields,
     937                numSlots: memoryCardsTable.numSlots,
     938                interface: memoryCardsTable.interface,
     939            };
     940            break;
    922941        default:
    923942            return [];
     
    945964
    946965    return components;
     966}
     967
     968async function getCompatibleOpticalDrives(db: Database, existing: any, limit?: number, sortCondition?: any) {
     969    if (existing.opticalDrives && existing.opticalDrives.length > 0) {
     970        return [];
     971    }
     972
     973    return db
     974        .select({
     975            id: componentsTable.id,
     976            name: componentsTable.name,
     977            brand: componentsTable.brand,
     978            price: componentsTable.price,
     979            imgUrl: componentsTable.imgUrl,
     980            type: componentsTable.type,
     981            driveType: opticalDrivesTable.type,
     982            formFactor: opticalDrivesTable.formFactor,
     983            interface: opticalDrivesTable.interface,
     984            writeSpeed: opticalDrivesTable.writeSpeed,
     985            readSpeed: opticalDrivesTable.readSpeed
     986        })
     987        .from(componentsTable)
     988        .innerJoin(
     989            opticalDrivesTable,
     990            eq(componentsTable.id, opticalDrivesTable.componentId)
     991        )
     992        .where(
     993            eq(componentsTable.type, 'optical_drive')
     994        )
     995        .orderBy(
     996            sortCondition
     997        )
     998        .limit(limit || 100);
     999}
     1000async function getCompatibleCables(db: Database, limit?: number, sortCondition?: any) {
     1001    return db
     1002        .select({
     1003            id: componentsTable.id,
     1004            name: componentsTable.name,
     1005            brand: componentsTable.brand,
     1006            price: componentsTable.price,
     1007            imgUrl: componentsTable.imgUrl,
     1008            type: componentsTable.type,
     1009            lengthCm: cablesTable.lengthCm,
     1010            cableType: cablesTable.type
     1011        })
     1012        .from(componentsTable)
     1013        .innerJoin(
     1014            cablesTable,
     1015            eq(componentsTable.id, cablesTable.componentId)
     1016        )
     1017        .where(
     1018            eq(componentsTable.type, 'cables')
     1019        )
     1020        .orderBy(
     1021            sortCondition
     1022        )
     1023        .limit(limit || 100);
    9471024}
    9481025
Note: See TracChangeset for help on using the changeset viewer.