rhythia-api 63.0.0 → 65.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/getProfile.ts +49 -0
- package/index.ts +8 -8
- package/package.json +1 -1
- package/utils/supabase.ts +13 -0
- package/api/getUser.ts +0 -60
- /package/api/{editUser.ts → editProfile.ts} +0 -0
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import z from "zod";
|
|
2
|
+
import { supabase } from "../utils/supabase";
|
|
3
|
+
|
|
4
|
+
export const Schema = {
|
|
5
|
+
input: z.object({
|
|
6
|
+
id: z.string(),
|
|
7
|
+
}),
|
|
8
|
+
output: z.object({
|
|
9
|
+
error: z.string().optional(),
|
|
10
|
+
user: z
|
|
11
|
+
.object({
|
|
12
|
+
about_me: z.string().nullable(),
|
|
13
|
+
avatar_url: z.string().nullable(),
|
|
14
|
+
badges: z.any().nullable(),
|
|
15
|
+
created_at: z.number().nullable(),
|
|
16
|
+
flag: z.string().nullable(),
|
|
17
|
+
id: z.number(),
|
|
18
|
+
uid: z.string().nullable(),
|
|
19
|
+
username: z.string().nullable(),
|
|
20
|
+
verified: z.boolean().nullable(),
|
|
21
|
+
})
|
|
22
|
+
.optional(),
|
|
23
|
+
}),
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export async function GET(
|
|
27
|
+
res: Response
|
|
28
|
+
): Promise<(typeof Schema)["output"]["_type"]> {
|
|
29
|
+
const toParse = await res.json();
|
|
30
|
+
const data = Schema.input.parse(toParse);
|
|
31
|
+
|
|
32
|
+
let { data: profiles, error } = await supabase
|
|
33
|
+
.from("profiles")
|
|
34
|
+
.select("*")
|
|
35
|
+
.eq("column", data.id);
|
|
36
|
+
|
|
37
|
+
if (!profiles?.length) {
|
|
38
|
+
return {
|
|
39
|
+
error: "User not found",
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const user = profiles[0];
|
|
44
|
+
return {
|
|
45
|
+
user: {
|
|
46
|
+
...user,
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
}
|
package/index.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { handleApi } from "./handleApi"
|
|
2
2
|
|
|
3
|
-
// ./api/
|
|
4
|
-
import { Schema as
|
|
5
|
-
export { Schema as
|
|
6
|
-
export const
|
|
3
|
+
// ./api/editProfile.ts API
|
|
4
|
+
import { Schema as EditProfile } from "./api/editProfile"
|
|
5
|
+
export { Schema as SchemaEditProfile } from "./api/editProfile"
|
|
6
|
+
export const editProfile = handleApi({url:"/api/editProfile",...EditProfile})
|
|
7
7
|
|
|
8
|
-
// ./api/
|
|
9
|
-
import { Schema as
|
|
10
|
-
export { Schema as
|
|
11
|
-
export const
|
|
8
|
+
// ./api/getProfile.ts API
|
|
9
|
+
import { Schema as GetProfile } from "./api/getProfile"
|
|
10
|
+
export { Schema as SchemaGetProfile } from "./api/getProfile"
|
|
11
|
+
export const getProfile = handleApi({url:"/api/getProfile",...GetProfile})
|
|
12
12
|
export { handleApi } from "./handleApi"
|
package/package.json
CHANGED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { createClient } from "@supabase/supabase-js";
|
|
2
|
+
import { Database } from "../types/supabase";
|
|
3
|
+
|
|
4
|
+
export const supabase = createClient<Database>(
|
|
5
|
+
`https://pfkajngbllcbdzoylrvp.supabase.co`,
|
|
6
|
+
process.env.ADMIN_KEY!,
|
|
7
|
+
{
|
|
8
|
+
auth: {
|
|
9
|
+
autoRefreshToken: false,
|
|
10
|
+
persistSession: false,
|
|
11
|
+
},
|
|
12
|
+
}
|
|
13
|
+
);
|
package/api/getUser.ts
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { createClient } from "@supabase/supabase-js";
|
|
2
|
-
import z from "zod";
|
|
3
|
-
import { Database } from "../types/supabase";
|
|
4
|
-
|
|
5
|
-
export const Schema = {
|
|
6
|
-
input: z.object({
|
|
7
|
-
id: z.string(),
|
|
8
|
-
}),
|
|
9
|
-
output: z
|
|
10
|
-
.object({
|
|
11
|
-
about_me: z.string().nullable(),
|
|
12
|
-
avatar_url: z.string().nullable(),
|
|
13
|
-
badges: z.any().nullable(),
|
|
14
|
-
created_at: z.number().nullable(),
|
|
15
|
-
flag: z.string().nullable(),
|
|
16
|
-
id: z.number(),
|
|
17
|
-
uid: z.string().nullable(),
|
|
18
|
-
username: z.string().nullable(),
|
|
19
|
-
verified: z.boolean().nullable(),
|
|
20
|
-
})
|
|
21
|
-
.or(
|
|
22
|
-
z.object({
|
|
23
|
-
error: z.string(),
|
|
24
|
-
})
|
|
25
|
-
),
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
const supabase = createClient<Database>(
|
|
29
|
-
`https://pfkajngbllcbdzoylrvp.supabase.co`,
|
|
30
|
-
process.env.ADMIN_KEY!,
|
|
31
|
-
{
|
|
32
|
-
auth: {
|
|
33
|
-
autoRefreshToken: false,
|
|
34
|
-
persistSession: false,
|
|
35
|
-
},
|
|
36
|
-
}
|
|
37
|
-
);
|
|
38
|
-
|
|
39
|
-
export async function GET(
|
|
40
|
-
res: Response
|
|
41
|
-
): Promise<(typeof Schema)["output"]["_type"]> {
|
|
42
|
-
const toParse = await res.json();
|
|
43
|
-
const data = Schema.input.parse(toParse);
|
|
44
|
-
|
|
45
|
-
let { data: profiles, error } = await supabase
|
|
46
|
-
.from("profiles")
|
|
47
|
-
.select("*")
|
|
48
|
-
.eq("column", data.id);
|
|
49
|
-
|
|
50
|
-
if (!profiles?.length) {
|
|
51
|
-
return {
|
|
52
|
-
error: "User not found",
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
const user = profiles[0];
|
|
57
|
-
return {
|
|
58
|
-
...user,
|
|
59
|
-
};
|
|
60
|
-
}
|
|
File without changes
|