mighttguy commited on
Commit
d2dda46
·
1 Parent(s): 5eff0b7

ft. friends route and endpoints implemented. cache strategy in process.

Browse files
Files changed (25) hide show
  1. chess-frontend/actions/friend.ts +65 -0
  2. chess-frontend/app/(protected)/community/_components/blocked-tab.tsx +2 -2
  3. chess-frontend/app/(protected)/community/_components/community-client.tsx +1 -0
  4. chess-frontend/app/(protected)/community/_components/community-shared.tsx +2 -101
  5. chess-frontend/app/(protected)/community/_components/find-players-tab.tsx +29 -4
  6. chess-frontend/app/(protected)/community/_components/friends-tab.tsx +11 -11
  7. chess-frontend/app/(protected)/community/_components/icon-btn.tsx +66 -0
  8. chess-frontend/app/(protected)/community/_components/player-card.tsx +62 -0
  9. chess-frontend/app/(protected)/community/_components/requests-tab.tsx +19 -26
  10. chess-frontend/app/(protected)/community/_components/search-users-form.tsx +5 -1
  11. chess-frontend/app/(protected)/community/page.tsx +0 -1
  12. chess-frontend/package.json +4 -1
  13. chess-monolith/drizzle/0004_nasty_gorilla_man.sql +1 -0
  14. chess-monolith/drizzle/0005_create_pg_trgm_extension.sql +1 -0
  15. chess-monolith/drizzle/meta/0004_snapshot.json +921 -0
  16. chess-monolith/drizzle/meta/0005_snapshot.json +921 -0
  17. chess-monolith/drizzle/meta/_journal.json +14 -0
  18. chess-monolith/package.json +4 -1
  19. chess-monolith/src/api/controller/friend-controller.ts +3 -4
  20. chess-monolith/src/api/repository/friend-repository.ts +3 -3
  21. chess-monolith/src/api/routes/friend-router.ts +3 -3
  22. chess-monolith/src/infrastructure/db/schema.ts +0 -2
  23. chess-monolith/src/lib/auth.ts +12 -16
  24. chess-monolith/src/seed/setup.ts +17 -0
  25. package.json +0 -12
chess-frontend/actions/friend.ts CHANGED
@@ -1,7 +1,9 @@
1
  "use server";
2
 
 
3
  import { safeFetch } from "@/lib/constants/safe-fetch";
4
  import { GetFriend, SearchFriend } from "@/types/friends";
 
5
 
6
  export async function getFriends(): Promise<GetFriend[] | null> {
7
  const friends = await safeFetch<GetFriend[]>("/friends?limit=50");
@@ -18,3 +20,66 @@ export async function searchUsers(query: string) {
18
 
19
  return result;
20
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  "use server";
2
 
3
+ import { api } from "@/lib/clients/server";
4
  import { safeFetch } from "@/lib/constants/safe-fetch";
5
  import { GetFriend, SearchFriend } from "@/types/friends";
6
+ import { revalidatePath } from "next/cache";
7
 
8
  export async function getFriends(): Promise<GetFriend[] | null> {
9
  const friends = await safeFetch<GetFriend[]>("/friends?limit=50");
 
20
 
21
  return result;
22
  }
23
+ export async function getRequests() {
24
+ const result = await safeFetch<SearchFriend[]>(`/friends/requests`);
25
+
26
+ if (!result?.length) return null;
27
+ return result;
28
+ }
29
+ export async function removeFriend(userId: string): Promise<boolean> {
30
+ const res = await api(`/friends/remove`, {
31
+ method: "DELETE",
32
+ headers: {
33
+ "Content-Type": "application/json",
34
+ },
35
+
36
+ body: { userId },
37
+ });
38
+
39
+ if (!res?.ok) return false;
40
+ revalidatePath("/community");
41
+
42
+ return true;
43
+ }
44
+ export async function addFriend(userId: string): Promise<boolean> {
45
+ const res = await api(`/friends/request`, {
46
+ method: "POST",
47
+ headers: {
48
+ "Content-Type": "application/json",
49
+ },
50
+
51
+ body: { userId },
52
+ });
53
+
54
+ if (!res?.ok) return false;
55
+ revalidatePath("/community");
56
+ return true;
57
+ }
58
+ export async function acceptRequest(userId: string): Promise<boolean> {
59
+ const res = await api(`/friends/accept`, {
60
+ method: "POST",
61
+ headers: {
62
+ "Content-Type": "application/json",
63
+ },
64
+
65
+ body: { userId },
66
+ });
67
+
68
+ if (!res?.ok) return false;
69
+ revalidatePath("/community");
70
+ return true;
71
+ }
72
+ export async function declineRequest(userId: string): Promise<boolean> {
73
+ const res = await api(`/friends/decline`, {
74
+ method: "DELETE",
75
+ headers: {
76
+ "Content-Type": "application/json",
77
+ },
78
+
79
+ body: { userId },
80
+ });
81
+
82
+ if (!res?.ok) return false;
83
+ revalidatePath("/community");
84
+ return true;
85
+ }
chess-frontend/app/(protected)/community/_components/blocked-tab.tsx CHANGED
@@ -21,7 +21,7 @@ export function BlockedTab() {
21
  {STUB_BLOCKED.length} block
22
  </p>
23
  <div className="flex flex-col gap-2">
24
- {STUB_BLOCKED.map((b) => (
25
  <PlayerCard
26
  key={b.id}
27
  player={b}
@@ -39,7 +39,7 @@ export function BlockedTab() {
39
  </button>
40
  }
41
  />
42
- ))}
43
  </div>
44
  </>
45
  )}
 
21
  {STUB_BLOCKED.length} block
22
  </p>
23
  <div className="flex flex-col gap-2">
24
+ {/* {STUB_BLOCKED.map((b) => (
25
  <PlayerCard
26
  key={b.id}
27
  player={b}
 
39
  </button>
40
  }
41
  />
42
+ ))} */}
43
  </div>
44
  </>
45
  )}
chess-frontend/app/(protected)/community/_components/community-client.tsx CHANGED
@@ -50,6 +50,7 @@ export function CommunityNav({ active }: { active: string }) {
50
  const handleTabChange = (id: string) => {
51
  const params = new URLSearchParams(searchParams);
52
  params.set("tab", id);
 
53
  router.replace(`${pathname}?${params.toString()}`);
54
  };
55
  return (
 
50
  const handleTabChange = (id: string) => {
51
  const params = new URLSearchParams(searchParams);
52
  params.set("tab", id);
53
+ params.delete("q");
54
  router.replace(`${pathname}?${params.toString()}`);
55
  };
56
  return (
chess-frontend/app/(protected)/community/_components/community-shared.tsx CHANGED
@@ -1,6 +1,8 @@
1
  import { Check, Search, Swords, Trophy, UserPlus, UserX } from "lucide-react";
2
  import { getInitials } from "@/lib/constants/get-initials";
3
  import { GetFriend, SearchFriend } from "@/types/friends";
 
 
4
 
5
  export function getAvatarHue(name: string) {
6
  return [...name].reduce((a, c) => a + c.charCodeAt(0), 0) % 360;
@@ -146,107 +148,6 @@ export function FriendCard({
146
  </div>
147
  );
148
  }
149
- export function PlayerCard({ player }: { player: SearchFriend }) {
150
- return (
151
- <div
152
- className="flex items-center gap-3 px-4 py-3 rounded-2xl group transition-all duration-150"
153
- style={{
154
- background: "rgba(255,255,255,0.03)",
155
- border: "1px solid rgba(255,255,255,0.06)",
156
- }}
157
- >
158
- <Avatar
159
- player={{
160
- name: player.name,
161
- image: player.image,
162
- }}
163
- size={44}
164
- />
165
-
166
- <div className="flex-1 min-w-0 flex flex-col gap-1">
167
- <div className="flex items-baseline gap-2">
168
- <span
169
- className="text-sm font-semibold text-white truncate"
170
- style={{ fontFamily: "'DM Sans', sans-serif" }}
171
- >
172
- {player.name}
173
- </span>
174
- <span
175
- className="text-[11px] text-zinc-500 truncate"
176
- style={{ fontFamily: "'Fira Code', monospace" }}
177
- >
178
- @{player.username}
179
- </span>
180
- </div>
181
- <div className="flex items-center gap-2">
182
- <div className="flex items-center gap-1">
183
- <Trophy size={10} className="text-amber-400" />
184
- <span
185
- className="text-xs font-bold text-amber-400"
186
- style={{ fontFamily: "'Fira Code', monospace" }}
187
- >
188
- {player.rating}
189
- </span>
190
- </div>
191
- <span className="text-zinc-700 text-xs">·</span>
192
- </div>
193
- </div>
194
-
195
- <div className="flex items-center gap-1.5 shrink-0">
196
- <IconBtn icon={Swords} label="Challenge to game" variant="amber" />
197
- <IconBtn icon={UserPlus} label="Send friend request" variant="green" />
198
- <IconBtn icon={UserX} label="Block user" variant="red" />
199
- </div>
200
- </div>
201
- );
202
- }
203
-
204
- export function IconBtn({
205
- icon: Icon,
206
- label,
207
- variant = "default",
208
- }: {
209
- icon: React.ElementType;
210
- label: string;
211
- onClick?: () => void;
212
- variant?: "default" | "green" | "red" | "amber";
213
- }) {
214
- const colors = {
215
- default: {
216
- bg: "rgba(255,255,255,0.07)",
217
- hover: "rgba(255,255,255,0.13)",
218
- color: "#a1a1aa",
219
- },
220
- green: {
221
- bg: "rgba(34,197,94,0.12)",
222
- hover: "rgba(34,197,94,0.22)",
223
- color: "#4ade80",
224
- },
225
- red: {
226
- bg: "rgba(239,68,68,0.1)",
227
- hover: "rgba(239,68,68,0.2)",
228
- color: "#f87171",
229
- },
230
- amber: {
231
- bg: "rgba(234,179,8,0.1)",
232
- hover: "rgba(234,179,8,0.2)",
233
- color: "#fbbf24",
234
- },
235
- }[variant];
236
-
237
- return (
238
- <button
239
- title={label}
240
- className="w-8 h-8 rounded-xl flex items-center justify-center transition-all duration-150"
241
- style={{
242
- background: false ? colors.hover : colors.bg,
243
- color: colors.color,
244
- }}
245
- >
246
- <Icon size={14} />
247
- </button>
248
- );
249
- }
250
 
251
  export function EmptyState({
252
  icon: Icon,
 
1
  import { Check, Search, Swords, Trophy, UserPlus, UserX } from "lucide-react";
2
  import { getInitials } from "@/lib/constants/get-initials";
3
  import { GetFriend, SearchFriend } from "@/types/friends";
4
+ import { IconBtn } from "./icon-btn";
5
+ import { addFriend } from "@/actions/friend";
6
 
7
  export function getAvatarHue(name: string) {
8
  return [...name].reduce((a, c) => a + c.charCodeAt(0), 0) % 360;
 
148
  </div>
149
  );
150
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
151
 
152
  export function EmptyState({
153
  icon: Icon,
chess-frontend/app/(protected)/community/_components/find-players-tab.tsx CHANGED
@@ -1,7 +1,9 @@
1
- import { EmptyState, PlayerCard } from "./community-shared";
2
- import { searchUsers } from "@/actions/friend";
3
  import { SearchUsersForm } from "./search-users-form";
4
- import { Search } from "lucide-react";
 
 
5
 
6
  export async function FindPlayersTab({ query }: { query: string }) {
7
  const results = query ? await searchUsers(query) : null;
@@ -22,7 +24,30 @@ export async function FindPlayersTab({ query }: { query: string }) {
22
  ) : (
23
  <div className="flex flex-col gap-2">
24
  {results.map((p) => (
25
- <PlayerCard key={p.id} player={p} />
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
  ))}
27
  </div>
28
  )}
 
1
+ import { EmptyState } from "./community-shared";
2
+ import { addFriend, searchUsers } from "@/actions/friend";
3
  import { SearchUsersForm } from "./search-users-form";
4
+ import { Search, Swords, UserPlus, UserX } from "lucide-react";
5
+ import { IconBtn } from "./icon-btn";
6
+ import { PlayerCard } from "./player-card";
7
 
8
  export async function FindPlayersTab({ query }: { query: string }) {
9
  const results = query ? await searchUsers(query) : null;
 
24
  ) : (
25
  <div className="flex flex-col gap-2">
26
  {results.map((p) => (
27
+ <PlayerCard
28
+ key={p.id}
29
+ player={p}
30
+ actions={
31
+ <>
32
+ <IconBtn
33
+ icon={<Swords size="14" />}
34
+ label="Challenge to game"
35
+ variant="amber"
36
+ />
37
+ <IconBtn
38
+ onClick={addFriend.bind(null, p.id)}
39
+ icon={<UserPlus size="14" />}
40
+ label="Send friend request"
41
+ variant="green"
42
+ />
43
+ <IconBtn
44
+ icon={<UserX size="14" />}
45
+ label="Block user"
46
+ variant="red"
47
+ />
48
+ </>
49
+ }
50
+ />
51
  ))}
52
  </div>
53
  )}
chess-frontend/app/(protected)/community/_components/friends-tab.tsx CHANGED
@@ -1,12 +1,8 @@
1
  import { Swords, MessageSquare, UserMinus, Users } from "lucide-react";
2
- import {
3
- PlayerCard,
4
- IconBtn,
5
- EmptyState,
6
- FriendCard,
7
- } from "./community-shared";
8
- import { getFriends } from "@/actions/friend";
9
  import { SearchUsersForm } from "./search-users-form";
 
10
 
11
  export async function FriendsTab({ query }: { query: string }) {
12
  const friends = await getFriends();
@@ -28,13 +24,17 @@ export async function FriendsTab({ query }: { query: string }) {
28
  player={f}
29
  actions={
30
  <>
31
- <IconBtn icon={Swords} label="Challenge" variant="amber" />
32
- <IconBtn icon={MessageSquare} label="Message" />
33
  <IconBtn
34
- icon={UserMinus}
 
 
 
 
 
 
35
  label="Remove friend"
36
  variant="red"
37
- // onClick={() => removeFriend(f.id)}
38
  />
39
  </>
40
  }
 
1
  import { Swords, MessageSquare, UserMinus, Users } from "lucide-react";
2
+ import { EmptyState, FriendCard } from "./community-shared";
3
+ import { getFriends, removeFriend } from "@/actions/friend";
 
 
 
 
 
4
  import { SearchUsersForm } from "./search-users-form";
5
+ import { IconBtn } from "./icon-btn";
6
 
7
  export async function FriendsTab({ query }: { query: string }) {
8
  const friends = await getFriends();
 
24
  player={f}
25
  actions={
26
  <>
 
 
27
  <IconBtn
28
+ icon={<Swords size="14" />}
29
+ label="Challenge"
30
+ variant="amber"
31
+ />
32
+ <IconBtn icon={<MessageSquare size="14" />} label="Message" />
33
+ <IconBtn
34
+ icon={<UserMinus size="14" />}
35
  label="Remove friend"
36
  variant="red"
37
+ onClick={removeFriend.bind(null, f.id)}
38
  />
39
  </>
40
  }
chess-frontend/app/(protected)/community/_components/icon-btn.tsx ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "use client";
2
+
3
+ import { useTransition } from "react";
4
+
5
+ export function IconBtn({
6
+ icon,
7
+ label,
8
+ onClick,
9
+ variant = "default",
10
+ className = "",
11
+ ...props
12
+ }: {
13
+ icon: React.ReactNode;
14
+ label: string;
15
+ onClick?: () => Promise<boolean>;
16
+ variant?: "default" | "green" | "red" | "amber";
17
+ className?: string;
18
+ } & React.ButtonHTMLAttributes<HTMLButtonElement>) {
19
+ const [isPending, startTransition] = useTransition();
20
+ const colors = {
21
+ default: {
22
+ bg: "rgba(255,255,255,0.07)",
23
+ hover: "rgba(255,255,255,0.13)",
24
+ color: "#a1a1aa",
25
+ },
26
+ green: {
27
+ bg: "rgba(34,197,94,0.12)",
28
+ hover: "rgba(34,197,94,0.22)",
29
+ color: "#4ade80",
30
+ },
31
+ red: {
32
+ bg: "rgba(239,68,68,0.1)",
33
+ hover: "rgba(239,68,68,0.2)",
34
+ color: "#f87171",
35
+ },
36
+ amber: {
37
+ bg: "rgba(234,179,8,0.1)",
38
+ hover: "rgba(234,179,8,0.2)",
39
+ color: "#fbbf24",
40
+ },
41
+ }[variant];
42
+
43
+ return (
44
+ <button
45
+ title={label}
46
+ className={`w-8 h-8 rounded-xl flex items-center justify-center transition-all duration-150 hover:brightness-125 disabled:opacity-50 disabled:pointer-events-none ${className}`}
47
+ style={{
48
+ background: colors.bg,
49
+ color: colors.color,
50
+ }}
51
+ onClick={(e) => {
52
+ e.preventDefault();
53
+ e.stopPropagation();
54
+ if (onClick) {
55
+ startTransition(async () => {
56
+ await onClick();
57
+ });
58
+ }
59
+ }}
60
+ disabled={isPending || props.disabled}
61
+ {...props}
62
+ >
63
+ {icon}
64
+ </button>
65
+ );
66
+ }
chess-frontend/app/(protected)/community/_components/player-card.tsx ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "use client";
2
+
3
+ import { SearchFriend } from "@/types/friends";
4
+ import { Trophy } from "lucide-react";
5
+ import { Avatar } from "./community-shared";
6
+
7
+ export function PlayerCard({
8
+ player,
9
+ actions,
10
+ }: {
11
+ player: SearchFriend;
12
+ actions: React.ReactNode;
13
+ }) {
14
+ return (
15
+ <div
16
+ className="flex items-center gap-3 px-4 py-3 rounded-2xl group transition-all duration-150"
17
+ style={{
18
+ background: "rgba(255,255,255,0.03)",
19
+ border: "1px solid rgba(255,255,255,0.06)",
20
+ }}
21
+ >
22
+ <Avatar
23
+ player={{
24
+ name: player.name,
25
+ image: player.image,
26
+ }}
27
+ size={44}
28
+ />
29
+
30
+ <div className="flex-1 min-w-0 flex flex-col gap-1">
31
+ <div className="flex items-baseline gap-2">
32
+ <span
33
+ className="text-sm font-semibold text-white truncate"
34
+ style={{ fontFamily: "'DM Sans', sans-serif" }}
35
+ >
36
+ {player.name}
37
+ </span>
38
+ <span
39
+ className="text-[11px] text-zinc-500 truncate"
40
+ style={{ fontFamily: "'Fira Code', monospace" }}
41
+ >
42
+ @{player.username}
43
+ </span>
44
+ </div>
45
+ <div className="flex items-center gap-2">
46
+ <div className="flex items-center gap-1">
47
+ <Trophy size={10} className="text-amber-400" />
48
+ <span
49
+ className="text-xs font-bold text-amber-400"
50
+ style={{ fontFamily: "'Fira Code', monospace" }}
51
+ >
52
+ {player.rating}
53
+ </span>
54
+ </div>
55
+ <span className="text-zinc-700 text-xs">·</span>
56
+ </div>
57
+ </div>
58
+
59
+ <div className="flex items-center gap-1.5 shrink-0">{actions}</div>
60
+ </div>
61
+ );
62
+ }
chess-frontend/app/(protected)/community/_components/requests-tab.tsx CHANGED
@@ -1,58 +1,51 @@
1
- "use client";
2
-
3
- import * as React from "react";
4
  import { Bell, Check, X } from "lucide-react";
5
- import { STUB_REQUESTS } from "./community-types";
6
- import { EmptyState, PlayerCard, IconBtn } from "./community-shared";
7
-
8
- export function RequestsTab() {
9
- const [requests, setRequests] = React.useState(STUB_REQUESTS);
10
 
11
- const accept = (id: string) =>
12
- setRequests((p) => p.filter((r) => r.id !== id));
13
- const decline = (id: string) =>
14
- setRequests((p) => p.filter((r) => r.id !== id));
15
 
16
  return (
17
  <div className="flex flex-col gap-4">
18
- {requests.length === 0 ? (
19
- // <EmptyState
20
- // icon={Bell}
21
- // title="No pending requests"
22
- // sub="When someone sends you a friend request, it'll show up here."
23
- // />
24
- <div></div>
25
  ) : (
26
  <>
27
  <p
28
  className="text-xs text-zinc-500"
29
  style={{ fontFamily: "'Fira Code', monospace" }}
30
  >
31
- {requests.length} pending
32
  </p>
33
  <div className="flex flex-col gap-2">
34
- {/* {requests.map((r) => (
35
  <PlayerCard
36
  key={r.id}
37
  player={r}
38
  actions={
39
  <>
40
  <IconBtn
41
- icon={Check}
42
  label="Accept"
43
  variant="green"
44
- onClick={() => accept(r.id)}
45
  />
46
  <IconBtn
47
- icon={X}
48
  label="Decline"
49
  variant="red"
50
- onClick={() => decline(r.id)}
51
  />
52
  </>
53
  }
54
  />
55
- ))} */}
56
  </div>
57
  </>
58
  )}
 
1
+ import { acceptRequest, declineRequest, getRequests } from "@/actions/friend";
2
+ import { EmptyState } from "./community-shared";
 
3
  import { Bell, Check, X } from "lucide-react";
4
+ import { IconBtn } from "./icon-btn";
5
+ import { PlayerCard } from "./player-card";
 
 
 
6
 
7
+ export async function RequestsTab() {
8
+ const friends = await getRequests();
 
 
9
 
10
  return (
11
  <div className="flex flex-col gap-4">
12
+ {!friends ? (
13
+ <EmptyState
14
+ icon={Bell}
15
+ title="No pending friends"
16
+ sub="When someone sends you a friend request, it'll show up here."
17
+ />
 
18
  ) : (
19
  <>
20
  <p
21
  className="text-xs text-zinc-500"
22
  style={{ fontFamily: "'Fira Code', monospace" }}
23
  >
24
+ {friends.length} pending
25
  </p>
26
  <div className="flex flex-col gap-2">
27
+ {friends.map((r) => (
28
  <PlayerCard
29
  key={r.id}
30
  player={r}
31
  actions={
32
  <>
33
  <IconBtn
34
+ icon={<Check size="14" />}
35
  label="Accept"
36
  variant="green"
37
+ onClick={acceptRequest.bind(null, r.id)}
38
  />
39
  <IconBtn
40
+ icon={<X size="14" />}
41
  label="Decline"
42
  variant="red"
43
+ onClick={declineRequest.bind(null, r.id)}
44
  />
45
  </>
46
  }
47
  />
48
+ ))}
49
  </div>
50
  </>
51
  )}
chess-frontend/app/(protected)/community/_components/search-users-form.tsx CHANGED
@@ -2,7 +2,7 @@
2
 
3
  import { Search } from "lucide-react";
4
  import { usePathname, useRouter, useSearchParams } from "next/navigation";
5
- import { useState } from "react";
6
 
7
  export function SearchUsersForm({
8
  placeholder,
@@ -17,6 +17,10 @@ export function SearchUsersForm({
17
 
18
  const [text, setText] = useState(query);
19
 
 
 
 
 
20
  const handleSubmit = (e: React.SubmitEvent<HTMLFormElement>) => {
21
  e.preventDefault();
22
  const params = new URLSearchParams(searchParams);
 
2
 
3
  import { Search } from "lucide-react";
4
  import { usePathname, useRouter, useSearchParams } from "next/navigation";
5
+ import { useState, useEffect } from "react";
6
 
7
  export function SearchUsersForm({
8
  placeholder,
 
17
 
18
  const [text, setText] = useState(query);
19
 
20
+ useEffect(() => {
21
+ setText(query);
22
+ }, [query]);
23
+
24
  const handleSubmit = (e: React.SubmitEvent<HTMLFormElement>) => {
25
  e.preventDefault();
26
  const params = new URLSearchParams(searchParams);
chess-frontend/app/(protected)/community/page.tsx CHANGED
@@ -1,4 +1,3 @@
1
- import { getFriends } from "@/actions/friend";
2
  import { BlockedTab } from "./_components/blocked-tab";
3
  import { CommunityNav } from "./_components/community-client";
4
  import { FindPlayersTab } from "./_components/find-players-tab";
 
 
1
  import { BlockedTab } from "./_components/blocked-tab";
2
  import { CommunityNav } from "./_components/community-client";
3
  import { FindPlayersTab } from "./_components/find-players-tab";
chess-frontend/package.json CHANGED
@@ -38,5 +38,8 @@
38
  "eslint-config-next": "16.1.6",
39
  "tailwindcss": "^4",
40
  "typescript": "^5"
41
- }
 
 
 
42
  }
 
38
  "eslint-config-next": "16.1.6",
39
  "tailwindcss": "^4",
40
  "typescript": "^5"
41
+ },
42
+ "trustedDependencies": [
43
+ "unrs-resolver"
44
+ ]
45
  }
chess-monolith/drizzle/0004_nasty_gorilla_man.sql ADDED
@@ -0,0 +1 @@
 
 
1
+ CREATE INDEX "users_search_trgm_idx" ON "user" USING gin (("username" || ' ' || "name") gin_trgm_ops);
chess-monolith/drizzle/0005_create_pg_trgm_extension.sql ADDED
@@ -0,0 +1 @@
 
 
1
+ CREATE EXTENSION IF NOT EXISTS pg_trgm;
chess-monolith/drizzle/meta/0004_snapshot.json ADDED
@@ -0,0 +1,921 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "id": "b4578431-aebb-4dcc-9871-b3d79df858dd",
3
+ "prevId": "5568ddc5-eb26-4fe2-a2b3-b703e32e8656",
4
+ "version": "7",
5
+ "dialect": "postgresql",
6
+ "tables": {
7
+ "public.account": {
8
+ "name": "account",
9
+ "schema": "",
10
+ "columns": {
11
+ "id": {
12
+ "name": "id",
13
+ "type": "text",
14
+ "primaryKey": true,
15
+ "notNull": true
16
+ },
17
+ "account_id": {
18
+ "name": "account_id",
19
+ "type": "text",
20
+ "primaryKey": false,
21
+ "notNull": true
22
+ },
23
+ "provider_id": {
24
+ "name": "provider_id",
25
+ "type": "text",
26
+ "primaryKey": false,
27
+ "notNull": true
28
+ },
29
+ "user_id": {
30
+ "name": "user_id",
31
+ "type": "text",
32
+ "primaryKey": false,
33
+ "notNull": true
34
+ },
35
+ "access_token": {
36
+ "name": "access_token",
37
+ "type": "text",
38
+ "primaryKey": false,
39
+ "notNull": false
40
+ },
41
+ "refresh_token": {
42
+ "name": "refresh_token",
43
+ "type": "text",
44
+ "primaryKey": false,
45
+ "notNull": false
46
+ },
47
+ "id_token": {
48
+ "name": "id_token",
49
+ "type": "text",
50
+ "primaryKey": false,
51
+ "notNull": false
52
+ },
53
+ "access_token_expires_at": {
54
+ "name": "access_token_expires_at",
55
+ "type": "timestamp",
56
+ "primaryKey": false,
57
+ "notNull": false
58
+ },
59
+ "refresh_token_expires_at": {
60
+ "name": "refresh_token_expires_at",
61
+ "type": "timestamp",
62
+ "primaryKey": false,
63
+ "notNull": false
64
+ },
65
+ "scope": {
66
+ "name": "scope",
67
+ "type": "text",
68
+ "primaryKey": false,
69
+ "notNull": false
70
+ },
71
+ "password": {
72
+ "name": "password",
73
+ "type": "text",
74
+ "primaryKey": false,
75
+ "notNull": false
76
+ },
77
+ "created_at": {
78
+ "name": "created_at",
79
+ "type": "timestamp",
80
+ "primaryKey": false,
81
+ "notNull": true,
82
+ "default": "now()"
83
+ },
84
+ "updated_at": {
85
+ "name": "updated_at",
86
+ "type": "timestamp",
87
+ "primaryKey": false,
88
+ "notNull": true
89
+ }
90
+ },
91
+ "indexes": {
92
+ "account_userId_idx": {
93
+ "name": "account_userId_idx",
94
+ "columns": [
95
+ {
96
+ "expression": "user_id",
97
+ "isExpression": false,
98
+ "asc": true,
99
+ "nulls": "last"
100
+ }
101
+ ],
102
+ "isUnique": false,
103
+ "concurrently": false,
104
+ "method": "btree",
105
+ "with": {}
106
+ }
107
+ },
108
+ "foreignKeys": {
109
+ "account_user_id_user_id_fk": {
110
+ "name": "account_user_id_user_id_fk",
111
+ "tableFrom": "account",
112
+ "tableTo": "user",
113
+ "columnsFrom": [
114
+ "user_id"
115
+ ],
116
+ "columnsTo": [
117
+ "id"
118
+ ],
119
+ "onDelete": "cascade",
120
+ "onUpdate": "no action"
121
+ }
122
+ },
123
+ "compositePrimaryKeys": {},
124
+ "uniqueConstraints": {},
125
+ "policies": {},
126
+ "checkConstraints": {},
127
+ "isRLSEnabled": false
128
+ },
129
+ "public.friends": {
130
+ "name": "friends",
131
+ "schema": "",
132
+ "columns": {
133
+ "user_id": {
134
+ "name": "user_id",
135
+ "type": "text",
136
+ "primaryKey": false,
137
+ "notNull": true
138
+ },
139
+ "friend_id": {
140
+ "name": "friend_id",
141
+ "type": "text",
142
+ "primaryKey": false,
143
+ "notNull": true
144
+ },
145
+ "status": {
146
+ "name": "status",
147
+ "type": "friend_status",
148
+ "typeSchema": "public",
149
+ "primaryKey": false,
150
+ "notNull": true,
151
+ "default": "'PENDING'"
152
+ },
153
+ "created_at": {
154
+ "name": "created_at",
155
+ "type": "timestamp",
156
+ "primaryKey": false,
157
+ "notNull": true,
158
+ "default": "now()"
159
+ }
160
+ },
161
+ "indexes": {},
162
+ "foreignKeys": {
163
+ "friends_user_id_user_id_fk": {
164
+ "name": "friends_user_id_user_id_fk",
165
+ "tableFrom": "friends",
166
+ "tableTo": "user",
167
+ "columnsFrom": [
168
+ "user_id"
169
+ ],
170
+ "columnsTo": [
171
+ "id"
172
+ ],
173
+ "onDelete": "no action",
174
+ "onUpdate": "no action"
175
+ },
176
+ "friends_friend_id_user_id_fk": {
177
+ "name": "friends_friend_id_user_id_fk",
178
+ "tableFrom": "friends",
179
+ "tableTo": "user",
180
+ "columnsFrom": [
181
+ "friend_id"
182
+ ],
183
+ "columnsTo": [
184
+ "id"
185
+ ],
186
+ "onDelete": "no action",
187
+ "onUpdate": "no action"
188
+ }
189
+ },
190
+ "compositePrimaryKeys": {
191
+ "friends_user_id_friend_id_pk": {
192
+ "name": "friends_user_id_friend_id_pk",
193
+ "columns": [
194
+ "user_id",
195
+ "friend_id"
196
+ ]
197
+ }
198
+ },
199
+ "uniqueConstraints": {},
200
+ "policies": {},
201
+ "checkConstraints": {},
202
+ "isRLSEnabled": false
203
+ },
204
+ "public.games": {
205
+ "name": "games",
206
+ "schema": "",
207
+ "columns": {
208
+ "id": {
209
+ "name": "id",
210
+ "type": "uuid",
211
+ "primaryKey": true,
212
+ "notNull": true
213
+ },
214
+ "white_id": {
215
+ "name": "white_id",
216
+ "type": "text",
217
+ "primaryKey": false,
218
+ "notNull": true
219
+ },
220
+ "black_id": {
221
+ "name": "black_id",
222
+ "type": "text",
223
+ "primaryKey": false,
224
+ "notNull": true
225
+ },
226
+ "winner_id": {
227
+ "name": "winner_id",
228
+ "type": "text",
229
+ "primaryKey": false,
230
+ "notNull": false
231
+ },
232
+ "status": {
233
+ "name": "status",
234
+ "type": "status",
235
+ "typeSchema": "public",
236
+ "primaryKey": false,
237
+ "notNull": true
238
+ },
239
+ "result": {
240
+ "name": "result",
241
+ "type": "result",
242
+ "typeSchema": "public",
243
+ "primaryKey": false,
244
+ "notNull": true,
245
+ "default": "'d'"
246
+ },
247
+ "time_control": {
248
+ "name": "time_control",
249
+ "type": "varchar(20)",
250
+ "primaryKey": false,
251
+ "notNull": true
252
+ },
253
+ "pgn": {
254
+ "name": "pgn",
255
+ "type": "text",
256
+ "primaryKey": false,
257
+ "notNull": true
258
+ },
259
+ "move_times": {
260
+ "name": "move_times",
261
+ "type": "jsonb",
262
+ "primaryKey": false,
263
+ "notNull": true,
264
+ "default": "'[]'::jsonb"
265
+ },
266
+ "fen": {
267
+ "name": "fen",
268
+ "type": "varchar(2048)",
269
+ "primaryKey": false,
270
+ "notNull": true
271
+ },
272
+ "white_time_left_ms": {
273
+ "name": "white_time_left_ms",
274
+ "type": "integer",
275
+ "primaryKey": false,
276
+ "notNull": true
277
+ },
278
+ "black_time_left_ms": {
279
+ "name": "black_time_left_ms",
280
+ "type": "integer",
281
+ "primaryKey": false,
282
+ "notNull": true
283
+ },
284
+ "white_rating": {
285
+ "name": "white_rating",
286
+ "type": "integer",
287
+ "primaryKey": false,
288
+ "notNull": true,
289
+ "default": 1000
290
+ },
291
+ "black_rating": {
292
+ "name": "black_rating",
293
+ "type": "integer",
294
+ "primaryKey": false,
295
+ "notNull": true,
296
+ "default": 1000
297
+ },
298
+ "white_diff": {
299
+ "name": "white_diff",
300
+ "type": "integer",
301
+ "primaryKey": false,
302
+ "notNull": true,
303
+ "default": 0
304
+ },
305
+ "black_diff": {
306
+ "name": "black_diff",
307
+ "type": "integer",
308
+ "primaryKey": false,
309
+ "notNull": true,
310
+ "default": 0
311
+ },
312
+ "captured_by_white": {
313
+ "name": "captured_by_white",
314
+ "type": "jsonb",
315
+ "primaryKey": false,
316
+ "notNull": true,
317
+ "default": "'[]'::jsonb"
318
+ },
319
+ "captured_by_black": {
320
+ "name": "captured_by_black",
321
+ "type": "jsonb",
322
+ "primaryKey": false,
323
+ "notNull": true,
324
+ "default": "'[]'::jsonb"
325
+ },
326
+ "chat_logs": {
327
+ "name": "chat_logs",
328
+ "type": "jsonb",
329
+ "primaryKey": false,
330
+ "notNull": true,
331
+ "default": "'[]'::jsonb"
332
+ },
333
+ "created_at": {
334
+ "name": "created_at",
335
+ "type": "timestamp",
336
+ "primaryKey": false,
337
+ "notNull": true,
338
+ "default": "now()"
339
+ },
340
+ "updated_at": {
341
+ "name": "updated_at",
342
+ "type": "timestamp",
343
+ "primaryKey": false,
344
+ "notNull": true,
345
+ "default": "now()"
346
+ }
347
+ },
348
+ "indexes": {
349
+ "games_white_id_idx": {
350
+ "name": "games_white_id_idx",
351
+ "columns": [
352
+ {
353
+ "expression": "white_id",
354
+ "isExpression": false,
355
+ "asc": true,
356
+ "nulls": "last"
357
+ }
358
+ ],
359
+ "isUnique": false,
360
+ "concurrently": false,
361
+ "method": "btree",
362
+ "with": {}
363
+ },
364
+ "games_black_id_idx": {
365
+ "name": "games_black_id_idx",
366
+ "columns": [
367
+ {
368
+ "expression": "black_id",
369
+ "isExpression": false,
370
+ "asc": true,
371
+ "nulls": "last"
372
+ }
373
+ ],
374
+ "isUnique": false,
375
+ "concurrently": false,
376
+ "method": "btree",
377
+ "with": {}
378
+ },
379
+ "games_created_at_idx": {
380
+ "name": "games_created_at_idx",
381
+ "columns": [
382
+ {
383
+ "expression": "created_at",
384
+ "isExpression": false,
385
+ "asc": true,
386
+ "nulls": "last"
387
+ }
388
+ ],
389
+ "isUnique": false,
390
+ "concurrently": false,
391
+ "method": "btree",
392
+ "with": {}
393
+ },
394
+ "games_winner_id_idx": {
395
+ "name": "games_winner_id_idx",
396
+ "columns": [
397
+ {
398
+ "expression": "winner_id",
399
+ "isExpression": false,
400
+ "asc": true,
401
+ "nulls": "last"
402
+ }
403
+ ],
404
+ "isUnique": false,
405
+ "concurrently": false,
406
+ "method": "btree",
407
+ "with": {}
408
+ }
409
+ },
410
+ "foreignKeys": {
411
+ "games_white_id_user_id_fk": {
412
+ "name": "games_white_id_user_id_fk",
413
+ "tableFrom": "games",
414
+ "tableTo": "user",
415
+ "columnsFrom": [
416
+ "white_id"
417
+ ],
418
+ "columnsTo": [
419
+ "id"
420
+ ],
421
+ "onDelete": "no action",
422
+ "onUpdate": "no action"
423
+ },
424
+ "games_black_id_user_id_fk": {
425
+ "name": "games_black_id_user_id_fk",
426
+ "tableFrom": "games",
427
+ "tableTo": "user",
428
+ "columnsFrom": [
429
+ "black_id"
430
+ ],
431
+ "columnsTo": [
432
+ "id"
433
+ ],
434
+ "onDelete": "no action",
435
+ "onUpdate": "no action"
436
+ },
437
+ "games_winner_id_user_id_fk": {
438
+ "name": "games_winner_id_user_id_fk",
439
+ "tableFrom": "games",
440
+ "tableTo": "user",
441
+ "columnsFrom": [
442
+ "winner_id"
443
+ ],
444
+ "columnsTo": [
445
+ "id"
446
+ ],
447
+ "onDelete": "no action",
448
+ "onUpdate": "no action"
449
+ }
450
+ },
451
+ "compositePrimaryKeys": {},
452
+ "uniqueConstraints": {},
453
+ "policies": {},
454
+ "checkConstraints": {},
455
+ "isRLSEnabled": false
456
+ },
457
+ "public.messages": {
458
+ "name": "messages",
459
+ "schema": "",
460
+ "columns": {
461
+ "id": {
462
+ "name": "id",
463
+ "type": "uuid",
464
+ "primaryKey": true,
465
+ "notNull": true,
466
+ "default": "gen_random_uuid()"
467
+ },
468
+ "sender_id": {
469
+ "name": "sender_id",
470
+ "type": "text",
471
+ "primaryKey": false,
472
+ "notNull": true
473
+ },
474
+ "receiver_id": {
475
+ "name": "receiver_id",
476
+ "type": "text",
477
+ "primaryKey": false,
478
+ "notNull": true
479
+ },
480
+ "content": {
481
+ "name": "content",
482
+ "type": "text",
483
+ "primaryKey": false,
484
+ "notNull": true
485
+ },
486
+ "created_at": {
487
+ "name": "created_at",
488
+ "type": "timestamp",
489
+ "primaryKey": false,
490
+ "notNull": true,
491
+ "default": "now()"
492
+ },
493
+ "read": {
494
+ "name": "read",
495
+ "type": "boolean",
496
+ "primaryKey": false,
497
+ "notNull": true,
498
+ "default": false
499
+ }
500
+ },
501
+ "indexes": {
502
+ "messages_sender_id_idx": {
503
+ "name": "messages_sender_id_idx",
504
+ "columns": [
505
+ {
506
+ "expression": "sender_id",
507
+ "isExpression": false,
508
+ "asc": true,
509
+ "nulls": "last"
510
+ }
511
+ ],
512
+ "isUnique": false,
513
+ "concurrently": false,
514
+ "method": "btree",
515
+ "with": {}
516
+ },
517
+ "messages_receiver_id_idx": {
518
+ "name": "messages_receiver_id_idx",
519
+ "columns": [
520
+ {
521
+ "expression": "receiver_id",
522
+ "isExpression": false,
523
+ "asc": true,
524
+ "nulls": "last"
525
+ }
526
+ ],
527
+ "isUnique": false,
528
+ "concurrently": false,
529
+ "method": "btree",
530
+ "with": {}
531
+ },
532
+ "messages_created_at_idx": {
533
+ "name": "messages_created_at_idx",
534
+ "columns": [
535
+ {
536
+ "expression": "created_at",
537
+ "isExpression": false,
538
+ "asc": true,
539
+ "nulls": "last"
540
+ }
541
+ ],
542
+ "isUnique": false,
543
+ "concurrently": false,
544
+ "method": "btree",
545
+ "with": {}
546
+ }
547
+ },
548
+ "foreignKeys": {
549
+ "messages_sender_id_user_id_fk": {
550
+ "name": "messages_sender_id_user_id_fk",
551
+ "tableFrom": "messages",
552
+ "tableTo": "user",
553
+ "columnsFrom": [
554
+ "sender_id"
555
+ ],
556
+ "columnsTo": [
557
+ "id"
558
+ ],
559
+ "onDelete": "no action",
560
+ "onUpdate": "no action"
561
+ },
562
+ "messages_receiver_id_user_id_fk": {
563
+ "name": "messages_receiver_id_user_id_fk",
564
+ "tableFrom": "messages",
565
+ "tableTo": "user",
566
+ "columnsFrom": [
567
+ "receiver_id"
568
+ ],
569
+ "columnsTo": [
570
+ "id"
571
+ ],
572
+ "onDelete": "no action",
573
+ "onUpdate": "no action"
574
+ }
575
+ },
576
+ "compositePrimaryKeys": {},
577
+ "uniqueConstraints": {},
578
+ "policies": {},
579
+ "checkConstraints": {},
580
+ "isRLSEnabled": false
581
+ },
582
+ "public.session": {
583
+ "name": "session",
584
+ "schema": "",
585
+ "columns": {
586
+ "id": {
587
+ "name": "id",
588
+ "type": "text",
589
+ "primaryKey": true,
590
+ "notNull": true
591
+ },
592
+ "expires_at": {
593
+ "name": "expires_at",
594
+ "type": "timestamp",
595
+ "primaryKey": false,
596
+ "notNull": true
597
+ },
598
+ "token": {
599
+ "name": "token",
600
+ "type": "text",
601
+ "primaryKey": false,
602
+ "notNull": true
603
+ },
604
+ "created_at": {
605
+ "name": "created_at",
606
+ "type": "timestamp",
607
+ "primaryKey": false,
608
+ "notNull": true,
609
+ "default": "now()"
610
+ },
611
+ "updated_at": {
612
+ "name": "updated_at",
613
+ "type": "timestamp",
614
+ "primaryKey": false,
615
+ "notNull": true
616
+ },
617
+ "ip_address": {
618
+ "name": "ip_address",
619
+ "type": "text",
620
+ "primaryKey": false,
621
+ "notNull": false
622
+ },
623
+ "user_agent": {
624
+ "name": "user_agent",
625
+ "type": "text",
626
+ "primaryKey": false,
627
+ "notNull": false
628
+ },
629
+ "user_id": {
630
+ "name": "user_id",
631
+ "type": "text",
632
+ "primaryKey": false,
633
+ "notNull": true
634
+ }
635
+ },
636
+ "indexes": {
637
+ "session_userId_idx": {
638
+ "name": "session_userId_idx",
639
+ "columns": [
640
+ {
641
+ "expression": "user_id",
642
+ "isExpression": false,
643
+ "asc": true,
644
+ "nulls": "last"
645
+ }
646
+ ],
647
+ "isUnique": false,
648
+ "concurrently": false,
649
+ "method": "btree",
650
+ "with": {}
651
+ }
652
+ },
653
+ "foreignKeys": {
654
+ "session_user_id_user_id_fk": {
655
+ "name": "session_user_id_user_id_fk",
656
+ "tableFrom": "session",
657
+ "tableTo": "user",
658
+ "columnsFrom": [
659
+ "user_id"
660
+ ],
661
+ "columnsTo": [
662
+ "id"
663
+ ],
664
+ "onDelete": "cascade",
665
+ "onUpdate": "no action"
666
+ }
667
+ },
668
+ "compositePrimaryKeys": {},
669
+ "uniqueConstraints": {
670
+ "session_token_unique": {
671
+ "name": "session_token_unique",
672
+ "nullsNotDistinct": false,
673
+ "columns": [
674
+ "token"
675
+ ]
676
+ }
677
+ },
678
+ "policies": {},
679
+ "checkConstraints": {},
680
+ "isRLSEnabled": false
681
+ },
682
+ "public.user": {
683
+ "name": "user",
684
+ "schema": "",
685
+ "columns": {
686
+ "id": {
687
+ "name": "id",
688
+ "type": "text",
689
+ "primaryKey": true,
690
+ "notNull": true
691
+ },
692
+ "name": {
693
+ "name": "name",
694
+ "type": "text",
695
+ "primaryKey": false,
696
+ "notNull": true
697
+ },
698
+ "username": {
699
+ "name": "username",
700
+ "type": "varchar(50)",
701
+ "primaryKey": false,
702
+ "notNull": true
703
+ },
704
+ "email": {
705
+ "name": "email",
706
+ "type": "text",
707
+ "primaryKey": false,
708
+ "notNull": true
709
+ },
710
+ "email_verified": {
711
+ "name": "email_verified",
712
+ "type": "boolean",
713
+ "primaryKey": false,
714
+ "notNull": true,
715
+ "default": false
716
+ },
717
+ "rating": {
718
+ "name": "rating",
719
+ "type": "integer",
720
+ "primaryKey": false,
721
+ "notNull": true,
722
+ "default": 1000
723
+ },
724
+ "wins": {
725
+ "name": "wins",
726
+ "type": "integer",
727
+ "primaryKey": false,
728
+ "notNull": true,
729
+ "default": 0
730
+ },
731
+ "losses": {
732
+ "name": "losses",
733
+ "type": "integer",
734
+ "primaryKey": false,
735
+ "notNull": true,
736
+ "default": 0
737
+ },
738
+ "draws": {
739
+ "name": "draws",
740
+ "type": "integer",
741
+ "primaryKey": false,
742
+ "notNull": true,
743
+ "default": 0
744
+ },
745
+ "image": {
746
+ "name": "image",
747
+ "type": "text",
748
+ "primaryKey": false,
749
+ "notNull": false
750
+ },
751
+ "created_at": {
752
+ "name": "created_at",
753
+ "type": "timestamp",
754
+ "primaryKey": false,
755
+ "notNull": true,
756
+ "default": "now()"
757
+ },
758
+ "updated_at": {
759
+ "name": "updated_at",
760
+ "type": "timestamp",
761
+ "primaryKey": false,
762
+ "notNull": true,
763
+ "default": "now()"
764
+ }
765
+ },
766
+ "indexes": {
767
+ "users_search_trgm_idx": {
768
+ "name": "users_search_trgm_idx",
769
+ "columns": [
770
+ {
771
+ "expression": "(\"username\" || ' ' || \"name\") gin_trgm_ops",
772
+ "asc": true,
773
+ "isExpression": true,
774
+ "nulls": "last"
775
+ }
776
+ ],
777
+ "isUnique": false,
778
+ "concurrently": false,
779
+ "method": "gin",
780
+ "with": {}
781
+ }
782
+ },
783
+ "foreignKeys": {},
784
+ "compositePrimaryKeys": {},
785
+ "uniqueConstraints": {
786
+ "user_username_unique": {
787
+ "name": "user_username_unique",
788
+ "nullsNotDistinct": false,
789
+ "columns": [
790
+ "username"
791
+ ]
792
+ },
793
+ "user_email_unique": {
794
+ "name": "user_email_unique",
795
+ "nullsNotDistinct": false,
796
+ "columns": [
797
+ "email"
798
+ ]
799
+ }
800
+ },
801
+ "policies": {},
802
+ "checkConstraints": {},
803
+ "isRLSEnabled": false
804
+ },
805
+ "public.verification": {
806
+ "name": "verification",
807
+ "schema": "",
808
+ "columns": {
809
+ "id": {
810
+ "name": "id",
811
+ "type": "text",
812
+ "primaryKey": true,
813
+ "notNull": true
814
+ },
815
+ "identifier": {
816
+ "name": "identifier",
817
+ "type": "text",
818
+ "primaryKey": false,
819
+ "notNull": true
820
+ },
821
+ "value": {
822
+ "name": "value",
823
+ "type": "text",
824
+ "primaryKey": false,
825
+ "notNull": true
826
+ },
827
+ "expires_at": {
828
+ "name": "expires_at",
829
+ "type": "timestamp",
830
+ "primaryKey": false,
831
+ "notNull": true
832
+ },
833
+ "created_at": {
834
+ "name": "created_at",
835
+ "type": "timestamp",
836
+ "primaryKey": false,
837
+ "notNull": true,
838
+ "default": "now()"
839
+ },
840
+ "updated_at": {
841
+ "name": "updated_at",
842
+ "type": "timestamp",
843
+ "primaryKey": false,
844
+ "notNull": true,
845
+ "default": "now()"
846
+ }
847
+ },
848
+ "indexes": {
849
+ "verification_identifier_idx": {
850
+ "name": "verification_identifier_idx",
851
+ "columns": [
852
+ {
853
+ "expression": "identifier",
854
+ "isExpression": false,
855
+ "asc": true,
856
+ "nulls": "last"
857
+ }
858
+ ],
859
+ "isUnique": false,
860
+ "concurrently": false,
861
+ "method": "btree",
862
+ "with": {}
863
+ }
864
+ },
865
+ "foreignKeys": {},
866
+ "compositePrimaryKeys": {},
867
+ "uniqueConstraints": {},
868
+ "policies": {},
869
+ "checkConstraints": {},
870
+ "isRLSEnabled": false
871
+ }
872
+ },
873
+ "enums": {
874
+ "public.friend_status": {
875
+ "name": "friend_status",
876
+ "schema": "public",
877
+ "values": [
878
+ "PENDING",
879
+ "ACCEPTED",
880
+ "REJECTED",
881
+ "BLOCKED"
882
+ ]
883
+ },
884
+ "public.status": {
885
+ "name": "status",
886
+ "schema": "public",
887
+ "values": [
888
+ "IN_PROGRESS",
889
+ "CHECKMATE",
890
+ "RESIGN",
891
+ "DRAW",
892
+ "AGREEMENT",
893
+ "STALEMATE",
894
+ "INSUFFICIENT_MATERIAL",
895
+ "FIFTY_MOVE_RULE",
896
+ "THREEFOLD_REPETITION",
897
+ "TIME_OUT",
898
+ "ABANDONED"
899
+ ]
900
+ },
901
+ "public.result": {
902
+ "name": "result",
903
+ "schema": "public",
904
+ "values": [
905
+ "d",
906
+ "w",
907
+ "b"
908
+ ]
909
+ }
910
+ },
911
+ "schemas": {},
912
+ "sequences": {},
913
+ "roles": {},
914
+ "policies": {},
915
+ "views": {},
916
+ "_meta": {
917
+ "columns": {},
918
+ "schemas": {},
919
+ "tables": {}
920
+ }
921
+ }
chess-monolith/drizzle/meta/0005_snapshot.json ADDED
@@ -0,0 +1,921 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "id": "7be37a92-6e08-4f6e-bda1-b1dc57d79b97",
3
+ "prevId": "b4578431-aebb-4dcc-9871-b3d79df858dd",
4
+ "version": "7",
5
+ "dialect": "postgresql",
6
+ "tables": {
7
+ "public.account": {
8
+ "name": "account",
9
+ "schema": "",
10
+ "columns": {
11
+ "id": {
12
+ "name": "id",
13
+ "type": "text",
14
+ "primaryKey": true,
15
+ "notNull": true
16
+ },
17
+ "account_id": {
18
+ "name": "account_id",
19
+ "type": "text",
20
+ "primaryKey": false,
21
+ "notNull": true
22
+ },
23
+ "provider_id": {
24
+ "name": "provider_id",
25
+ "type": "text",
26
+ "primaryKey": false,
27
+ "notNull": true
28
+ },
29
+ "user_id": {
30
+ "name": "user_id",
31
+ "type": "text",
32
+ "primaryKey": false,
33
+ "notNull": true
34
+ },
35
+ "access_token": {
36
+ "name": "access_token",
37
+ "type": "text",
38
+ "primaryKey": false,
39
+ "notNull": false
40
+ },
41
+ "refresh_token": {
42
+ "name": "refresh_token",
43
+ "type": "text",
44
+ "primaryKey": false,
45
+ "notNull": false
46
+ },
47
+ "id_token": {
48
+ "name": "id_token",
49
+ "type": "text",
50
+ "primaryKey": false,
51
+ "notNull": false
52
+ },
53
+ "access_token_expires_at": {
54
+ "name": "access_token_expires_at",
55
+ "type": "timestamp",
56
+ "primaryKey": false,
57
+ "notNull": false
58
+ },
59
+ "refresh_token_expires_at": {
60
+ "name": "refresh_token_expires_at",
61
+ "type": "timestamp",
62
+ "primaryKey": false,
63
+ "notNull": false
64
+ },
65
+ "scope": {
66
+ "name": "scope",
67
+ "type": "text",
68
+ "primaryKey": false,
69
+ "notNull": false
70
+ },
71
+ "password": {
72
+ "name": "password",
73
+ "type": "text",
74
+ "primaryKey": false,
75
+ "notNull": false
76
+ },
77
+ "created_at": {
78
+ "name": "created_at",
79
+ "type": "timestamp",
80
+ "primaryKey": false,
81
+ "notNull": true,
82
+ "default": "now()"
83
+ },
84
+ "updated_at": {
85
+ "name": "updated_at",
86
+ "type": "timestamp",
87
+ "primaryKey": false,
88
+ "notNull": true
89
+ }
90
+ },
91
+ "indexes": {
92
+ "account_userId_idx": {
93
+ "name": "account_userId_idx",
94
+ "columns": [
95
+ {
96
+ "expression": "user_id",
97
+ "isExpression": false,
98
+ "asc": true,
99
+ "nulls": "last"
100
+ }
101
+ ],
102
+ "isUnique": false,
103
+ "with": {},
104
+ "method": "btree",
105
+ "concurrently": false
106
+ }
107
+ },
108
+ "foreignKeys": {
109
+ "account_user_id_user_id_fk": {
110
+ "name": "account_user_id_user_id_fk",
111
+ "tableFrom": "account",
112
+ "columnsFrom": [
113
+ "user_id"
114
+ ],
115
+ "tableTo": "user",
116
+ "columnsTo": [
117
+ "id"
118
+ ],
119
+ "onUpdate": "no action",
120
+ "onDelete": "cascade"
121
+ }
122
+ },
123
+ "compositePrimaryKeys": {},
124
+ "uniqueConstraints": {},
125
+ "policies": {},
126
+ "checkConstraints": {},
127
+ "isRLSEnabled": false
128
+ },
129
+ "public.friends": {
130
+ "name": "friends",
131
+ "schema": "",
132
+ "columns": {
133
+ "user_id": {
134
+ "name": "user_id",
135
+ "type": "text",
136
+ "primaryKey": false,
137
+ "notNull": true
138
+ },
139
+ "friend_id": {
140
+ "name": "friend_id",
141
+ "type": "text",
142
+ "primaryKey": false,
143
+ "notNull": true
144
+ },
145
+ "status": {
146
+ "name": "status",
147
+ "type": "friend_status",
148
+ "typeSchema": "public",
149
+ "primaryKey": false,
150
+ "notNull": true,
151
+ "default": "'PENDING'"
152
+ },
153
+ "created_at": {
154
+ "name": "created_at",
155
+ "type": "timestamp",
156
+ "primaryKey": false,
157
+ "notNull": true,
158
+ "default": "now()"
159
+ }
160
+ },
161
+ "indexes": {},
162
+ "foreignKeys": {
163
+ "friends_user_id_user_id_fk": {
164
+ "name": "friends_user_id_user_id_fk",
165
+ "tableFrom": "friends",
166
+ "columnsFrom": [
167
+ "user_id"
168
+ ],
169
+ "tableTo": "user",
170
+ "columnsTo": [
171
+ "id"
172
+ ],
173
+ "onUpdate": "no action",
174
+ "onDelete": "no action"
175
+ },
176
+ "friends_friend_id_user_id_fk": {
177
+ "name": "friends_friend_id_user_id_fk",
178
+ "tableFrom": "friends",
179
+ "columnsFrom": [
180
+ "friend_id"
181
+ ],
182
+ "tableTo": "user",
183
+ "columnsTo": [
184
+ "id"
185
+ ],
186
+ "onUpdate": "no action",
187
+ "onDelete": "no action"
188
+ }
189
+ },
190
+ "compositePrimaryKeys": {
191
+ "friends_user_id_friend_id_pk": {
192
+ "name": "friends_user_id_friend_id_pk",
193
+ "columns": [
194
+ "user_id",
195
+ "friend_id"
196
+ ]
197
+ }
198
+ },
199
+ "uniqueConstraints": {},
200
+ "policies": {},
201
+ "checkConstraints": {},
202
+ "isRLSEnabled": false
203
+ },
204
+ "public.games": {
205
+ "name": "games",
206
+ "schema": "",
207
+ "columns": {
208
+ "id": {
209
+ "name": "id",
210
+ "type": "uuid",
211
+ "primaryKey": true,
212
+ "notNull": true
213
+ },
214
+ "white_id": {
215
+ "name": "white_id",
216
+ "type": "text",
217
+ "primaryKey": false,
218
+ "notNull": true
219
+ },
220
+ "black_id": {
221
+ "name": "black_id",
222
+ "type": "text",
223
+ "primaryKey": false,
224
+ "notNull": true
225
+ },
226
+ "winner_id": {
227
+ "name": "winner_id",
228
+ "type": "text",
229
+ "primaryKey": false,
230
+ "notNull": false
231
+ },
232
+ "status": {
233
+ "name": "status",
234
+ "type": "status",
235
+ "typeSchema": "public",
236
+ "primaryKey": false,
237
+ "notNull": true
238
+ },
239
+ "result": {
240
+ "name": "result",
241
+ "type": "result",
242
+ "typeSchema": "public",
243
+ "primaryKey": false,
244
+ "notNull": true,
245
+ "default": "'d'"
246
+ },
247
+ "time_control": {
248
+ "name": "time_control",
249
+ "type": "varchar(20)",
250
+ "primaryKey": false,
251
+ "notNull": true
252
+ },
253
+ "pgn": {
254
+ "name": "pgn",
255
+ "type": "text",
256
+ "primaryKey": false,
257
+ "notNull": true
258
+ },
259
+ "move_times": {
260
+ "name": "move_times",
261
+ "type": "jsonb",
262
+ "primaryKey": false,
263
+ "notNull": true,
264
+ "default": "'[]'::jsonb"
265
+ },
266
+ "fen": {
267
+ "name": "fen",
268
+ "type": "varchar(2048)",
269
+ "primaryKey": false,
270
+ "notNull": true
271
+ },
272
+ "white_time_left_ms": {
273
+ "name": "white_time_left_ms",
274
+ "type": "integer",
275
+ "primaryKey": false,
276
+ "notNull": true
277
+ },
278
+ "black_time_left_ms": {
279
+ "name": "black_time_left_ms",
280
+ "type": "integer",
281
+ "primaryKey": false,
282
+ "notNull": true
283
+ },
284
+ "white_rating": {
285
+ "name": "white_rating",
286
+ "type": "integer",
287
+ "primaryKey": false,
288
+ "notNull": true,
289
+ "default": 1000
290
+ },
291
+ "black_rating": {
292
+ "name": "black_rating",
293
+ "type": "integer",
294
+ "primaryKey": false,
295
+ "notNull": true,
296
+ "default": 1000
297
+ },
298
+ "white_diff": {
299
+ "name": "white_diff",
300
+ "type": "integer",
301
+ "primaryKey": false,
302
+ "notNull": true,
303
+ "default": 0
304
+ },
305
+ "black_diff": {
306
+ "name": "black_diff",
307
+ "type": "integer",
308
+ "primaryKey": false,
309
+ "notNull": true,
310
+ "default": 0
311
+ },
312
+ "captured_by_white": {
313
+ "name": "captured_by_white",
314
+ "type": "jsonb",
315
+ "primaryKey": false,
316
+ "notNull": true,
317
+ "default": "'[]'::jsonb"
318
+ },
319
+ "captured_by_black": {
320
+ "name": "captured_by_black",
321
+ "type": "jsonb",
322
+ "primaryKey": false,
323
+ "notNull": true,
324
+ "default": "'[]'::jsonb"
325
+ },
326
+ "chat_logs": {
327
+ "name": "chat_logs",
328
+ "type": "jsonb",
329
+ "primaryKey": false,
330
+ "notNull": true,
331
+ "default": "'[]'::jsonb"
332
+ },
333
+ "created_at": {
334
+ "name": "created_at",
335
+ "type": "timestamp",
336
+ "primaryKey": false,
337
+ "notNull": true,
338
+ "default": "now()"
339
+ },
340
+ "updated_at": {
341
+ "name": "updated_at",
342
+ "type": "timestamp",
343
+ "primaryKey": false,
344
+ "notNull": true,
345
+ "default": "now()"
346
+ }
347
+ },
348
+ "indexes": {
349
+ "games_white_id_idx": {
350
+ "name": "games_white_id_idx",
351
+ "columns": [
352
+ {
353
+ "expression": "white_id",
354
+ "isExpression": false,
355
+ "asc": true,
356
+ "nulls": "last"
357
+ }
358
+ ],
359
+ "isUnique": false,
360
+ "with": {},
361
+ "method": "btree",
362
+ "concurrently": false
363
+ },
364
+ "games_black_id_idx": {
365
+ "name": "games_black_id_idx",
366
+ "columns": [
367
+ {
368
+ "expression": "black_id",
369
+ "isExpression": false,
370
+ "asc": true,
371
+ "nulls": "last"
372
+ }
373
+ ],
374
+ "isUnique": false,
375
+ "with": {},
376
+ "method": "btree",
377
+ "concurrently": false
378
+ },
379
+ "games_created_at_idx": {
380
+ "name": "games_created_at_idx",
381
+ "columns": [
382
+ {
383
+ "expression": "created_at",
384
+ "isExpression": false,
385
+ "asc": true,
386
+ "nulls": "last"
387
+ }
388
+ ],
389
+ "isUnique": false,
390
+ "with": {},
391
+ "method": "btree",
392
+ "concurrently": false
393
+ },
394
+ "games_winner_id_idx": {
395
+ "name": "games_winner_id_idx",
396
+ "columns": [
397
+ {
398
+ "expression": "winner_id",
399
+ "isExpression": false,
400
+ "asc": true,
401
+ "nulls": "last"
402
+ }
403
+ ],
404
+ "isUnique": false,
405
+ "with": {},
406
+ "method": "btree",
407
+ "concurrently": false
408
+ }
409
+ },
410
+ "foreignKeys": {
411
+ "games_white_id_user_id_fk": {
412
+ "name": "games_white_id_user_id_fk",
413
+ "tableFrom": "games",
414
+ "columnsFrom": [
415
+ "white_id"
416
+ ],
417
+ "tableTo": "user",
418
+ "columnsTo": [
419
+ "id"
420
+ ],
421
+ "onUpdate": "no action",
422
+ "onDelete": "no action"
423
+ },
424
+ "games_black_id_user_id_fk": {
425
+ "name": "games_black_id_user_id_fk",
426
+ "tableFrom": "games",
427
+ "columnsFrom": [
428
+ "black_id"
429
+ ],
430
+ "tableTo": "user",
431
+ "columnsTo": [
432
+ "id"
433
+ ],
434
+ "onUpdate": "no action",
435
+ "onDelete": "no action"
436
+ },
437
+ "games_winner_id_user_id_fk": {
438
+ "name": "games_winner_id_user_id_fk",
439
+ "tableFrom": "games",
440
+ "columnsFrom": [
441
+ "winner_id"
442
+ ],
443
+ "tableTo": "user",
444
+ "columnsTo": [
445
+ "id"
446
+ ],
447
+ "onUpdate": "no action",
448
+ "onDelete": "no action"
449
+ }
450
+ },
451
+ "compositePrimaryKeys": {},
452
+ "uniqueConstraints": {},
453
+ "policies": {},
454
+ "checkConstraints": {},
455
+ "isRLSEnabled": false
456
+ },
457
+ "public.messages": {
458
+ "name": "messages",
459
+ "schema": "",
460
+ "columns": {
461
+ "id": {
462
+ "name": "id",
463
+ "type": "uuid",
464
+ "primaryKey": true,
465
+ "notNull": true,
466
+ "default": "gen_random_uuid()"
467
+ },
468
+ "sender_id": {
469
+ "name": "sender_id",
470
+ "type": "text",
471
+ "primaryKey": false,
472
+ "notNull": true
473
+ },
474
+ "receiver_id": {
475
+ "name": "receiver_id",
476
+ "type": "text",
477
+ "primaryKey": false,
478
+ "notNull": true
479
+ },
480
+ "content": {
481
+ "name": "content",
482
+ "type": "text",
483
+ "primaryKey": false,
484
+ "notNull": true
485
+ },
486
+ "created_at": {
487
+ "name": "created_at",
488
+ "type": "timestamp",
489
+ "primaryKey": false,
490
+ "notNull": true,
491
+ "default": "now()"
492
+ },
493
+ "read": {
494
+ "name": "read",
495
+ "type": "boolean",
496
+ "primaryKey": false,
497
+ "notNull": true,
498
+ "default": false
499
+ }
500
+ },
501
+ "indexes": {
502
+ "messages_sender_id_idx": {
503
+ "name": "messages_sender_id_idx",
504
+ "columns": [
505
+ {
506
+ "expression": "sender_id",
507
+ "isExpression": false,
508
+ "asc": true,
509
+ "nulls": "last"
510
+ }
511
+ ],
512
+ "isUnique": false,
513
+ "with": {},
514
+ "method": "btree",
515
+ "concurrently": false
516
+ },
517
+ "messages_receiver_id_idx": {
518
+ "name": "messages_receiver_id_idx",
519
+ "columns": [
520
+ {
521
+ "expression": "receiver_id",
522
+ "isExpression": false,
523
+ "asc": true,
524
+ "nulls": "last"
525
+ }
526
+ ],
527
+ "isUnique": false,
528
+ "with": {},
529
+ "method": "btree",
530
+ "concurrently": false
531
+ },
532
+ "messages_created_at_idx": {
533
+ "name": "messages_created_at_idx",
534
+ "columns": [
535
+ {
536
+ "expression": "created_at",
537
+ "isExpression": false,
538
+ "asc": true,
539
+ "nulls": "last"
540
+ }
541
+ ],
542
+ "isUnique": false,
543
+ "with": {},
544
+ "method": "btree",
545
+ "concurrently": false
546
+ }
547
+ },
548
+ "foreignKeys": {
549
+ "messages_sender_id_user_id_fk": {
550
+ "name": "messages_sender_id_user_id_fk",
551
+ "tableFrom": "messages",
552
+ "columnsFrom": [
553
+ "sender_id"
554
+ ],
555
+ "tableTo": "user",
556
+ "columnsTo": [
557
+ "id"
558
+ ],
559
+ "onUpdate": "no action",
560
+ "onDelete": "no action"
561
+ },
562
+ "messages_receiver_id_user_id_fk": {
563
+ "name": "messages_receiver_id_user_id_fk",
564
+ "tableFrom": "messages",
565
+ "columnsFrom": [
566
+ "receiver_id"
567
+ ],
568
+ "tableTo": "user",
569
+ "columnsTo": [
570
+ "id"
571
+ ],
572
+ "onUpdate": "no action",
573
+ "onDelete": "no action"
574
+ }
575
+ },
576
+ "compositePrimaryKeys": {},
577
+ "uniqueConstraints": {},
578
+ "policies": {},
579
+ "checkConstraints": {},
580
+ "isRLSEnabled": false
581
+ },
582
+ "public.session": {
583
+ "name": "session",
584
+ "schema": "",
585
+ "columns": {
586
+ "id": {
587
+ "name": "id",
588
+ "type": "text",
589
+ "primaryKey": true,
590
+ "notNull": true
591
+ },
592
+ "expires_at": {
593
+ "name": "expires_at",
594
+ "type": "timestamp",
595
+ "primaryKey": false,
596
+ "notNull": true
597
+ },
598
+ "token": {
599
+ "name": "token",
600
+ "type": "text",
601
+ "primaryKey": false,
602
+ "notNull": true
603
+ },
604
+ "created_at": {
605
+ "name": "created_at",
606
+ "type": "timestamp",
607
+ "primaryKey": false,
608
+ "notNull": true,
609
+ "default": "now()"
610
+ },
611
+ "updated_at": {
612
+ "name": "updated_at",
613
+ "type": "timestamp",
614
+ "primaryKey": false,
615
+ "notNull": true
616
+ },
617
+ "ip_address": {
618
+ "name": "ip_address",
619
+ "type": "text",
620
+ "primaryKey": false,
621
+ "notNull": false
622
+ },
623
+ "user_agent": {
624
+ "name": "user_agent",
625
+ "type": "text",
626
+ "primaryKey": false,
627
+ "notNull": false
628
+ },
629
+ "user_id": {
630
+ "name": "user_id",
631
+ "type": "text",
632
+ "primaryKey": false,
633
+ "notNull": true
634
+ }
635
+ },
636
+ "indexes": {
637
+ "session_userId_idx": {
638
+ "name": "session_userId_idx",
639
+ "columns": [
640
+ {
641
+ "expression": "user_id",
642
+ "isExpression": false,
643
+ "asc": true,
644
+ "nulls": "last"
645
+ }
646
+ ],
647
+ "isUnique": false,
648
+ "with": {},
649
+ "method": "btree",
650
+ "concurrently": false
651
+ }
652
+ },
653
+ "foreignKeys": {
654
+ "session_user_id_user_id_fk": {
655
+ "name": "session_user_id_user_id_fk",
656
+ "tableFrom": "session",
657
+ "columnsFrom": [
658
+ "user_id"
659
+ ],
660
+ "tableTo": "user",
661
+ "columnsTo": [
662
+ "id"
663
+ ],
664
+ "onUpdate": "no action",
665
+ "onDelete": "cascade"
666
+ }
667
+ },
668
+ "compositePrimaryKeys": {},
669
+ "uniqueConstraints": {
670
+ "session_token_unique": {
671
+ "name": "session_token_unique",
672
+ "columns": [
673
+ "token"
674
+ ],
675
+ "nullsNotDistinct": false
676
+ }
677
+ },
678
+ "policies": {},
679
+ "checkConstraints": {},
680
+ "isRLSEnabled": false
681
+ },
682
+ "public.user": {
683
+ "name": "user",
684
+ "schema": "",
685
+ "columns": {
686
+ "id": {
687
+ "name": "id",
688
+ "type": "text",
689
+ "primaryKey": true,
690
+ "notNull": true
691
+ },
692
+ "name": {
693
+ "name": "name",
694
+ "type": "text",
695
+ "primaryKey": false,
696
+ "notNull": true
697
+ },
698
+ "username": {
699
+ "name": "username",
700
+ "type": "varchar(50)",
701
+ "primaryKey": false,
702
+ "notNull": true
703
+ },
704
+ "email": {
705
+ "name": "email",
706
+ "type": "text",
707
+ "primaryKey": false,
708
+ "notNull": true
709
+ },
710
+ "email_verified": {
711
+ "name": "email_verified",
712
+ "type": "boolean",
713
+ "primaryKey": false,
714
+ "notNull": true,
715
+ "default": false
716
+ },
717
+ "rating": {
718
+ "name": "rating",
719
+ "type": "integer",
720
+ "primaryKey": false,
721
+ "notNull": true,
722
+ "default": 1000
723
+ },
724
+ "wins": {
725
+ "name": "wins",
726
+ "type": "integer",
727
+ "primaryKey": false,
728
+ "notNull": true,
729
+ "default": 0
730
+ },
731
+ "losses": {
732
+ "name": "losses",
733
+ "type": "integer",
734
+ "primaryKey": false,
735
+ "notNull": true,
736
+ "default": 0
737
+ },
738
+ "draws": {
739
+ "name": "draws",
740
+ "type": "integer",
741
+ "primaryKey": false,
742
+ "notNull": true,
743
+ "default": 0
744
+ },
745
+ "image": {
746
+ "name": "image",
747
+ "type": "text",
748
+ "primaryKey": false,
749
+ "notNull": false
750
+ },
751
+ "created_at": {
752
+ "name": "created_at",
753
+ "type": "timestamp",
754
+ "primaryKey": false,
755
+ "notNull": true,
756
+ "default": "now()"
757
+ },
758
+ "updated_at": {
759
+ "name": "updated_at",
760
+ "type": "timestamp",
761
+ "primaryKey": false,
762
+ "notNull": true,
763
+ "default": "now()"
764
+ }
765
+ },
766
+ "indexes": {
767
+ "users_search_trgm_idx": {
768
+ "name": "users_search_trgm_idx",
769
+ "columns": [
770
+ {
771
+ "expression": "(\"username\" || ' ' || \"name\") gin_trgm_ops",
772
+ "isExpression": true,
773
+ "asc": true,
774
+ "nulls": "last"
775
+ }
776
+ ],
777
+ "isUnique": false,
778
+ "with": {},
779
+ "method": "gin",
780
+ "concurrently": false
781
+ }
782
+ },
783
+ "foreignKeys": {},
784
+ "compositePrimaryKeys": {},
785
+ "uniqueConstraints": {
786
+ "user_username_unique": {
787
+ "name": "user_username_unique",
788
+ "columns": [
789
+ "username"
790
+ ],
791
+ "nullsNotDistinct": false
792
+ },
793
+ "user_email_unique": {
794
+ "name": "user_email_unique",
795
+ "columns": [
796
+ "email"
797
+ ],
798
+ "nullsNotDistinct": false
799
+ }
800
+ },
801
+ "policies": {},
802
+ "checkConstraints": {},
803
+ "isRLSEnabled": false
804
+ },
805
+ "public.verification": {
806
+ "name": "verification",
807
+ "schema": "",
808
+ "columns": {
809
+ "id": {
810
+ "name": "id",
811
+ "type": "text",
812
+ "primaryKey": true,
813
+ "notNull": true
814
+ },
815
+ "identifier": {
816
+ "name": "identifier",
817
+ "type": "text",
818
+ "primaryKey": false,
819
+ "notNull": true
820
+ },
821
+ "value": {
822
+ "name": "value",
823
+ "type": "text",
824
+ "primaryKey": false,
825
+ "notNull": true
826
+ },
827
+ "expires_at": {
828
+ "name": "expires_at",
829
+ "type": "timestamp",
830
+ "primaryKey": false,
831
+ "notNull": true
832
+ },
833
+ "created_at": {
834
+ "name": "created_at",
835
+ "type": "timestamp",
836
+ "primaryKey": false,
837
+ "notNull": true,
838
+ "default": "now()"
839
+ },
840
+ "updated_at": {
841
+ "name": "updated_at",
842
+ "type": "timestamp",
843
+ "primaryKey": false,
844
+ "notNull": true,
845
+ "default": "now()"
846
+ }
847
+ },
848
+ "indexes": {
849
+ "verification_identifier_idx": {
850
+ "name": "verification_identifier_idx",
851
+ "columns": [
852
+ {
853
+ "expression": "identifier",
854
+ "isExpression": false,
855
+ "asc": true,
856
+ "nulls": "last"
857
+ }
858
+ ],
859
+ "isUnique": false,
860
+ "with": {},
861
+ "method": "btree",
862
+ "concurrently": false
863
+ }
864
+ },
865
+ "foreignKeys": {},
866
+ "compositePrimaryKeys": {},
867
+ "uniqueConstraints": {},
868
+ "policies": {},
869
+ "checkConstraints": {},
870
+ "isRLSEnabled": false
871
+ }
872
+ },
873
+ "enums": {
874
+ "public.friend_status": {
875
+ "name": "friend_status",
876
+ "schema": "public",
877
+ "values": [
878
+ "PENDING",
879
+ "ACCEPTED",
880
+ "REJECTED",
881
+ "BLOCKED"
882
+ ]
883
+ },
884
+ "public.status": {
885
+ "name": "status",
886
+ "schema": "public",
887
+ "values": [
888
+ "IN_PROGRESS",
889
+ "CHECKMATE",
890
+ "RESIGN",
891
+ "DRAW",
892
+ "AGREEMENT",
893
+ "STALEMATE",
894
+ "INSUFFICIENT_MATERIAL",
895
+ "FIFTY_MOVE_RULE",
896
+ "THREEFOLD_REPETITION",
897
+ "TIME_OUT",
898
+ "ABANDONED"
899
+ ]
900
+ },
901
+ "public.result": {
902
+ "name": "result",
903
+ "schema": "public",
904
+ "values": [
905
+ "d",
906
+ "w",
907
+ "b"
908
+ ]
909
+ }
910
+ },
911
+ "schemas": {},
912
+ "views": {},
913
+ "sequences": {},
914
+ "roles": {},
915
+ "policies": {},
916
+ "_meta": {
917
+ "columns": {},
918
+ "schemas": {},
919
+ "tables": {}
920
+ }
921
+ }
chess-monolith/drizzle/meta/_journal.json CHANGED
@@ -29,6 +29,20 @@
29
  "when": 1774968691852,
30
  "tag": "0003_enable_trgm",
31
  "breakpoints": true
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
  }
33
  ]
34
  }
 
29
  "when": 1774968691852,
30
  "tag": "0003_enable_trgm",
31
  "breakpoints": true
32
+ },
33
+ {
34
+ "idx": 4,
35
+ "version": "7",
36
+ "when": 1775570671797,
37
+ "tag": "0004_nasty_gorilla_man",
38
+ "breakpoints": true
39
+ },
40
+ {
41
+ "idx": 5,
42
+ "version": "7",
43
+ "when": 1775570955536,
44
+ "tag": "0005_create_pg_trgm_extension",
45
+ "breakpoints": true
46
  }
47
  ]
48
  }
chess-monolith/package.json CHANGED
@@ -8,7 +8,7 @@
8
  "build": "npx tsc --build --force",
9
  "start": "node -r dotenv/config dist/index.js",
10
  "db:generate": "drizzle-kit generate",
11
- "db:push": "drizzle-kit push",
12
  "db:studio": "drizzle-kit studio",
13
  "seed": "tsx src/seed/seed-users.ts"
14
  },
@@ -42,5 +42,8 @@
42
  "nodemon": "^3.1.14",
43
  "tsx": "^4.21.0",
44
  "typescript": "^5.9.3"
 
 
 
45
  }
46
  }
 
8
  "build": "npx tsc --build --force",
9
  "start": "node -r dotenv/config dist/index.js",
10
  "db:generate": "drizzle-kit generate",
11
+ "db:push": "tsx seed/setup-db.ts",
12
  "db:studio": "drizzle-kit studio",
13
  "seed": "tsx src/seed/seed-users.ts"
14
  },
 
42
  "nodemon": "^3.1.14",
43
  "tsx": "^4.21.0",
44
  "typescript": "^5.9.3"
45
+ },
46
+ "overrides": {
47
+ "esbuild": "^0.25.0"
48
  }
49
  }
chess-monolith/src/api/controller/friend-controller.ts CHANGED
@@ -4,7 +4,7 @@ import { toFetchHeaders } from "../../lib/utils/to-fetch-headers";
4
  import {
5
  sendFriendRequest,
6
  acceptFriendRequest,
7
- rejectFriendRequest,
8
  removeFriend,
9
  blockUser,
10
  getFriends,
@@ -110,7 +110,7 @@ export async function acceptRequest(req: Request, res: Response) {
110
  return res.json({ success: true });
111
  }
112
 
113
- export async function rejectRequest(req: Request, res: Response) {
114
  const session = await auth.api.getSession({
115
  headers: toFetchHeaders(req.headers),
116
  });
@@ -155,7 +155,7 @@ export async function rejectRequest(req: Request, res: Response) {
155
  .json({ error: "No pending friend request from this user" });
156
  }
157
 
158
- await rejectFriendRequest(session.user.id, targetUserId);
159
  return res.json({ success: true });
160
  }
161
 
@@ -261,6 +261,5 @@ export async function searchUsers(req: Request, res: Response) {
261
  session.user.id,
262
  );
263
 
264
- console.log({ query: req.query.q, result });
265
  return res.json({ success: true, data: result });
266
  }
 
4
  import {
5
  sendFriendRequest,
6
  acceptFriendRequest,
7
+ declineFriendRequest,
8
  removeFriend,
9
  blockUser,
10
  getFriends,
 
110
  return res.json({ success: true });
111
  }
112
 
113
+ export async function declineRequest(req: Request, res: Response) {
114
  const session = await auth.api.getSession({
115
  headers: toFetchHeaders(req.headers),
116
  });
 
155
  .json({ error: "No pending friend request from this user" });
156
  }
157
 
158
+ await declineFriendRequest(session.user.id, targetUserId);
159
  return res.json({ success: true });
160
  }
161
 
 
261
  session.user.id,
262
  );
263
 
 
264
  return res.json({ success: true, data: result });
265
  }
chess-monolith/src/api/repository/friend-repository.ts CHANGED
@@ -42,10 +42,9 @@ export async function acceptFriendRequest(userId: string, friendId: string) {
42
  .where(and(eq(friends.userId, friendId), eq(friends.friendId, userId)));
43
  }
44
 
45
- export async function rejectFriendRequest(userId: string, friendId: string) {
46
  await db
47
- .update(friends)
48
- .set({ status: "REJECTED" })
49
  .where(and(eq(friends.userId, friendId), eq(friends.friendId, userId)));
50
  }
51
 
@@ -141,6 +140,7 @@ export async function getFriendRequests(userId: string) {
141
  .innerJoin(u, eq(f.userId, u.id))
142
  .where(and(eq(f.friendId, userId), eq(f.status, "PENDING")));
143
  }
 
144
  export async function searchGlobalUsers(
145
  searchTerm: string,
146
  currentUserId: string,
 
42
  .where(and(eq(friends.userId, friendId), eq(friends.friendId, userId)));
43
  }
44
 
45
+ export async function declineFriendRequest(userId: string, friendId: string) {
46
  await db
47
+ .delete(friends)
 
48
  .where(and(eq(friends.userId, friendId), eq(friends.friendId, userId)));
49
  }
50
 
 
140
  .innerJoin(u, eq(f.userId, u.id))
141
  .where(and(eq(f.friendId, userId), eq(f.status, "PENDING")));
142
  }
143
+
144
  export async function searchGlobalUsers(
145
  searchTerm: string,
146
  currentUserId: string,
chess-monolith/src/api/routes/friend-router.ts CHANGED
@@ -2,7 +2,7 @@ import { Router } from "express";
2
  import {
3
  requestFriend,
4
  acceptRequest,
5
- rejectRequest,
6
  remove,
7
  block,
8
  listFriends,
@@ -17,8 +17,8 @@ friendRouter.get("/requests", listRequests);
17
  friendRouter.get("/search", searchUsers);
18
  friendRouter.post("/request", requestFriend);
19
  friendRouter.post("/accept", acceptRequest);
20
- friendRouter.post("/reject", rejectRequest);
21
- friendRouter.post("/remove", remove);
22
  friendRouter.post("/block", block);
23
 
24
  export default friendRouter;
 
2
  import {
3
  requestFriend,
4
  acceptRequest,
5
+ declineRequest,
6
  remove,
7
  block,
8
  listFriends,
 
17
  friendRouter.get("/search", searchUsers);
18
  friendRouter.post("/request", requestFriend);
19
  friendRouter.post("/accept", acceptRequest);
20
+ friendRouter.delete("/decline", declineRequest);
21
+ friendRouter.delete("/remove", remove);
22
  friendRouter.post("/block", block);
23
 
24
  export default friendRouter;
chess-monolith/src/infrastructure/db/schema.ts CHANGED
@@ -3,7 +3,6 @@ import {
3
  boolean,
4
  index,
5
  integer,
6
- json,
7
  jsonb,
8
  pgEnum,
9
  pgTable,
@@ -33,7 +32,6 @@ export const resultEnum = pgEnum("result", ["d", "w", "b"]);
33
  export const friendStatusEnum = pgEnum("friend_status", [
34
  "PENDING",
35
  "ACCEPTED",
36
- "REJECTED",
37
  "BLOCKED",
38
  ]);
39
 
 
3
  boolean,
4
  index,
5
  integer,
 
6
  jsonb,
7
  pgEnum,
8
  pgTable,
 
32
  export const friendStatusEnum = pgEnum("friend_status", [
33
  "PENDING",
34
  "ACCEPTED",
 
35
  "BLOCKED",
36
  ]);
37
 
chess-monolith/src/lib/auth.ts CHANGED
@@ -9,15 +9,11 @@ export const auth = betterAuth({
9
  emailAndPassword: {
10
  enabled: true,
11
  },
12
- advanced: {
13
- crossSubDomainCookies: {
14
- enabled: true,
15
- },
16
- },
17
  trustedOrigins: ["http://localhost:3000"],
18
  session: {
19
  expiresIn: 60 * 60 * 24 * 7,
20
- updateAge: 60 * 60 * 24,
21
  cookieCache: {
22
  enabled: true,
23
  maxAge: 60 * 60 * 24 * 7,
@@ -43,14 +39,14 @@ export const auth = betterAuth({
43
  },
44
  },
45
  },
46
- socialProviders: {
47
- github: {
48
- clientId: process.env.GITHUB_CLIENT_ID as string,
49
- clientSecret: process.env.GITHUB_CLIENT_SECRET as string,
50
- },
51
- google: {
52
- clientId: process.env.GOOGLE_CLIENT_ID as string,
53
- clientSecret: process.env.GOOGLE_CLIENT_SECRET as string,
54
- },
55
- },
56
  });
 
9
  emailAndPassword: {
10
  enabled: true,
11
  },
12
+
 
 
 
 
13
  trustedOrigins: ["http://localhost:3000"],
14
  session: {
15
  expiresIn: 60 * 60 * 24 * 7,
16
+ updateAge: 60 * 60 * 24 * 7,
17
  cookieCache: {
18
  enabled: true,
19
  maxAge: 60 * 60 * 24 * 7,
 
39
  },
40
  },
41
  },
42
+ // socialProviders: {
43
+ // github: {
44
+ // clientId: process.env.GITHUB_CLIENT_ID as string,
45
+ // clientSecret: process.env.GITHUB_CLIENT_SECRET as string,
46
+ // },
47
+ // google: {
48
+ // clientId: process.env.GOOGLE_CLIENT_ID as string,
49
+ // clientSecret: process.env.GOOGLE_CLIENT_SECRET as string,
50
+ // },
51
+ // },
52
  });
chess-monolith/src/seed/setup.ts ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import postgres from "postgres";
2
+ import "dotenv/config";
3
+
4
+ const sql = postgres(process.env.DATABASE_URL!);
5
+
6
+ async function main() {
7
+ try {
8
+ await sql`CREATE EXTENSION IF NOT EXISTS pg_trgm;`;
9
+ console.log("✅ Extension 'pg_trgm' created or already exists.");
10
+ } catch (error) {
11
+ console.error("❌ Failed to create extension:", error);
12
+ } finally {
13
+ process.exit(0);
14
+ }
15
+ }
16
+
17
+ main();
package.json DELETED
@@ -1,12 +0,0 @@
1
- {
2
- "name": "chess-app-root",
3
- "private": true,
4
- "workspaces": [
5
- "chess-frontend",
6
- "chess-monolith",
7
- "types"
8
- ],
9
- "dependencies": {
10
- "zod": "^4.3.6"
11
- }
12
- }