rhythia-api 177.0.0 → 178.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.
@@ -37,6 +37,11 @@ export async function handler(data: (typeof Schema)["input"]["_type"]) {
37
37
  return NextResponse.json({ error: "Can't find user" });
38
38
  }
39
39
 
40
+ if (data.title.length < 3) {
41
+ return NextResponse.json({
42
+ error: "Collection title should be longer than 3",
43
+ });
44
+ }
40
45
  const inserted = await supabase
41
46
  .from("beatmapCollections")
42
47
  .insert({
@@ -0,0 +1,55 @@
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
+ }),
13
+ output: z.object({
14
+ error: z.string().optional(),
15
+ }),
16
+ };
17
+
18
+ export async function POST(request: Request) {
19
+ return protectedApi({
20
+ request,
21
+ schema: Schema,
22
+ authorization: validUser,
23
+ activity: handler,
24
+ });
25
+ }
26
+
27
+ export async function handler(data: (typeof Schema)["input"]["_type"]) {
28
+ const user = (await getUserBySession(data.session)) as User;
29
+ let { data: queryUserData, error: userError } = await supabase
30
+ .from("profiles")
31
+ .select("*")
32
+ .eq("uid", user.id)
33
+ .single();
34
+
35
+ if (!queryUserData) {
36
+ return NextResponse.json({ error: "Can't find user" });
37
+ }
38
+
39
+ let { data: queryCollectionData, error: collectionError } = await supabase
40
+ .from("beatmapCollections")
41
+ .select("*")
42
+ .eq("id", data.collection)
43
+ .single();
44
+
45
+ if (!queryCollectionData) {
46
+ return NextResponse.json({ error: "Can't find collection" });
47
+ }
48
+
49
+ if (queryCollectionData.owner !== queryUserData.id) {
50
+ return NextResponse.json({ error: "You can't update foreign collections" });
51
+ }
52
+
53
+ await supabase.from("beatmapCollections").delete().eq("id", data.collection);
54
+ return NextResponse.json({});
55
+ }
@@ -0,0 +1,69 @@
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
+ import { describe } from "node:test";
8
+
9
+ export const Schema = {
10
+ input: z.strictObject({
11
+ session: z.string(),
12
+ collection: z.number(),
13
+ title: z.string(),
14
+ description: z.string(),
15
+ }),
16
+ output: z.object({
17
+ error: z.string().optional(),
18
+ }),
19
+ };
20
+
21
+ export async function POST(request: Request) {
22
+ return protectedApi({
23
+ request,
24
+ schema: Schema,
25
+ authorization: validUser,
26
+ activity: handler,
27
+ });
28
+ }
29
+
30
+ export async function handler(data: (typeof Schema)["input"]["_type"]) {
31
+ const user = (await getUserBySession(data.session)) as User;
32
+ let { data: queryUserData, error: userError } = await supabase
33
+ .from("profiles")
34
+ .select("*")
35
+ .eq("uid", user.id)
36
+ .single();
37
+
38
+ if (!queryUserData) {
39
+ return NextResponse.json({ error: "Can't find user" });
40
+ }
41
+
42
+ let { data: queryCollectionData, error: collectionError } = await supabase
43
+ .from("beatmapCollections")
44
+ .select("*")
45
+ .eq("id", data.collection)
46
+ .single();
47
+
48
+ if (!queryCollectionData) {
49
+ return NextResponse.json({ error: "Can't find collection" });
50
+ }
51
+
52
+ if (queryCollectionData.owner !== queryUserData.id) {
53
+ return NextResponse.json({ error: "You can't update foreign collections" });
54
+ }
55
+
56
+ if (data.title.length < 3) {
57
+ return NextResponse.json({
58
+ error: "Collection title should be longer than 3",
59
+ });
60
+ }
61
+
62
+ await supabase.from("beatmapCollections").upsert({
63
+ id: data.collection,
64
+ title: data.title,
65
+ description: data.description,
66
+ owner: queryUserData.id,
67
+ });
68
+ return NextResponse.json({});
69
+ }
package/index.ts CHANGED
@@ -128,6 +128,22 @@ import { Schema as DeleteBeatmapPage } from "./api/deleteBeatmapPage"
128
128
  export { Schema as SchemaDeleteBeatmapPage } from "./api/deleteBeatmapPage"
129
129
  export const deleteBeatmapPage = handleApi({url:"/api/deleteBeatmapPage",...DeleteBeatmapPage})
130
130
 
131
+ // ./api/deleteCollection.ts API
132
+
133
+ /*
134
+ export const Schema = {
135
+ input: z.strictObject({
136
+ session: z.string(),
137
+ collection: z.number(),
138
+ }),
139
+ output: z.object({
140
+ error: z.string().optional(),
141
+ }),
142
+ };*/
143
+ import { Schema as DeleteCollection } from "./api/deleteCollection"
144
+ export { Schema as SchemaDeleteCollection } from "./api/deleteCollection"
145
+ export const deleteCollection = handleApi({url:"/api/deleteCollection",...DeleteCollection})
146
+
131
147
  // ./api/editAboutMe.ts API
132
148
 
133
149
  /*
@@ -166,6 +182,24 @@ import { Schema as EditClan } from "./api/editClan"
166
182
  export { Schema as SchemaEditClan } from "./api/editClan"
167
183
  export const editClan = handleApi({url:"/api/editClan",...EditClan})
168
184
 
185
+ // ./api/editCollection.ts API
186
+
187
+ /*
188
+ export const Schema = {
189
+ input: z.strictObject({
190
+ session: z.string(),
191
+ collection: z.number(),
192
+ title: z.string(),
193
+ description: z.string(),
194
+ }),
195
+ output: z.object({
196
+ error: z.string().optional(),
197
+ }),
198
+ };*/
199
+ import { Schema as EditCollection } from "./api/editCollection"
200
+ export { Schema as SchemaEditCollection } from "./api/editCollection"
201
+ export const editCollection = handleApi({url:"/api/editCollection",...EditCollection})
202
+
169
203
  // ./api/editProfile.ts API
170
204
 
171
205
  /*
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rhythia-api",
3
- "version": "177.0.0",
3
+ "version": "178.0.0",
4
4
  "main": "index.ts",
5
5
  "author": "online-contributors",
6
6
  "scripts": {