source: pages/+Layout.telefunc.ts@ b615094

main
Last change on this file since b615094 was b69759d, checked in by Tome <gjorgievtome@…>, 7 months ago

add telefunctions

  • Property mode set to 100644
File size: 2.8 KB
Line 
1import * as drizzleQueries from "../database/drizzle/queries";
2import {ctx, getAuthState, requireUser} from "../server/telefunc/ctx";
3import {Abort} from "telefunc";
4
5export async function getAuthenticationState() {
6 const c = getAuthState();
7
8 return c;
9}
10
11export async function getPopupAllComponents({ componentType, q, limit }
12 : { componentType?: string; q?: string; limit?: number }) {
13 const c = ctx();
14
15 // getAllComponents
16}
17
18export async function getPopupAllApprovedBuilds({ limit, q }
19 : { limit?: number; q?: string }) {
20 const context = ctx();
21
22 const approvedBuilds = await drizzleQueries.getApprovedBuilds(context.db, limit, q);
23
24 return approvedBuilds;
25}
26
27export async function getPopupHighestRankedBuilds({ limit }
28 : { limit?: number }) {
29 const context = ctx();
30
31 const highestRankedBuilds = await drizzleQueries.getHighestRankedBuilds(context.db, limit);
32
33 return highestRankedBuilds;
34}
35
36// Shared
37
38export async function getPopupBuildDetails({ buildId }
39 : { buildId: number }) {
40 const context = ctx();
41
42 if(!Number.isInteger(buildId) || buildId <= 0) throw Abort();
43
44 const buildDetails = await drizzleQueries.getBuildDetails(context.db, buildId);
45
46 if(!buildDetails) throw Abort();
47
48 return buildDetails;
49}
50
51export async function togglePopupFavorite({ buildId }
52 : { buildId: number }) {
53 const { c, userId } = requireUser()
54
55 if (!Number.isInteger(buildId) || buildId <= 0) throw Abort();
56
57 const isFavorite = await drizzleQueries.toggleFavoriteBuild(c.db, userId, buildId);
58
59 return isFavorite.favorite;
60}
61
62export async function setPopupRating({ buildId, value }
63 : { buildId: number; value: number }) {
64 const { c, userId } = requireUser()
65
66 if (!Number.isInteger(buildId) || buildId <= 0) throw Abort();
67
68 const result = await drizzleQueries.setBuildRating(c.db, userId, buildId, value);
69
70 return { success: true };
71}
72
73export async function setPopupReview({ buildId, content }
74 : { buildId: number; content: string }) {
75 const { c, userId } = requireUser()
76
77 if (!Number.isInteger(buildId) || buildId <= 0) throw Abort();
78
79 const result = await drizzleQueries.setBuildReview(c.db, userId, buildId, content);
80
81 return { success: true };
82}
83
84export async function clonePopupBuild({ buildId }
85 : { buildId: number }) {
86 const { c, userId } = requireUser()
87
88 if (!Number.isInteger(buildId) || buildId <= 0) throw Abort();
89
90 const newBuildId = await drizzleQueries.cloneBuild(c.db, userId, buildId);
91
92 if (!newBuildId) throw Abort();
93
94 return newBuildId;
95}
Note: See TracBrowser for help on using the repository browser.