rhythia-api 200.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.
- package/api/acceptInvite.ts +1 -49
- package/api/executeAdminOperation.ts +29 -0
- package/api/getInventory.ts +50 -0
- package/index.ts +16 -0
- package/package.json +1 -1
- package/types/database.ts +23 -0
package/api/acceptInvite.ts
CHANGED
|
@@ -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
|
-
|
|
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
|
}
|
|
@@ -9,6 +9,8 @@ import { User } from "@supabase/supabase-js";
|
|
|
9
9
|
// Define supported admin operations and their parameter types
|
|
10
10
|
const adminOperations = {
|
|
11
11
|
deleteUser: z.object({ userId: z.number() }),
|
|
12
|
+
changeFlag: z.object({ userId: z.number(), flag: z.string() }),
|
|
13
|
+
changeBadges: z.object({ userId: z.number(), badges: z.string() }),
|
|
12
14
|
excludeUser: z.object({ userId: z.number() }),
|
|
13
15
|
restrictUser: z.object({ userId: z.number() }),
|
|
14
16
|
silenceUser: z.object({ userId: z.number() }),
|
|
@@ -57,6 +59,14 @@ const OperationParam = z.discriminatedUnion("operation", [
|
|
|
57
59
|
operation: z.literal("unbanUser"),
|
|
58
60
|
params: adminOperations.unbanUser,
|
|
59
61
|
}),
|
|
62
|
+
z.object({
|
|
63
|
+
operation: z.literal("changeFlag"),
|
|
64
|
+
params: adminOperations.changeFlag,
|
|
65
|
+
}),
|
|
66
|
+
z.object({
|
|
67
|
+
operation: z.literal("changeBadges"),
|
|
68
|
+
params: adminOperations.changeBadges,
|
|
69
|
+
}),
|
|
60
70
|
]);
|
|
61
71
|
|
|
62
72
|
export const Schema = {
|
|
@@ -176,6 +186,25 @@ export async function handler(
|
|
|
176
186
|
user_id: params.userId,
|
|
177
187
|
});
|
|
178
188
|
break;
|
|
189
|
+
|
|
190
|
+
case "changeFlag":
|
|
191
|
+
result = await supabase
|
|
192
|
+
.from("profiles")
|
|
193
|
+
.upsert({
|
|
194
|
+
id: params.userId,
|
|
195
|
+
flag: params.flag,
|
|
196
|
+
})
|
|
197
|
+
.select();
|
|
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;
|
|
179
208
|
}
|
|
180
209
|
|
|
181
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
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
|