fix: removed unused database fields & fix prisma errors

This commit is contained in:
Elie Baier 2023-12-20 10:20:21 +01:00
parent da3a9df402
commit b47b59f4cd
5 changed files with 12 additions and 23 deletions

View File

@ -8,7 +8,6 @@ export async function getGrade(testId: number, userId: number) {
grade: true, grade: true,
id: true, id: true,
testId: true, testId: true,
note: true,
createdAt: true, createdAt: true,
}, },
where: { where: {
@ -24,7 +23,6 @@ export async function addGrade(testId: number, userId: number, grade: number, no
const newGrade = await prisma.grade.create({ const newGrade = await prisma.grade.create({
data: { data: {
grade: grade, grade: grade,
note: note,
testId: testId, testId: testId,
userId: userId, userId: userId,
} }

View File

@ -16,7 +16,6 @@ export async function getActiveTest(date: Date) {
select: { select: {
id: true, id: true,
isActive: true, isActive: true,
isPassed: true,
testOf: { testOf: {
select: { select: {
id: true, id: true,
@ -30,7 +29,6 @@ export async function getActiveTest(date: Date) {
}, },
where: { where: {
isActive: true, isActive: true,
isPassed: false,
testOn: new Date(date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + (date.getDate().toString().length === 1 ? '0' + date.getDate() : date.getDate())), testOn: new Date(date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + (date.getDate().toString().length === 1 ? '0' + date.getDate() : date.getDate())),
}, },
}); });
@ -41,7 +39,6 @@ export async function getActiveTestWithGrade(date: Date, userId: number) {
select: { select: {
id: true, id: true,
isActive: true, isActive: true,
isPassed: true,
testOf: { testOf: {
select: { select: {
id: true, id: true,
@ -54,7 +51,6 @@ export async function getActiveTestWithGrade(date: Date, userId: number) {
select: { select: {
id: true, id: true,
grade: true, grade: true,
note: true,
createdAt: true, createdAt: true,
}, },
take: 1, take: 1,
@ -67,7 +63,6 @@ export async function getActiveTestWithGrade(date: Date, userId: number) {
}, },
where: { where: {
isActive: true, isActive: true,
isPassed: false,
testOn: new Date(date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + (date.getDate().toString().length === 1 ? '0' + date.getDate() : date.getDate())), testOn: new Date(date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + (date.getDate().toString().length === 1 ? '0' + date.getDate() : date.getDate())),
}, },
}); });

View File

@ -8,10 +8,9 @@ export default async function Dashboard() {
console.log(authSession); console.log(authSession);
if (!authSession) return redirect('/'); if (!authSession) return redirect('/');
const tests = await prisma.test.findMany({ select: { isActive: true, isPassed: true, id: true, testOf: { select: { id: true, firstName: true, lastName: true, isTeacher: true } } } }); const tests = await prisma.test.findMany({ select: { isActive: true, id: true, testOf: { select: { id: true, firstName: true, lastName: true, isTeacher: true } } } });
const activeTests = tests.filter((test) => test.isActive); const activeTests = tests.filter((test) => test.isActive);
const passedTests = tests.filter((test) => test.isPassed);
return ( return (
<div> <div>

View File

@ -24,11 +24,10 @@ export default function Page({ params }: { params: { id: string } }) {
useEffect(() => { useEffect(() => {
featchResults(testId); featchResults(testId);
}, [testId]);
setTimeout(() => { setTimeout(() => {
featchResults(testId); featchResults(testId);
}, 5000); }, 5000);
}, [testId]);
return ( return (
<div className={'p-4 md:p-12 w-full h-screen bg-black flex flex-col justify-between gap-y-4'}> <div className={'p-4 md:p-12 w-full h-screen bg-black flex flex-col justify-between gap-y-4'}>

View File

@ -14,6 +14,7 @@ model Users {
firstName String firstName String
lastName String lastName String
isTeacher Boolean @default(false) isTeacher Boolean @default(false)
isAdmin Boolean @default(false)
createdAt DateTime @default(now()) createdAt DateTime @default(now())
grades Grade[] grades Grade[]
test Test? test Test?
@ -27,14 +28,11 @@ model Test {
testOf Users @relation(fields: [testOfId], references: [id]) testOf Users @relation(fields: [testOfId], references: [id])
grades Grade[] grades Grade[]
isActive Boolean @default(false) isActive Boolean @default(false)
isPassed Boolean @default(false)
teacherGrade Float?
} }
model Grade { model Grade {
id Int @id @default(autoincrement()) id Int @id @default(autoincrement())
userId Int userId Int
note String?
createdAt DateTime @default(now()) createdAt DateTime @default(now())
grade Float grade Float
testId Int testId Int