rhythia-api 78.0.0 → 79.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/editProfile.ts +1 -1
- package/api/getLeaderboard.ts +1 -1
- package/api/getProfile.ts +17 -9
- package/api/searchUsers.ts +46 -0
- package/index.ts +5 -0
- package/package.json +1 -1
- package/api/webhook_createUser.ts +0 -37
- package/scripts/test.ts +0 -10
package/api/editProfile.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { protectedApi, validUser } from "../utils/requestUtils";
|
|
|
5
5
|
import { supabase } from "../utils/supabase";
|
|
6
6
|
|
|
7
7
|
export const Schema = {
|
|
8
|
-
input: z.
|
|
8
|
+
input: z.strictObject({
|
|
9
9
|
session: z.string(),
|
|
10
10
|
data: z.object({
|
|
11
11
|
avatar_url: z.string().optional(),
|
package/api/getLeaderboard.ts
CHANGED
package/api/getProfile.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { protectedApi, validUser } from "../utils/requestUtils";
|
|
|
5
5
|
import { supabase } from "../utils/supabase";
|
|
6
6
|
|
|
7
7
|
export const Schema = {
|
|
8
|
-
input: z.
|
|
8
|
+
input: z.strictObject({
|
|
9
9
|
session: z.string(),
|
|
10
10
|
id: z.number().optional(),
|
|
11
11
|
}),
|
|
@@ -75,16 +75,24 @@ export async function handler(
|
|
|
75
75
|
.eq("uid", user.id);
|
|
76
76
|
|
|
77
77
|
console.log(profiles, error);
|
|
78
|
-
|
|
79
78
|
if (!queryData?.length) {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
79
|
+
const data = await supabase
|
|
80
|
+
.from("profiles")
|
|
81
|
+
.upsert({
|
|
82
|
+
uid: user.id,
|
|
83
|
+
about_me: "",
|
|
84
|
+
avatar_url: user.user_metadata.avatar_url,
|
|
85
|
+
badges: ["Early Bird"],
|
|
86
|
+
username: user.user_metadata.full_name,
|
|
87
|
+
flag: "",
|
|
88
|
+
created_at: Date.now(),
|
|
89
|
+
})
|
|
90
|
+
.select();
|
|
91
|
+
|
|
92
|
+
profiles = data.data!;
|
|
93
|
+
} else {
|
|
94
|
+
profiles = queryData;
|
|
86
95
|
}
|
|
87
|
-
profiles = queryData;
|
|
88
96
|
}
|
|
89
97
|
|
|
90
98
|
const user = profiles[0];
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { NextResponse } from "next/server";
|
|
2
|
+
import z from "zod";
|
|
3
|
+
import { protectedApi } from "../utils/requestUtils";
|
|
4
|
+
import { supabase } from "../utils/supabase";
|
|
5
|
+
|
|
6
|
+
export const Schema = {
|
|
7
|
+
input: z.strictObject({
|
|
8
|
+
text: z.string(),
|
|
9
|
+
}),
|
|
10
|
+
output: z.object({
|
|
11
|
+
error: z.string().optional(),
|
|
12
|
+
results: z
|
|
13
|
+
.array(
|
|
14
|
+
z.object({
|
|
15
|
+
id: z.number(),
|
|
16
|
+
username: z.string().nullable(),
|
|
17
|
+
})
|
|
18
|
+
)
|
|
19
|
+
.optional(),
|
|
20
|
+
}),
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export async function POST(res: Response): Promise<NextResponse> {
|
|
24
|
+
return protectedApi({
|
|
25
|
+
response: res,
|
|
26
|
+
schema: Schema,
|
|
27
|
+
authorization: () => {},
|
|
28
|
+
activity: handler,
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export async function handler(
|
|
33
|
+
data: (typeof Schema)["input"]["_type"]
|
|
34
|
+
): Promise<NextResponse<(typeof Schema)["output"]["_type"]>> {
|
|
35
|
+
const { data: searchData, error } = await supabase
|
|
36
|
+
.from("profiles")
|
|
37
|
+
.select()
|
|
38
|
+
.ilike("username", `%${data.text}%`)
|
|
39
|
+
.limit(10);
|
|
40
|
+
return NextResponse.json({
|
|
41
|
+
results: (searchData || []).map((data) => ({
|
|
42
|
+
id: data.id,
|
|
43
|
+
username: data.username,
|
|
44
|
+
})),
|
|
45
|
+
});
|
|
46
|
+
}
|
package/index.ts
CHANGED
|
@@ -14,4 +14,9 @@ export const getLeaderboard = handleApi({url:"/api/getLeaderboard",...GetLeaderb
|
|
|
14
14
|
import { Schema as GetProfile } from "./api/getProfile"
|
|
15
15
|
export { Schema as SchemaGetProfile } from "./api/getProfile"
|
|
16
16
|
export const getProfile = handleApi({url:"/api/getProfile",...GetProfile})
|
|
17
|
+
|
|
18
|
+
// ./api/searchUsers.ts API
|
|
19
|
+
import { Schema as SearchUsers } from "./api/searchUsers"
|
|
20
|
+
export { Schema as SchemaSearchUsers } from "./api/searchUsers"
|
|
21
|
+
export const searchUsers = handleApi({url:"/api/searchUsers",...SearchUsers})
|
|
17
22
|
export { handleApi } from "./handleApi"
|
package/package.json
CHANGED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { createClient } from "@supabase/supabase-js";
|
|
2
|
-
import { Database } from "../types/database";
|
|
3
|
-
|
|
4
|
-
const adminClient = createClient<Database>(
|
|
5
|
-
`https://pfkajngbllcbdzoylrvp.supabase.co`,
|
|
6
|
-
process.env.ADMIN_KEY!,
|
|
7
|
-
{
|
|
8
|
-
auth: {
|
|
9
|
-
autoRefreshToken: false,
|
|
10
|
-
persistSession: false,
|
|
11
|
-
},
|
|
12
|
-
}
|
|
13
|
-
);
|
|
14
|
-
|
|
15
|
-
export async function POST(request: Request) {
|
|
16
|
-
const payload: any = await request.json();
|
|
17
|
-
|
|
18
|
-
if (payload.type !== "INSERT") return new Response(`not today`);
|
|
19
|
-
console.log("Inserting...");
|
|
20
|
-
const metadata = payload.record.raw_user_meta_data;
|
|
21
|
-
|
|
22
|
-
const data = await adminClient
|
|
23
|
-
.from("profiles")
|
|
24
|
-
.upsert({
|
|
25
|
-
uid: payload.record.id,
|
|
26
|
-
about_me: "",
|
|
27
|
-
avatar_url: metadata.avatar_url,
|
|
28
|
-
badges: ["Early Bird"],
|
|
29
|
-
username: metadata.full_name,
|
|
30
|
-
flag: "",
|
|
31
|
-
created_at: Date.now(),
|
|
32
|
-
})
|
|
33
|
-
.select();
|
|
34
|
-
|
|
35
|
-
console.log(data);
|
|
36
|
-
return new Response(`good one`);
|
|
37
|
-
}
|
package/scripts/test.ts
DELETED