main
|
Last change
on this file since b6e1b3c was 1ac9ee4, checked in by Tome <gjorgievtome@…>, 6 months ago |
|
Refactor queries and telefunctions 2
|
-
Property mode
set to
100644
|
|
File size:
1.3 KB
|
| Rev | Line | |
|---|
| [b69759d] | 1 | import * as drizzleQueries from "../../../database/drizzle/queries";
|
|---|
| 2 | import {requireUser} from "../../../server/telefunc/ctx";
|
|---|
| [226fbbb] | 3 | import {Abort} from "telefunc";
|
|---|
| [b69759d] | 4 |
|
|---|
| 5 | export async function getUserInfoAndData() {
|
|---|
| 6 | const { c, userId } = requireUser()
|
|---|
| 7 |
|
|---|
| 8 | const user = await drizzleQueries.getUserProfile(c.db, userId);
|
|---|
| 9 |
|
|---|
| 10 | if (!user) throw new Error();
|
|---|
| 11 |
|
|---|
| 12 | const userBuilds = await drizzleQueries.getUserBuilds(c.db, userId);
|
|---|
| 13 | const favoriteBuilds = await drizzleQueries.getFavoriteBuilds(c.db, userId);
|
|---|
| 14 |
|
|---|
| 15 | return {
|
|---|
| [9c87509] | 16 | user: {
|
|---|
| 17 | ...user,
|
|---|
| 18 | id: userId,
|
|---|
| 19 | },
|
|---|
| [b69759d] | 20 | userBuilds,
|
|---|
| 21 | favoriteBuilds
|
|---|
| 22 | };
|
|---|
| [226fbbb] | 23 | }
|
|---|
| 24 |
|
|---|
| 25 | export async function onDeleteBuild({ buildId }
|
|---|
| 26 | : { buildId: number }) {
|
|---|
| 27 | const { c, userId } = requireUser()
|
|---|
| 28 |
|
|---|
| 29 | if (!Number.isInteger(buildId) || buildId <= 0) throw Abort();
|
|---|
| 30 |
|
|---|
| 31 | const result = await drizzleQueries.deleteBuild(c.db, userId, buildId);
|
|---|
| 32 |
|
|---|
| [83fb5e2] | 33 | if(!result) throw Abort();
|
|---|
| 34 |
|
|---|
| [226fbbb] | 35 | return { success: true };
|
|---|
| 36 | }
|
|---|
| 37 |
|
|---|
| 38 | export async function onEditBuild({ buildId }
|
|---|
| 39 | : { buildId: number }) {
|
|---|
| 40 | const { c, userId } = requireUser()
|
|---|
| 41 |
|
|---|
| 42 | if(!Number.isInteger(buildId) || buildId <= 0) throw Abort();
|
|---|
| 43 |
|
|---|
| [1ac9ee4] | 44 | const buildToEditId = await drizzleQueries.editBuild(c.db, userId, buildId);
|
|---|
| [226fbbb] | 45 |
|
|---|
| [1ac9ee4] | 46 | if(!buildToEditId) throw Abort();
|
|---|
| [226fbbb] | 47 |
|
|---|
| [1ac9ee4] | 48 | return buildToEditId;
|
|---|
| [b69759d] | 49 | } |
|---|
Note:
See
TracBrowser
for help on using the repository browser.