From a5dd1aac4e6a51e0494ecb0cac11f3b5c5943a1a Mon Sep 17 00:00:00 2001 From: Oliver-Akins Date: Sun, 19 Feb 2023 20:45:58 -0700 Subject: [PATCH] Add a method to view the game's current state without affecting it. --- src/endpoints/view_game_state.ts | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 src/endpoints/view_game_state.ts diff --git a/src/endpoints/view_game_state.ts b/src/endpoints/view_game_state.ts new file mode 100644 index 0000000..16bb104 --- /dev/null +++ b/src/endpoints/view_game_state.ts @@ -0,0 +1,21 @@ +import { ServerRoute } from "@hapi/hapi"; +import { database } from "$/main"; +import Joi from "joi"; + +const route: ServerRoute = { + method: `GET`, path: `/{channel}/game`, + options: { + validate: { + params: Joi.object({ + channel: Joi.string().alphanum(), + }), + }, + }, + async handler(request) { + const { channel } = request.params; + + let { current, incorrect } = await database.getChannel(channel); + return { current, incorrect }; + }, +}; +export default route; \ No newline at end of file