Merge remote-tracking branch 'origin/dev' into dev

# Conflicts:
#	prisma/schema.prisma
This commit is contained in:
timhaller 2023-12-05 23:24:00 +01:00
commit f2a2abbad7
10 changed files with 107 additions and 35 deletions

1
.gitignore vendored
View File

@ -37,3 +37,4 @@ yarn-error.log*
next-env.d.ts
env
/.idea/

5
.idea/.gitignore vendored
View File

@ -1,5 +0,0 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/

View File

@ -1,12 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/.tmp" />
<excludeFolder url="file://$MODULE_DIR$/temp" />
<excludeFolder url="file://$MODULE_DIR$/tmp" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/calendrier-avant.iml" filepath="$PROJECT_DIR$/.idea/calendrier-avant.iml" />
</modules>
</component>
</project>

View File

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

36
app/api/me/route.ts Normal file
View File

@ -0,0 +1,36 @@
import {NextRequest, NextResponse} from "next/server";
import prisma from "@/lib/prisma";
export async function GET(req: NextRequest){
const key = req.nextUrl.searchParams.get("key");
if(!key) return NextResponse.json({error: "No key provided"}, {status: 400});
const user = await prisma.users.findUnique({
select: {
id: true,
firstName: true,
lastName: true,
isTeacher: true,
test: {
select: {
testOn: true
}
}
},
where: {
key
}
});
if(!user) return NextResponse.json({error: "Key not found"}, {status: 404});
return NextResponse.json({
id: user.id,
firstName: user.firstName,
lastName: user.lastName,
isTeacher: user.isTeacher,
testOn: user.test?.testOn
});
}

38
app/api/test/route.ts Normal file
View File

@ -0,0 +1,38 @@
import {NextRequest, NextResponse} from "next/server";
import prisma from "@/lib/prisma";
export async function GET(req: NextRequest){
const date = req.nextUrl.searchParams.get("date");
const test = await prisma.test.findFirst({
select: {
id: true,
testOn: true,
testOf: {
select: {
id: true,
firstName: true,
lastName: true,
isTeacher: true
}
}
},
where: {
testOn: (date ? new Date(date) : new Date())
}
});
if(!test){
return NextResponse.json({error: "Test not found"}, {status: 404});
}
return NextResponse.json({
id: test.id,
testOn: test.testOn,
testOf: {
firstName: test.testOf.firstName,
lastName: test.testOf.lastName,
isTeacher: test.testOf.isTeacher
}
});
}

View File

@ -1,12 +1,18 @@
'use client';
import { useState } from 'react';
import { useState, useEffect } from 'react';
import { useRouter } from 'next/navigation';
export default function Home() {
const [password, setPassword] = useState('');
const router = useRouter();
useEffect(() => {
if (localStorage.getItem('@password')) {
router.push('/play');
}
}, [router]);
function handleSubmit(event: React.FormEvent<HTMLFormElement>) {
event.preventDefault();
@ -15,9 +21,9 @@ export default function Home() {
}
return (
<div className={""}>
<h1 className={"border-l-blue-600"}>Calendrier-avent</h1>
<p>Please enter the password :</p>
<div className={''}>
<h1 className={'border-l-blue-600'}>Calendrier-avent</h1>
<p>Merci d'entrer votre clé :</p>
<form onSubmit={handleSubmit}>
<input type="password" id="password" name="password" value={password} onChange={(e) => setPassword(e.target.value)}></input>
<input type="submit" value="Submit"></input>

21
package-lock.json generated
View File

@ -21,6 +21,7 @@
"react-dom": "^18",
"socket.io": "^4.7.2",
"socket.io-client": "^4.7.2",
"swr": "^2.2.4",
"tailwind-merge": "^2.1.0",
"tailwindcss-animate": "^1.0.7"
},
@ -4199,6 +4200,18 @@
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/swr": {
"version": "2.2.4",
"resolved": "https://registry.npmjs.org/swr/-/swr-2.2.4.tgz",
"integrity": "sha512-njiZ/4RiIhoOlAaLYDqwz5qH/KZXVilRLvomrx83HjzCWTfa+InyfAjv05PSFxnmLzZkNO9ZfvgoqzAaEI4sGQ==",
"dependencies": {
"client-only": "^0.0.1",
"use-sync-external-store": "^1.2.0"
},
"peerDependencies": {
"react": "^16.11.0 || ^17.0.0 || ^18.0.0"
}
},
"node_modules/tailwind-merge": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/tailwind-merge/-/tailwind-merge-2.1.0.tgz",
@ -4495,6 +4508,14 @@
"punycode": "^2.1.0"
}
},
"node_modules/use-sync-external-store": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/use-sync-external-store/-/use-sync-external-store-1.2.0.tgz",
"integrity": "sha512-eEgnFxGQ1Ife9bzYs6VLi8/4X6CObHMw9Qr9tPY43iKwsPw8xE8+EFsf/2cFZ5S3esXgpWgtSCtLNS41F+sKPA==",
"peerDependencies": {
"react": "^16.8.0 || ^17.0.0 || ^18.0.0"
}
},
"node_modules/util-deprecate": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz",

View File

@ -22,6 +22,7 @@
"react-dom": "^18",
"socket.io": "^4.7.2",
"socket.io-client": "^4.7.2",
"swr": "^2.2.4",
"tailwind-merge": "^2.1.0",
"tailwindcss-animate": "^1.0.7"
},