Add an endpoint to end a game prematurely
This commit is contained in:
parent
667b3f04aa
commit
35d36aa06b
1 changed files with 31 additions and 0 deletions
31
src/endpoints/end_game.ts
Normal file
31
src/endpoints/end_game.ts
Normal 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;
|
||||
Loading…
Add table
Add a link
Reference in a new issue