-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #37 from RuffByte/KL-UserStats
- Loading branch information
Showing
26 changed files
with
1,079 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 0 additions & 19 deletions
19
prisma/migrations/20241006114925_add_userid_to_gameentry/migration.sql
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
-- CreateTable | ||
CREATE TABLE "Session" ( | ||
"id" TEXT NOT NULL, | ||
"userId" TEXT NOT NULL, | ||
"expiresAt" TIMESTAMP(3) NOT NULL, | ||
|
||
CONSTRAINT "Session_pkey" PRIMARY KEY ("id") | ||
); | ||
|
||
-- CreateTable | ||
CREATE TABLE "PasswordResetToken" ( | ||
"id" TEXT NOT NULL, | ||
"userId" TEXT NOT NULL, | ||
"token" TEXT NOT NULL, | ||
"expiresAt" TIMESTAMP(3) NOT NULL, | ||
|
||
CONSTRAINT "PasswordResetToken_pkey" PRIMARY KEY ("id") | ||
); | ||
|
||
-- CreateTable | ||
CREATE TABLE "User" ( | ||
"id" TEXT NOT NULL, | ||
"email" TEXT NOT NULL, | ||
"name" TEXT NOT NULL, | ||
"role" TEXT, | ||
"hashedPassword" TEXT, | ||
"picture" TEXT, | ||
"totalGames" INTEGER NOT NULL DEFAULT 0, | ||
"totalTime" DOUBLE PRECISION NOT NULL DEFAULT 0.0, | ||
|
||
CONSTRAINT "User_pkey" PRIMARY KEY ("id") | ||
); | ||
|
||
-- CreateTable | ||
CREATE TABLE "UserStats" ( | ||
"id" TEXT NOT NULL, | ||
"userId" TEXT NOT NULL, | ||
"mode" TEXT NOT NULL, | ||
"category" TEXT NOT NULL, | ||
"avgLpm" DOUBLE PRECISION NOT NULL DEFAULT 0.0, | ||
"avgAccuracy" DOUBLE PRECISION NOT NULL DEFAULT 0.0, | ||
"totalGames" INTEGER NOT NULL DEFAULT 0, | ||
"totalTime" DOUBLE PRECISION NOT NULL DEFAULT 0.0, | ||
|
||
CONSTRAINT "UserStats_pkey" PRIMARY KEY ("id") | ||
); | ||
|
||
-- CreateTable | ||
CREATE TABLE "GameEntry" ( | ||
"id" TEXT NOT NULL, | ||
"userId" TEXT NOT NULL, | ||
"mode" TEXT NOT NULL, | ||
"language" TEXT NOT NULL, | ||
"wpm" DOUBLE PRECISION NOT NULL, | ||
"rawWpm" DOUBLE PRECISION NOT NULL, | ||
"lpm" DOUBLE PRECISION NOT NULL, | ||
"rawLpm" DOUBLE PRECISION NOT NULL, | ||
"totalChar" INTEGER NOT NULL, | ||
"totalClicks" INTEGER NOT NULL, | ||
"totalTime" DOUBLE PRECISION NOT NULL, | ||
"accuracy" DOUBLE PRECISION NOT NULL, | ||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
"targetSize" INTEGER NOT NULL, | ||
|
||
CONSTRAINT "GameEntry_pkey" PRIMARY KEY ("id") | ||
); | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "PasswordResetToken_token_key" ON "PasswordResetToken"("token"); | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "User_email_key" ON "User"("email"); | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "User_name_key" ON "User"("name"); | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "UserStats_userId_mode_category_key" ON "UserStats"("userId", "mode", "category"); | ||
|
||
-- CreateIndex | ||
CREATE INDEX "GameEntry_lpm_userId_idx" ON "GameEntry"("lpm", "userId"); | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "Session" ADD CONSTRAINT "Session_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "PasswordResetToken" ADD CONSTRAINT "PasswordResetToken_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "UserStats" ADD CONSTRAINT "UserStats_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "GameEntry" ADD CONSTRAINT "GameEntry_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE; |
2 changes: 2 additions & 0 deletions
2
prisma/migrations/20241007111409_added_user_date_joined/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
-- AlterTable | ||
ALTER TABLE "User" ADD COLUMN "joinedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP; |
5 changes: 5 additions & 0 deletions
5
prisma/migrations/20241008044333_added_best_entry/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
-- AlterTable | ||
ALTER TABLE "UserStats" ADD COLUMN "bestGameEntryId" TEXT; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "UserStats" ADD CONSTRAINT "UserStats_bestGameEntryId_fkey" FOREIGN KEY ("bestGameEntryId") REFERENCES "GameEntry"("id") ON DELETE SET NULL ON UPDATE CASCADE; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
//this is just a function in case we manually invalidate a score and need to recalc some1s stats |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
:root { | ||
--background: 233 18% 18%; /* catppuccin clone */ | ||
--secondary: 274 71% 77%; | ||
--foreground: 317 76% 84%; | ||
--tertiary: #000; | ||
--hover: 0 0% 100%; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/* Some awwwards site i stole */ | ||
|
||
:root { | ||
--background: 220 4% 13%; | ||
--secondary: 50 100% 96%; | ||
--foreground: 50 100% 96%; | ||
--tertiary: 0 0% 100%; | ||
--hover: 0 0% 100%; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// src/app/api/data/user.ts | ||
import { NextResponse } from 'next/server'; | ||
|
||
import { prisma } from '@/lib/prisma'; | ||
|
||
export async function GET(request: Request) { | ||
const { searchParams } = new URL(request.url); | ||
const name = searchParams.get('name'); | ||
|
||
if (!name) { | ||
return NextResponse.json({ error: 'Name is required' }, { status: 400 }); | ||
} | ||
|
||
const fullUser = await prisma.user.findUnique({ | ||
where: { name: name }, | ||
select: { | ||
id: true, | ||
email: true, | ||
name: true, | ||
role: true, | ||
picture: true, | ||
totalGames: true, | ||
totalTime: true, | ||
joinedAt: true, | ||
}, | ||
}); | ||
|
||
if (!fullUser) { | ||
return NextResponse.json( | ||
{ error: 'Full user data not found' }, | ||
{ status: 404 } | ||
); | ||
} | ||
|
||
const userStats = await prisma.userStats.findMany({ | ||
where: { userId: fullUser.id }, | ||
}); | ||
|
||
return NextResponse.json({ user: fullUser, stats: userStats }); | ||
} |
Oops, something went wrong.