rhythia-api 201.0.0 → 202.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -27,53 +27,5 @@ export async function POST(request: Request) {
27
27
  }
28
28
 
29
29
  export async function handler(data: (typeof Schema)["input"]["_type"]) {
30
- const user = (await getUserBySession(data.session)) as User;
31
- let { data: queryUserData, error: userError } = await supabase
32
- .from("profiles")
33
- .select("*")
34
- .eq("uid", user.id)
35
- .single();
36
-
37
- if (!queryUserData) {
38
- return NextResponse.json({ error: "Can't find user" });
39
- }
40
-
41
- let { data: codeData } = await supabase
42
- .from("invites")
43
- .select("*")
44
- .eq("code", data.code)
45
- .single();
46
-
47
- if (!codeData || (codeData && codeData.used)) {
48
- return NextResponse.json({ error: "Can't find code, or used" });
49
- }
50
-
51
- if (codeData.type == "clan") {
52
- if (queryUserData.clan) {
53
- return NextResponse.json({
54
- error: "You can't join another clan while being in a clan",
55
- });
56
- }
57
-
58
- let { data: queryClanData, error: clanError } = await supabase
59
- .from("clans")
60
- .select("*")
61
- .eq("id", Number(codeData.resourceId))
62
- .single();
63
-
64
- if (!queryClanData) {
65
- return NextResponse.json({
66
- error: "No such clan",
67
- });
68
- }
69
-
70
- await supabase.from("profiles").upsert({
71
- id: queryUserData.id,
72
- clan: queryClanData?.id,
73
- });
74
-
75
- return NextResponse.json({});
76
- }
77
-
78
- return NextResponse.json({ error: "Unknown invite type" });
30
+ return NextResponse.json({ error: "Disabled" }, { status: 403 });
79
31
  }
@@ -10,6 +10,7 @@ import { User } from "@supabase/supabase-js";
10
10
  const adminOperations = {
11
11
  deleteUser: z.object({ userId: z.number() }),
12
12
  changeFlag: z.object({ userId: z.number(), flag: z.string() }),
13
+ changeBadges: z.object({ userId: z.number(), badges: z.string() }),
13
14
  excludeUser: z.object({ userId: z.number() }),
14
15
  restrictUser: z.object({ userId: z.number() }),
15
16
  silenceUser: z.object({ userId: z.number() }),
@@ -62,6 +63,10 @@ const OperationParam = z.discriminatedUnion("operation", [
62
63
  operation: z.literal("changeFlag"),
63
64
  params: adminOperations.changeFlag,
64
65
  }),
66
+ z.object({
67
+ operation: z.literal("changeBadges"),
68
+ params: adminOperations.changeBadges,
69
+ }),
65
70
  ]);
66
71
 
67
72
  export const Schema = {
@@ -183,7 +188,7 @@ export async function handler(
183
188
  break;
184
189
 
185
190
  case "changeFlag":
186
- await supabase
191
+ result = await supabase
187
192
  .from("profiles")
188
193
  .upsert({
189
194
  id: params.userId,
@@ -191,6 +196,15 @@ export async function handler(
191
196
  })
192
197
  .select();
193
198
  break;
199
+ case "changeBadges":
200
+ result = await supabase
201
+ .from("profiles")
202
+ .upsert({
203
+ id: params.userId,
204
+ badges: JSON.parse(params.badges),
205
+ })
206
+ .select();
207
+ break;
194
208
  }
195
209
 
196
210
  // Log the admin action
@@ -0,0 +1,50 @@
1
+ import { NextResponse } from "next/server";
2
+ import z from "zod";
3
+ import { protectedApi, validUser } from "../utils/requestUtils";
4
+ import { supabase } from "../utils/supabase";
5
+ import { User } from "@supabase/supabase-js";
6
+ import { getUserBySession } from "../utils/getUserBySession";
7
+
8
+ export const Schema = {
9
+ input: z.strictObject({
10
+ session: z.string(),
11
+ }),
12
+ output: z.strictObject({
13
+ error: z.string().optional(),
14
+ inventory: z.any().optional(),
15
+ }),
16
+ };
17
+
18
+ export async function POST(request: Request): Promise<NextResponse> {
19
+ return protectedApi({
20
+ request,
21
+ schema: Schema,
22
+ authorization: () => {},
23
+ activity: handler,
24
+ });
25
+ }
26
+
27
+ export async function handler(
28
+ data: (typeof Schema)["input"]["_type"]
29
+ ): Promise<NextResponse<(typeof Schema)["output"]["_type"]>> {
30
+ const user = (await getUserBySession(data.session)) as User;
31
+ let { data: queryData, error } = await supabase
32
+ .from("profiles")
33
+ .select("*")
34
+ .eq("uid", user.id)
35
+ .single();
36
+ if (!queryData) {
37
+ return NextResponse.json({ error: "Can't retrieve user inventory" });
38
+ }
39
+
40
+ let { data: inventoryData, error: inventoryError } = await supabase
41
+ .from("inventories")
42
+ .select("*")
43
+ .eq("id", queryData.id)
44
+ .single();
45
+
46
+ if (!queryData) {
47
+ NextResponse.json({});
48
+ }
49
+ return NextResponse.json({ inventory: inventoryData });
50
+ }
package/index.ts CHANGED
@@ -735,6 +735,22 @@ import { Schema as GetCollections } from "./api/getCollections"
735
735
  export { Schema as SchemaGetCollections } from "./api/getCollections"
736
736
  export const getCollections = handleApi({url:"/api/getCollections",...GetCollections})
737
737
 
738
+ // ./api/getInventory.ts API
739
+
740
+ /*
741
+ export const Schema = {
742
+ input: z.strictObject({
743
+ session: z.string(),
744
+ }),
745
+ output: z.strictObject({
746
+ error: z.string().optional(),
747
+ inventory: z.any().optional(),
748
+ }),
749
+ };*/
750
+ import { Schema as GetInventory } from "./api/getInventory"
751
+ export { Schema as SchemaGetInventory } from "./api/getInventory"
752
+ export const getInventory = handleApi({url:"/api/getInventory",...GetInventory})
753
+
738
754
  // ./api/getLeaderboard.ts API
739
755
 
740
756
  /*
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rhythia-api",
3
- "version": "201.0.0",
3
+ "version": "202.0.0",
4
4
  "main": "index.ts",
5
5
  "author": "online-contributors-cunev",
6
6
  "scripts": {
package/types/database.ts CHANGED
@@ -363,6 +363,29 @@ export type Database = {
363
363
  }
364
364
  Relationships: []
365
365
  }
366
+ inventories: {
367
+ Row: {
368
+ contents: Json
369
+ id: number
370
+ }
371
+ Insert: {
372
+ contents?: Json
373
+ id?: number
374
+ }
375
+ Update: {
376
+ contents?: Json
377
+ id?: number
378
+ }
379
+ Relationships: [
380
+ {
381
+ foreignKeyName: "inventory_id_fkey"
382
+ columns: ["id"]
383
+ isOneToOne: true
384
+ referencedRelation: "profiles"
385
+ referencedColumns: ["id"]
386
+ },
387
+ ]
388
+ }
366
389
  invites: {
367
390
  Row: {
368
391
  code: string