fix: refactored server functions names
This commit is contained in:
parent
7c89ca8338
commit
771d9a8637
|
@ -2,24 +2,7 @@
|
||||||
|
|
||||||
import prisma from "@/lib/prisma";
|
import prisma from "@/lib/prisma";
|
||||||
|
|
||||||
export async function getGrade(testId: number, userId: number) {
|
export async function addGrade(testId: number, userId: number, grade: number) {
|
||||||
const grade = await prisma.grade.findFirst({
|
|
||||||
select: {
|
|
||||||
grade: true,
|
|
||||||
id: true,
|
|
||||||
testId: true,
|
|
||||||
createdAt: true,
|
|
||||||
},
|
|
||||||
where: {
|
|
||||||
testId: testId,
|
|
||||||
userId: userId
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return grade;
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function addGrade(testId: number, userId: number, grade: number, note: string | null) {
|
|
||||||
const newGrade = await prisma.grade.create({
|
const newGrade = await prisma.grade.create({
|
||||||
data: {
|
data: {
|
||||||
grade: grade,
|
grade: grade,
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
import prisma from "@/lib/prisma";
|
import prisma from "@/lib/prisma";
|
||||||
|
|
||||||
|
// Only a test function
|
||||||
export async function setTestActive(id: number, active: boolean) {
|
export async function setTestActive(id: number, active: boolean) {
|
||||||
const users = await prisma.users.findFirst();
|
const users = await prisma.users.findFirst();
|
||||||
|
|
||||||
|
@ -11,7 +12,7 @@ export async function setTestActive(id: number, active: boolean) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getActiveTest(date: Date) {
|
export async function getFirstActiveTest(date: Date) {
|
||||||
return await prisma.test.findFirst({
|
return await prisma.test.findFirst({
|
||||||
select: {
|
select: {
|
||||||
id: true,
|
id: true,
|
||||||
|
@ -34,7 +35,7 @@ export async function getActiveTest(date: Date) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getActiveTestWithGrade(date: Date, userId: number) {
|
export async function getFirstActiveTestWithGrade(date: Date, userId: number) {
|
||||||
return await prisma.test.findFirst({
|
return await prisma.test.findFirst({
|
||||||
select: {
|
select: {
|
||||||
id: true,
|
id: true,
|
||||||
|
|
|
@ -6,7 +6,7 @@ export interface Results {
|
||||||
total: number;
|
total: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getResults(testId: number) {
|
export async function getStudentResults(testId: number) {
|
||||||
const grades = await prisma.grade.findMany({ where: { testId: testId, user: { isTeacher: false } } });
|
const grades = await prisma.grade.findMany({ where: { testId: testId, user: { isTeacher: false } } });
|
||||||
|
|
||||||
const allGrades = ['1', '1.5', '2', '2.5', '3', '3.5', '4', '4.5', '5', '5.5', '6'];
|
const allGrades = ['1', '1.5', '2', '2.5', '3', '3.5', '4', '4.5', '5', '5.5', '6'];
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { getActiveTestWithGrade } from '@/actions/mangeTest';
|
import { getFirstActiveTestWithGrade } from '@/actions/mangeTest';
|
||||||
import { TestCard } from '@/components/custom';
|
import { TestCard } from '@/components/custom';
|
||||||
import { Session } from 'next-auth';
|
import { Session } from 'next-auth';
|
||||||
import { signOut } from 'next-auth/react';
|
import { signOut } from 'next-auth/react';
|
||||||
|
@ -14,7 +14,7 @@ export function TodayTest({ session }: { session: Session }) {
|
||||||
const [activeTest, setActiveTest] = useState<{ data: any | null; error: Error | null; isLoading: boolean }>({ isLoading: true, data: null, error: null });
|
const [activeTest, setActiveTest] = useState<{ data: any | null; error: Error | null; isLoading: boolean }>({ isLoading: true, data: null, error: null });
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
getActiveTestWithGrade(new Date(), session.user.id)
|
getFirstActiveTestWithGrade(new Date(), session.user.id)
|
||||||
.catch((err) => setActiveTest({ data: null, error: err, isLoading: false }))
|
.catch((err) => setActiveTest({ data: null, error: err, isLoading: false }))
|
||||||
.then((data) => setActiveTest({ data, error: null, isLoading: false }));
|
.then((data) => setActiveTest({ data, error: null, isLoading: false }));
|
||||||
}, [session.user.id]);
|
}, [session.user.id]);
|
||||||
|
|
|
@ -2,7 +2,7 @@ import Image from 'next/image';
|
||||||
import Logo from '/images/logo.svg';
|
import Logo from '/images/logo.svg';
|
||||||
import { getAuthServerSession } from '@/lib/authenticate';
|
import { getAuthServerSession } from '@/lib/authenticate';
|
||||||
import { redirect } from 'next/navigation';
|
import { redirect } from 'next/navigation';
|
||||||
import { getActiveTest } from '@/actions/mangeTest';
|
import { getFirstActiveTest } from '@/actions/mangeTest';
|
||||||
import { TodayTest } from './TodayTest';
|
import { TodayTest } from './TodayTest';
|
||||||
|
|
||||||
export default async function Play() {
|
export default async function Play() {
|
||||||
|
@ -13,7 +13,7 @@ export default async function Play() {
|
||||||
}
|
}
|
||||||
|
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
const todayTest = await getActiveTest(now);
|
const todayTest = await getFirstActiveTest(now);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={'w-full h-[100vh] text-[#F0F0F0] bg-black p-12 flex flex-col items-center justify-center gap-y-28'}>
|
<div className={'w-full h-[100vh] text-[#F0F0F0] bg-black p-12 flex flex-col items-center justify-center gap-y-28'}>
|
||||||
|
|
|
@ -3,7 +3,7 @@ import { Chart } from '@components/custom/chart';
|
||||||
import logo from '@images/logo.svg';
|
import logo from '@images/logo.svg';
|
||||||
import Image from 'next/image';
|
import Image from 'next/image';
|
||||||
import ginger from '@images/ginger.png';
|
import ginger from '@images/ginger.png';
|
||||||
import { getResults, getTeacherResult, Results } from '@/actions/results';
|
import { getStudentResults, getTeacherResult, Results } from '@/actions/results';
|
||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
|
|
||||||
export default function Page({ params }: { params: { id: string } }) {
|
export default function Page({ params }: { params: { id: string } }) {
|
||||||
|
@ -17,7 +17,7 @@ export default function Page({ params }: { params: { id: string } }) {
|
||||||
.then((res) => setTeacherGrade(res?.grade || 0))
|
.then((res) => setTeacherGrade(res?.grade || 0))
|
||||||
.catch((err) => console.error(err));
|
.catch((err) => console.error(err));
|
||||||
|
|
||||||
getResults(testId)
|
getStudentResults(testId)
|
||||||
.then((res) => setData(res))
|
.then((res) => setData(res))
|
||||||
.catch((err) => console.error(err));
|
.catch((err) => console.error(err));
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@ export function GradingForm({ session, testId }: { session: Session; testId: num
|
||||||
async function handleSubmit(event: React.FormEvent<HTMLFormElement>) {
|
async function handleSubmit(event: React.FormEvent<HTMLFormElement>) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|
||||||
const result = await addGrade(testId, session.user.id, grade, null);
|
const result = await addGrade(testId, session.user.id, grade);
|
||||||
if (result.id) {
|
if (result.id) {
|
||||||
console.log('ok');
|
console.log('ok');
|
||||||
setHasVoted(true);
|
setHasVoted(true);
|
||||||
|
@ -39,7 +39,7 @@ export function GradingForm({ session, testId }: { session: Session; testId: num
|
||||||
<div className={'w-full md:w-[400px]'}>
|
<div className={'w-full md:w-[400px]'}>
|
||||||
<form onSubmit={handleSubmit}>
|
<form onSubmit={handleSubmit}>
|
||||||
<div>
|
<div>
|
||||||
<input type="range" value={grade} step="0.5" min="1" max="6" id="gradeSelector" className={"w-full appearance-none bg-transparent [&::-webkit-slider-runnable-track]:rounded-full [&::-webkit-slider-runnable-track]:bg-primary/75 accent-accent"} onChange={(e) => setGrade(Number(e.target.value))} />
|
<input type="range" value={grade} step="0.5" min="1" max="6" id="gradeSelector" className={'w-full appearance-none bg-transparent [&::-webkit-slider-runnable-track]:rounded-full [&::-webkit-slider-runnable-track]:bg-primary/75 accent-accent'} onChange={(e) => setGrade(Number(e.target.value))} />
|
||||||
</div>
|
</div>
|
||||||
<div className={'flex flex-row justify-evenly'}>
|
<div className={'flex flex-row justify-evenly'}>
|
||||||
<Image src={YourGrade} alt={YourGrade} width={100} />
|
<Image src={YourGrade} alt={YourGrade} width={100} />
|
||||||
|
|
Loading…
Reference in New Issue