[web] GET for team data

This commit is contained in:
Admin 2023-05-06 12:36:52 -04:00
parent d43ffb680a
commit c901e3ac42
2 changed files with 32 additions and 9 deletions

View File

@ -11,7 +11,7 @@ model User {
id Int @id @default(autoincrement())
username String @unique
password String
Submission Session[]
sessions Session[]
}
model Session {
@ -47,7 +47,7 @@ model Problem {
sampleOutput String
realInput String
realOutput String
Submission Submission[]
submissions Submission[]
contests Contest[] @relation("ProblemContestRelation")
}
@ -66,6 +66,8 @@ model ActiveTeam {
team Team @relation(fields: [teamId], references: [id])
sessionToken String? @unique
sessionCreatedAt DateTime?
contestId Int
contest Contest @relation(fields: [contestId], references: [id])
}
model Contest {
@ -73,4 +75,5 @@ model Contest {
name String
teams Team[] @relation("TeamContestRelation")
problems Problem[] @relation("ProblemContestRelation")
activeTeams ActiveTeam[]
}

View File

@ -0,0 +1,20 @@
import type { RequestHandler } from './$types';
import { error, json } from '@sveltejs/kit';
import { db } from '$lib/server/prisma';
export const GET = (async ({ params }) => {
const session = params.session;
const activeTeam = await db.activeTeam.findUnique({
where: { sessionToken: session }
});
if (!activeTeam) {
return json({ success: false });
}
return json({
success: true,
data: {
teamId: activeTeam.teamId,
contestId: activeTeam.contestId
}
});
}) satisfies RequestHandler;