0
0
Fork 0

Add an endpoint to end a game prematurely

This commit is contained in:
Oliver-Akins 2023-09-03 11:46:51 -06:00
parent 667b3f04aa
commit 35d36aa06b

31
src/endpoints/end_game.ts Normal file
View file

@ -0,0 +1,31 @@
import { channelSchema } from "$/schemas/general";
import { ServerRoute } from "@hapi/hapi";
import { database, log } from "$/main";
import Joi from "joi";
const route: ServerRoute = {
method: `DELETE`, path: `/{channel}/game`,
options: {
validate: {
params: Joi.object({
channel: channelSchema,
}),
},
},
async handler(request) {
const { channel } = request.params;
log.info(`Ending game for channel: ${channel}`);
await database.resetChannel(channel);
// Tell the overlay(s) to end the game
request.server.app.io.to(channel).emit(`finish`, {
active: false,
win: null,
solution: null,
});
return `Reset the game, start a new game to keep playing`;
},
};
export default route;