rhythia-api 121.0.0 → 123.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/approveMap.ts +65 -0
- package/api/nominateMap.ts +63 -0
- package/index.ts +10 -0
- package/package.json +1 -1
- package/types/database.ts +3 -0
|
@@ -0,0 +1,65 @@
|
|
|
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
|
+
|
|
6
|
+
export const Schema = {
|
|
7
|
+
input: z.strictObject({
|
|
8
|
+
session: z.string(),
|
|
9
|
+
mapId: z.number(),
|
|
10
|
+
}),
|
|
11
|
+
output: z.object({
|
|
12
|
+
error: z.string().optional(),
|
|
13
|
+
}),
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export async function POST(request: Request) {
|
|
17
|
+
return protectedApi({
|
|
18
|
+
request,
|
|
19
|
+
schema: Schema,
|
|
20
|
+
authorization: validUser,
|
|
21
|
+
activity: handler,
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export async function handler(data: (typeof Schema)["input"]["_type"]) {
|
|
26
|
+
const user = (await supabase.auth.getUser(data.session)).data.user!;
|
|
27
|
+
let { data: queryUserData, error: userError } = await supabase
|
|
28
|
+
.from("profiles")
|
|
29
|
+
.select("*")
|
|
30
|
+
.eq("uid", user.id)
|
|
31
|
+
.single();
|
|
32
|
+
|
|
33
|
+
if (!queryUserData) {
|
|
34
|
+
return NextResponse.json({ error: "Can't find user" });
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const tags = (queryUserData?.badges || []) as string[];
|
|
38
|
+
|
|
39
|
+
if (!tags.includes("MMT")) {
|
|
40
|
+
return NextResponse.json({ error: "Only MMTs can approve maps!" });
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const { data: mapData, error } = await supabase
|
|
44
|
+
.from("beatmapPages")
|
|
45
|
+
.select("id,nominations")
|
|
46
|
+
.eq("id", data.mapId)
|
|
47
|
+
.single();
|
|
48
|
+
|
|
49
|
+
if (!mapData) {
|
|
50
|
+
return NextResponse.json({ error: "Bad map" });
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if ((mapData.nominations as number[])!.length < 2) {
|
|
54
|
+
return NextResponse.json({
|
|
55
|
+
error: "Maps can get approved only if they have 2 approvals",
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
await supabase.from("beatmapPages").upsert({
|
|
60
|
+
id: data.mapId,
|
|
61
|
+
status: "RANKED",
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
return NextResponse.json({});
|
|
65
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
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
|
+
|
|
6
|
+
export const Schema = {
|
|
7
|
+
input: z.strictObject({
|
|
8
|
+
session: z.string(),
|
|
9
|
+
mapId: z.number(),
|
|
10
|
+
}),
|
|
11
|
+
output: z.object({
|
|
12
|
+
error: z.string().optional(),
|
|
13
|
+
}),
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export async function POST(request: Request) {
|
|
17
|
+
return protectedApi({
|
|
18
|
+
request,
|
|
19
|
+
schema: Schema,
|
|
20
|
+
authorization: validUser,
|
|
21
|
+
activity: handler,
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export async function handler(data: (typeof Schema)["input"]["_type"]) {
|
|
26
|
+
const user = (await supabase.auth.getUser(data.session)).data.user!;
|
|
27
|
+
let { data: queryUserData, error: userError } = await supabase
|
|
28
|
+
.from("profiles")
|
|
29
|
+
.select("*")
|
|
30
|
+
.eq("uid", user.id)
|
|
31
|
+
.single();
|
|
32
|
+
|
|
33
|
+
if (!queryUserData) {
|
|
34
|
+
return NextResponse.json({ error: "Can't find user" });
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const tags = (queryUserData?.badges || []) as string[];
|
|
38
|
+
|
|
39
|
+
if (!tags.includes("RCT")) {
|
|
40
|
+
return NextResponse.json({ error: "Only RCTs can nominate maps!" });
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const { data: mapData, error } = await supabase
|
|
44
|
+
.from("beatmapPages")
|
|
45
|
+
.select("id,nominations")
|
|
46
|
+
.eq("id", data.mapId)
|
|
47
|
+
.single();
|
|
48
|
+
|
|
49
|
+
if (!mapData) {
|
|
50
|
+
return NextResponse.json({ error: "Bad map" });
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if ((mapData.nominations as number[]).includes(queryUserData.id)) {
|
|
54
|
+
return NextResponse.json({ error: "Already nominated" });
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
await supabase.from("beatmapPages").upsert({
|
|
58
|
+
id: data.mapId,
|
|
59
|
+
nominations: [...(mapData.nominations! as number[]), queryUserData.id],
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
return NextResponse.json({});
|
|
63
|
+
}
|
package/index.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import { handleApi } from "./handleApi"
|
|
2
2
|
|
|
3
|
+
// ./api/approveMap.ts API
|
|
4
|
+
import { Schema as ApproveMap } from "./api/approveMap"
|
|
5
|
+
export { Schema as SchemaApproveMap } from "./api/approveMap"
|
|
6
|
+
export const approveMap = handleApi({url:"/api/approveMap",...ApproveMap})
|
|
7
|
+
|
|
3
8
|
// ./api/createBeatmap.ts API
|
|
4
9
|
import { Schema as CreateBeatmap } from "./api/createBeatmap"
|
|
5
10
|
export { Schema as SchemaCreateBeatmap } from "./api/createBeatmap"
|
|
@@ -65,6 +70,11 @@ import { Schema as GetUserScores } from "./api/getUserScores"
|
|
|
65
70
|
export { Schema as SchemaGetUserScores } from "./api/getUserScores"
|
|
66
71
|
export const getUserScores = handleApi({url:"/api/getUserScores",...GetUserScores})
|
|
67
72
|
|
|
73
|
+
// ./api/nominateMap.ts API
|
|
74
|
+
import { Schema as NominateMap } from "./api/nominateMap"
|
|
75
|
+
export { Schema as SchemaNominateMap } from "./api/nominateMap"
|
|
76
|
+
export const nominateMap = handleApi({url:"/api/nominateMap",...NominateMap})
|
|
77
|
+
|
|
68
78
|
// ./api/searchUsers.ts API
|
|
69
79
|
import { Schema as SearchUsers } from "./api/searchUsers"
|
|
70
80
|
export { Schema as SchemaSearchUsers } from "./api/searchUsers"
|
package/package.json
CHANGED
package/types/database.ts
CHANGED
|
@@ -15,6 +15,7 @@ export type Database = {
|
|
|
15
15
|
genre: string | null
|
|
16
16
|
id: number
|
|
17
17
|
latestBeatmapHash: string | null
|
|
18
|
+
nominations: Json | null
|
|
18
19
|
owner: number | null
|
|
19
20
|
status: string | null
|
|
20
21
|
title: string | null
|
|
@@ -24,6 +25,7 @@ export type Database = {
|
|
|
24
25
|
genre?: string | null
|
|
25
26
|
id?: number
|
|
26
27
|
latestBeatmapHash?: string | null
|
|
28
|
+
nominations?: Json | null
|
|
27
29
|
owner?: number | null
|
|
28
30
|
status?: string | null
|
|
29
31
|
title?: string | null
|
|
@@ -33,6 +35,7 @@ export type Database = {
|
|
|
33
35
|
genre?: string | null
|
|
34
36
|
id?: number
|
|
35
37
|
latestBeatmapHash?: string | null
|
|
38
|
+
nominations?: Json | null
|
|
36
39
|
owner?: number | null
|
|
37
40
|
status?: string | null
|
|
38
41
|
title?: string | null
|