Changeset dda6f51 for database


Ignore:
Timestamp:
12/29/25 03:57:02 (6 months ago)
Author:
Tome <gjorgievtome@…>
Branches:
main
Children:
f46bf5c
Parents:
3870834
Message:

Implement getDetailsForNewComponent

Location:
database/drizzle
Files:
2 edited

Legend:

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

    r3870834 rdda6f51  
    1212} from "../schema";
    1313import {and, asc, desc, eq, ilike, SQL, sql} from "drizzle-orm";
    14 import {typeConfigMap, ComponentType} from "../util/componentFieldConfig";
     14import {typeConfigMap, ComponentType, requiredFields} from "../util/componentFieldConfig";
    1515import {AnyPgColumn} from "drizzle-orm/pg-core";
    1616import {inArray} from "drizzle-orm/sql/expressions/conditions";
     
    101101        ...component,
    102102        details: details
     103    };
     104}
     105
     106export async function getDetailsForNewComponent(componentType: string) {
     107    const config = typeConfigMap[componentType as ComponentType];
     108
     109    return {
     110        type: componentType as ComponentType,
     111        requiredFields: requiredFields[componentType as ComponentType] ?? [],
     112        multiTables: config.multiTables ?? {},
    103113    };
    104114}
  • database/drizzle/util/componentFieldConfig.ts

    r3870834 rdda6f51  
    108108    return true;
    109109}
    110 
    111 export function getValidationError(type: string, specificData: any): string | null {
    112     if (!(type in requiredFields)) {
    113         return `Invalid component type: ${type}`;
    114     }
    115 
    116     const fields = requiredFields[type as ComponentType];
    117     const missingFields: string[] = [];
    118 
    119     for (const field of fields) {
    120         const value = specificData[field];
    121         if (value === undefined || value === null || value === '') {
    122             missingFields.push(field);
    123         }
    124     }
    125 
    126     if (missingFields.length > 0) {
    127         return `Missing required fields: ${missingFields.join(', ')}`;
    128     }
    129 
    130     return null;
    131 }
Note: See TracChangeset for help on using the changeset viewer.