Skip to content

Commit f4e9173

Browse files
probabile ultimo aggiornamento
1 parent 96a6718 commit f4e9173

File tree

5 files changed

+17
-6
lines changed

5 files changed

+17
-6
lines changed

src/Db/gameQueries.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import { IntegerDataType } from 'sequelize';
22
import { gameModel } from '../models/gameModel';
33
import { Request } from "express";
4+
import { BoardObjInterface } from '../Utils/historyUtils';
45

56

67

78
//crea una partita nella tabella game
89
export async function createGameDb(req: Request, user: IntegerDataType, draughts: any, diff: number ): Promise<any> {
910
const stato: string = draughts.status;
1011

11-
const newGameState = {
12+
const newGameState: BoardObjInterface = {
1213
data : draughts.engine.data,
1314
history: draughts.history
1415
}
@@ -70,7 +71,7 @@ export async function findGamesfromUser(user_id: number): Promise<any> {
7071

7172
//aggiorna nella tabella game la colonna storico
7273
export async function updateDb(game_id: number, draughts: any): Promise<any> {
73-
const newGameState = {
74+
const newGameState: BoardObjInterface = {
7475
data : draughts.engine.data,
7576
history: draughts.history
7677
}

src/Utils/gameUtils.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11

22
import { Request, Response } from "express";
3-
import { DraughtsPlayer, DraughtsStatus } from 'rapid-draughts';
3+
import { DraughtsPlayer} from 'rapid-draughts';
44
import {
5-
EnglishDraughts as Draughts,
65
EnglishDraughtsComputerFactory as ComputerFactory,
76
} from 'rapid-draughts/english';
87
import { updateStatusDb } from "../Db/gameQueries";

src/Utils/historyUtils.ts

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { DraughtsGameHistory1D } from 'rapid-draughts/dist/core/game';
2+
import { DraughtsEngineData } from 'rapid-draughts/dist/core/engine';
3+
import { EnglishDraughtsEngineStore } from 'rapid-draughts/dist/english/engine';
4+
5+
6+
export interface BoardObjInterface {
7+
data: Partial<DraughtsEngineData<number, EnglishDraughtsEngineStore>>;
8+
history: Partial<DraughtsGameHistory1D>;
9+
}
10+
11+

src/controllers/gameController.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export const getState = async (req: Request,res: Response) => {
4343
const user = await getUserFromJwt(req);
4444
const stato = await findState(user[0].dataValues.user_id);
4545
if(stato){
46-
return res.status(200).json(stato);
46+
return res.status(200).json({stato: stato});
4747
}
4848
else {
4949
res.status(500).json({ message: "impossibile avere lo stato" });

src/middlewares/userMiddleware.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export const checkToken = async (req: Request, res: Response, next: NextFunction
7171
if (tokens >= 0.25) {
7272
next();
7373
} else {
74-
return res.status(400).json({ message: "Credito non sufficiente per giocare." });
74+
return res.status(401).json({ message: "Credito non sufficiente per giocare." });
7575
}
7676
} else if (req.path === '/move') {
7777
if (tokens >= 0.0125) {

0 commit comments

Comments
 (0)