aboutsummaryrefslogtreecommitdiffstats
path: root/backend/ts/api/readyStateToggle.ts
blob: 6bca5b232107d53594476b138808e4c0bf48bc29 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import { Request, Response } from "express";
import { makeQuery } from "../../../helpers/helpersBack";
import startGame from "../startGame";

export default async function (req: Request, res: Response) {
    if (req.session === undefined || req.body.state === undefined) {
        res.status(500);
        res.send("");
        return;
    }
    await makeQuery("UPDATE `fia` SET `playersAreReady`=`playersAreReady`+" + (req.body.state ? 1 : -1)
        + " WHERE `id`=" + req.session.gid, []);
    let start = (
        await makeQuery('SELECT playersAreReady=playersCount and playersCount > 1 "start" FROM `fia` WHERE `id`= ?',
        [req.session.gid])
    )[0].start;
    if(start === 1)
        startGame(req, res);
}