rhythia-api 178.0.0 → 179.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.
@@ -61,6 +61,7 @@ export async function handler({
61
61
  return NextResponse.json({ error: "Only unranked maps can be updated" });
62
62
 
63
63
  await supabase.from("beatmapPageComments").delete().eq("beatmapPage", id);
64
+ await supabase.from("collectionRelations").delete().eq("beatmapPage", id);
64
65
  await supabase.from("beatmapPages").delete().eq("id", id);
65
66
  await supabase
66
67
  .from("beatmaps")
@@ -51,5 +51,9 @@ export async function handler(data: (typeof Schema)["input"]["_type"]) {
51
51
  }
52
52
 
53
53
  await supabase.from("beatmapCollections").delete().eq("id", data.collection);
54
+ await supabase
55
+ .from("collectionRelations")
56
+ .delete()
57
+ .eq("collection", data.collection);
54
58
  return NextResponse.json({});
55
59
  }
@@ -0,0 +1,71 @@
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 { getUserBySession } from "../utils/getUserBySession";
6
+ import { User } from "@supabase/supabase-js";
7
+
8
+ export const Schema = {
9
+ input: z.strictObject({
10
+ session: z.string(),
11
+ collection: z.number(),
12
+ beatmapPage: z.number(),
13
+ }),
14
+ output: z.object({
15
+ error: z.string().optional(),
16
+ }),
17
+ };
18
+
19
+ export async function POST(request: Request) {
20
+ return protectedApi({
21
+ request,
22
+ schema: Schema,
23
+ authorization: validUser,
24
+ activity: handler,
25
+ });
26
+ }
27
+
28
+ export async function handler(data: (typeof Schema)["input"]["_type"]) {
29
+ const user = (await getUserBySession(data.session)) as User;
30
+ let { data: queryUserData, error: userError } = await supabase
31
+ .from("profiles")
32
+ .select("*")
33
+ .eq("uid", user.id)
34
+ .single();
35
+
36
+ if (!queryUserData) {
37
+ return NextResponse.json({ error: "Can't find user" });
38
+ }
39
+
40
+ let { data: queryCollectionData, error: collectionError } = await supabase
41
+ .from("beatmapCollections")
42
+ .select("*")
43
+ .eq("id", data.collection)
44
+ .single();
45
+
46
+ let { data: queryBeatmapData, error: beatmapData } = await supabase
47
+ .from("beatmapPages")
48
+ .select("*")
49
+ .eq("id", data.beatmapPage)
50
+ .single();
51
+
52
+ if (!queryCollectionData) {
53
+ return NextResponse.json({ error: "Can't find collection" });
54
+ }
55
+
56
+ if (!queryBeatmapData) {
57
+ return NextResponse.json({ error: "Can't find beatmap page" });
58
+ }
59
+
60
+ if (queryCollectionData.owner !== queryUserData.id) {
61
+ return NextResponse.json({ error: "You can't update foreign collections" });
62
+ }
63
+
64
+ await supabase
65
+ .from("collectionRelations")
66
+ .delete()
67
+ .eq("beatmapPage", data.beatmapPage)
68
+ .eq("collection", data.collection);
69
+
70
+ return NextResponse.json({});
71
+ }
package/index.ts CHANGED
@@ -144,6 +144,23 @@ import { Schema as DeleteCollection } from "./api/deleteCollection"
144
144
  export { Schema as SchemaDeleteCollection } from "./api/deleteCollection"
145
145
  export const deleteCollection = handleApi({url:"/api/deleteCollection",...DeleteCollection})
146
146
 
147
+ // ./api/deleteCollectionMap.ts API
148
+
149
+ /*
150
+ export const Schema = {
151
+ input: z.strictObject({
152
+ session: z.string(),
153
+ collection: z.number(),
154
+ beatmapPage: z.number(),
155
+ }),
156
+ output: z.object({
157
+ error: z.string().optional(),
158
+ }),
159
+ };*/
160
+ import { Schema as DeleteCollectionMap } from "./api/deleteCollectionMap"
161
+ export { Schema as SchemaDeleteCollectionMap } from "./api/deleteCollectionMap"
162
+ export const deleteCollectionMap = handleApi({url:"/api/deleteCollectionMap",...DeleteCollectionMap})
163
+
147
164
  // ./api/editAboutMe.ts API
148
165
 
149
166
  /*
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rhythia-api",
3
- "version": "178.0.0",
3
+ "version": "179.0.0",
4
4
  "main": "index.ts",
5
5
  "author": "online-contributors",
6
6
  "scripts": {