Add endpoints and game utilities
This commit is contained in:
parent
56f2195962
commit
6a174e4d36
7 changed files with 213 additions and 1 deletions
33
src/endpoints/new_game.ts
Normal file
33
src/endpoints/new_game.ts
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
import { database } from "$/main";
|
||||
import { anonymizePhrase, convertToKey, spacePhrase } from "$/utils/game";
|
||||
import { ServerRoute } from "@hapi/hapi";
|
||||
import Joi from "joi";
|
||||
|
||||
const route: ServerRoute = {
|
||||
method: `POST`, path: `/{channel}/game`,
|
||||
options: {
|
||||
validate: {
|
||||
params: Joi.object({
|
||||
channel: Joi.string().alphanum(),
|
||||
}),
|
||||
},
|
||||
},
|
||||
async handler(request) {
|
||||
const { channel } = request.params;
|
||||
|
||||
let data = await database.getChannel(channel);
|
||||
|
||||
// TODO: Get the proper phrase
|
||||
let phrase = "Hello world";
|
||||
|
||||
let spaced = spacePhrase(phrase.toUpperCase());
|
||||
let anonymized = anonymizePhrase(spaced);
|
||||
data.current = anonymized;
|
||||
data.solution = spaced;
|
||||
data.incorrect = 0;
|
||||
data.key = convertToKey(spaced);
|
||||
|
||||
return `${data.current} (incorrect: ${data.incorrect}/6)`;
|
||||
},
|
||||
};
|
||||
export default route;
|
||||
Loading…
Add table
Add a link
Reference in a new issue