Changeset 226fbbb for pages


Ignore:
Timestamp:
12/23/25 04:21:42 (7 months ago)
Author:
Tome <gjorgievtome@…>
Branches:
main
Children:
ea09e98
Parents:
ee1fa4e
Message:

Update telefunctions

Location:
pages
Files:
1 added
1 deleted
3 edited

Legend:

Unmodified
Added
Removed
  • pages/+Layout.telefunc.ts

    ree1fa4e r226fbbb  
    22import {ctx, getAuthState, requireUser} from "../server/telefunc/ctx";
    33import {Abort} from "telefunc";
     4import type {Database} from "../database/drizzle/db";
    45
    5 export async function getAuthenticationState() {
     6export async function AuthenticationState() {
    67    const context = getAuthState();
    78
     
    910}
    1011
    11 export async function getPopupAllComponents({ componentType, limit, q }
     12export async function onGetAllComponents({ componentType, limit, q }
    1213                                            : { componentType?: string; limit?: number; q?: string }) {
    1314    const c = ctx();
     
    1819}
    1920
    20 export async function getPopupComponentDetails({ componentId }
     21export async function onGetComponentDetails({ componentId }
    2122                                           : { componentId: number }) {
    2223    const context = ctx();
     
    3132}
    3233
    33 export async function getPopupSuggestComponent({ link, description, componentType }
     34export async function onSuggestComponent({ link, description, componentType }
    3435                                               : { link: string; description: string; componentType: string }) {
    3536    const { c, userId } = requireUser()
    3637
    37     const newSuggestionId = await drizzleQueries.addComponentSuggestion(c.db, userId, link, description, componentType);
     38    const newSuggestionId = await drizzleQueries.addNewComponentSuggestion(c.db, userId, link, description, componentType);
    3839
    3940    if(!newSuggestionId) throw Abort();
     
    4243}
    4344
    44 export async function getPopupAllApprovedBuilds({ limit, q }
     45export async function onGetApprovedBuilds({ limit, q }
    4546                                                 : { limit?: number; q?: string }) {
    4647    const context = ctx();
     
    5152}
    5253
    53 export async function getPopupHighestRankedBuilds({ limit }
     54export async function onGetHighestRankedBuilds({ limit }
    5455                                                  : { limit?: number }) {
    5556    const context = ctx();
     
    6263// Shared
    6364
    64 export async function getPopupBuildDetails({ buildId }
     65export async function onGetBuildDetails({ buildId }
    6566                                           : { buildId: number }) {
    6667    const context = getAuthState();
     
    7576}
    7677
    77 export async function togglePopupFavorite({ buildId }
     78export async function onToggleFavorite({ buildId }
    7879                                          : { buildId: number }) {
    7980    const { c, userId } = requireUser()
     
    8687}
    8788
    88 export async function setPopupRating({ buildId, value }
     89export async function onSetRating({ buildId, value }
    8990                                     : { buildId: number; value: number }) {
    9091    const { c, userId } = requireUser()
     
    99100}
    100101
    101 export async function setPopupReview({ buildId, content }
     102export async function onSetReview({ buildId, content }
    102103                                     : { buildId: number; content: string }) {
    103104    const { c, userId } = requireUser()
     
    110111}
    111112
    112 export async function clonePopupBuild({ buildId }
     113export async function onCloneBuild({ buildId }
    113114                                      : { buildId: number }) {
    114115    const { c, userId } = requireUser()
     
    116117    if (!Number.isInteger(buildId) || buildId <= 0) throw Abort();
    117118
    118     const newBuildId = await drizzleQueries.cloneBuild(c.db, userId, buildId);
     119    const newBuild = await drizzleQueries.cloneBuild(c.db, userId, buildId);
    119120
    120     if (!newBuildId) throw Abort();
     121    if (!newBuild) throw Abort();
    121122
    122     return newBuildId;
     123    return newBuild;
    123124}
     125
     126
     127
     128
     129
     130
  • pages/dashboard/admin/adminDashboard.telefunc.ts

    ree1fa4e r226fbbb  
    22import { requireAdmin } from "../../../server/telefunc/ctx";
    33import {Abort} from "telefunc";
     4import { validateComponentSpecificData } from "../../../database/drizzle/config/componentFieldConfig";
    45
    56export async function getAdminInfoAndData() {
     
    2223}
    2324
    24 export async function setPopupBuildApprovalStatus({ buildId, isApproved }
     25export async function onSetBuildApprovalStatus({ buildId, isApproved }
    2526                                                 : { buildId: number; isApproved: boolean }) {
    2627    const { c, userId } = await requireAdmin()
     
    3536}
    3637
    37 export async function setComponentSuggestionStatus({ suggestionId, status, adminComment }
     38export async function onSetComponentSuggestionStatus({ suggestionId, status, adminComment }
    3839                                                : { suggestionId: number; status: string; adminComment: string }) {
    3940    const { c, userId } = await requireAdmin()
     
    4849    return { success: true };
    4950}
     51
     52export async function onCreateNewComponent({ name, brand, price, imgUrl, type, specificData }
     53                                            : { name: string; brand: string; price: number; imgUrl: string; type: string, specificData: any }) {
     54
     55    const { c, userId } = await requireAdmin()
     56
     57    if(!validateComponentSpecificData(type, specificData)) throw Abort();
     58
     59    const newComponentId = await drizzleQueries.addNewComponent(c.db, name, brand, price, imgUrl, type, specificData);
     60
     61    if(!newComponentId) throw Abort();
     62
     63    return newComponentId;
     64}
  • pages/dashboard/user/userDashboard.telefunc.ts

    ree1fa4e r226fbbb  
    11import * as drizzleQueries from "../../../database/drizzle/queries";
    22import {requireUser} from "../../../server/telefunc/ctx";
     3import {Abort} from "telefunc";
    34
    45export async function getUserInfoAndData() {
     
    1819    };
    1920}
     21
     22export async function onDeleteBuild({ buildId }
     23                                  : { buildId: number }) {
     24    const { c, userId } = requireUser()
     25
     26    if (!Number.isInteger(buildId) || buildId <= 0) throw Abort();
     27
     28    const result = await drizzleQueries.deleteBuild(c.db, userId, buildId);
     29
     30    return { success: true };
     31}
     32
     33export async function onEditBuild({ buildId }
     34                                  : { buildId: number }) {
     35    const { c, userId } = requireUser()
     36
     37    if(!Number.isInteger(buildId) || buildId <= 0) throw Abort();
     38
     39    const buildDetails = await drizzleQueries.getBuildDetails(c.db, buildId, userId);
     40
     41    if(!buildDetails) throw Abort();
     42
     43    return buildDetails;
     44}
     45
     46export async function onSaveEditBuild({ buildId, name, description, componentIds }
     47                                      : { buildId: number; name: string; description: string; componentIds: number[] }) {
     48    const { c, userId } = requireUser()
     49
     50    if (!Number.isInteger(buildId) || buildId <= 0) throw Abort();
     51
     52    const result = await drizzleQueries.editBuild(c.db, userId, buildId, name, description, componentIds);
     53
     54    if(!result) throw Abort();
     55
     56    return { success: true };
     57}
Note: See TracChangeset for help on using the changeset viewer.