const express = require("express");
const Game = require("./game.js");
+const MAX_PROMPT_ITEMS = 20;
+
class Empathy extends Game {
constructor(id) {
super(id);
}
add_prompt(items, prompt_string) {
+ if (items > MAX_PROMPT_ITEMS)
+ return {
+ valid: false,
+ message: `Maximum number of items is ${MAX_PROMPT_ITEMS}`
+ };
+
const prompt = new Prompt(this.next_prompt_id, items, prompt_string);
this.next_prompt_id++;
this.broadcast_event_object('prompt', prompt);
- return prompt;
+ return {
+ valid: true,
+ id: prompt.id
+ };
}
/* Returns true if vote toggled, false for player or prompt not found */
router.post('/prompts', (request, response) => {
const game = request.game;
- prompt = game.add_prompt(request.body.items, request.body.prompt);
+ const result = game.add_prompt(request.body.items, request.body.prompt);
- response.json({ id: prompt.id});
+ response.json(result);
});
router.post('/vote/:prompt_id([0-9]+)', (request, response) => {