Ignore:
Timestamp:
12/28/25 17:27:19 (6 months ago)
Author:
Tome <gjorgievtome@…>
Branches:
main
Children:
1ac9ee4
Parents:
67186d2
Message:

Refactor queries and telefunctions

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pages/forge/forge.telefunc.ts

    r67186d2 r8fe7f1a  
    55import {removeComponentFromBuild} from "../../database/drizzle/queries";
    66
    7 export async function onSaveNewBuild({ name, description, componentIds }
    8                                        : { name: string; description: string; componentIds: number[] }) {
     7export async function onRemoveComponentFromBuild({ buildId, componentId }
     8                                                 : { buildId: number, componentId: number }) {
    99    const { c, userId } = requireUser()
    1010
    11     const newBuildId = await drizzleQueries.addNewBuild(c.db, userId, name, description, componentIds);
     11    const result = await drizzleQueries.removeComponentFromBuild(c.db, userId, buildId, componentId);
    1212
    13     if(!newBuildId) throw Abort();
     13    if(!result) throw Abort();
    1414
    1515    return { success: true };
    1616}
    1717
    18 export async function onRemoveComponentFromBuild({ buildId, componentId }
    19                                                  : { buildId: number, componentId: number }) {
     18export async function onAddComponentToBuild({ buildId, componentId }: { buildId: number, componentId: number }) {
    2019    const { c, userId } = requireUser()
    2120
    22     const result = await drizzleQueries.removeComponentFromBuild(c.db, buildId, componentId);
     21    if(!Number.isInteger(buildId) || buildId <= 0) throw Abort();
     22    if(!Number.isInteger(componentId) || componentId <= 0) throw Abort();
     23
     24    const result = await drizzleQueries.addComponentToBuild(c.db, userId, buildId, componentId);
    2325
    2426    if(!result) throw Abort();
     
    4951}
    5052
    51 export async function onAddComponentToBuild({ buildId, componentId }: { buildId: number, componentId: number }) {
    52     const { c, userId } = requireUser()
    53 
    54     if(!Number.isInteger(buildId) || buildId <= 0) throw Abort();
    55     if(!Number.isInteger(componentId) || componentId <= 0) throw Abort();
    56 
    57     const result = await drizzleQueries.addComponentToBuild(c.db, buildId, componentId);
    58 
    59     if(!result) throw Abort();
    60 
    61     return { success: true };
    62 }
    63 
    6453export async function onGetCompatibleComponents({ buildId, componentType, limit, sort }
    65                                                 : { db: Database, buildId: number, componentType: string, limit?: number, sort?: string }) {
     54                                                : { buildId: number, componentType: string, limit?: number, sort?: string }) {
    6655    const { c, userId } = requireUser()
    6756
     
    7463    return compatibleComponents;
    7564}
     65
     66export async function onGetBuildState({ db, buildId}
     67                                      :{ db: Database, buildId: number }) {
     68    const { c, userId } = requireUser()
     69
     70    if(!Number.isInteger(buildId) || buildId <= 0) throw Abort();
     71
     72    const buildState = await drizzleQueries.getBuildState(c.db, userId, buildId);
     73
     74    if(!buildState) throw Abort();
     75
     76    return buildState;
     77}
     78
     79export async function saveBuildState({ db, buildId, name, description }
     80                                     :{ db: Database, buildId: number, name: string, description: string }) {
     81    const { c, userId } = requireUser()
     82
     83    if(!Number.isInteger(buildId) || buildId <= 0) throw Abort();
     84
     85    const result = await drizzleQueries.saveBuildState(c.db, userId, buildId, name, description);
     86
     87    if(!result) throw Abort();
     88
     89    return { success: true };
     90}
Note: See TracChangeset for help on using the changeset viewer.