-
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.
Question implementation- player must answer question correctly to mov…
…e between rooms Created LocalDoor type for improved type safety
- Loading branch information
1 parent
9d2b800
commit 0ce8ebc
Showing
7 changed files
with
77 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export type Question = { id: number; question: string }; | ||
export type LocalDoor = { room1_id: number; room2_id: number }; |
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,24 @@ | ||
import { error, type RequestHandler } from "@sveltejs/kit"; | ||
import prisma from "$lib/prisma"; | ||
|
||
export const GET: RequestHandler = async ({ url }) => { | ||
const id = url.searchParams.get("id"); | ||
if (!id) throw error(400, "Question ID not provided"); | ||
const answer = url.searchParams.get("answer"); | ||
if (!answer) throw error(400, "Answer not provided"); | ||
const res = await prisma.definition.findUnique({ | ||
where: { | ||
id: +id, | ||
}, | ||
select: { | ||
answer_regex: true, | ||
}, | ||
}); | ||
if (!res) throw error(400, "Invalid question ID"); | ||
const correct = new RegExp("^" + res.answer_regex + "$").test(answer); | ||
return new Response(JSON.stringify({ correct }), { | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
}); | ||
}; |
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,17 @@ | ||
import prisma from "$lib/prisma"; | ||
import type { RequestHandler } from "@sveltejs/kit"; | ||
|
||
export const GET: RequestHandler = async () => { | ||
const definition: { id: bigint; definition: string }[] = | ||
await prisma.$queryRaw`SELECT id,definition FROM Definition ORDER BY rand() LIMIT 1`; | ||
return new Response( | ||
JSON.stringify(definition[0], (_, v) => | ||
typeof v === "bigint" ? Number(v) : v, | ||
), | ||
{ | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
}, | ||
); | ||
}; |
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