From 6691f6ae006393d95a887227befa2ea681547db2 Mon Sep 17 00:00:00 2001 From: Dylan JUZAINE Date: Mon, 25 Nov 2024 12:42:54 +0100 Subject: [PATCH] feat(vil-612): change game data model --- server/controllers/game.ts | 3 ++- src/api/game/game.getOneGameById.ts | 1 + src/components/game/DisplayGameById.tsx | 23 ++++++++++------------- types/activity.type.ts | 2 +- 4 files changed, 14 insertions(+), 15 deletions(-) diff --git a/server/controllers/game.ts b/server/controllers/game.ts index 679941c5e..f9002716f 100644 --- a/server/controllers/game.ts +++ b/server/controllers/game.ts @@ -412,7 +412,8 @@ gameController.get({ path: '/standardGame/:id', userType: UserType.TEACHER }, as .orderBy('game.createDate', 'ASC') .getMany(); - activity.content.game = games; + activity.games = games; + res.sendJSON(activity); }); diff --git a/src/api/game/game.getOneGameById.ts b/src/api/game/game.getOneGameById.ts index feab3c12b..97ab6962b 100644 --- a/src/api/game/game.getOneGameById.ts +++ b/src/api/game/game.getOneGameById.ts @@ -37,6 +37,7 @@ export type DataUse = { userId: number; villageId: number; subType: number; + games: GameItem[]; }; type GetOneGameByIdProps = { diff --git a/src/components/game/DisplayGameById.tsx b/src/components/game/DisplayGameById.tsx index c0e21999e..49df1428c 100644 --- a/src/components/game/DisplayGameById.tsx +++ b/src/components/game/DisplayGameById.tsx @@ -181,11 +181,11 @@ const DisplayGameById = ({ subType }: SubTypeProps) => { setErrorModalOpen(false); setIsReset(true); - if (currentStep + 1 === getOneGameById?.content?.game?.length) { + if (currentStep + 1 === getOneGameById?.games.length) { setIsLastGameModalOpen(true); return; } - }, [currentStep, getOneGameById?.content?.game?.length]); + }, [currentStep, getOneGameById?.games.length]); const userMap = useMemo( () => @@ -203,14 +203,15 @@ const DisplayGameById = ({ subType }: SubTypeProps) => { const { id, content, - content: { game: steps, labelPresentation, radio, language, monney, type }, + content: { labelPresentation, radio, language, monney, type }, createDate, villageId, + games: steps, } = getOneGameById || {}; const responses: { signification: string | undefined; isSuccess: boolean; value: number }[] = []; const euro = content.monney; - const media = getOneGameById.content.game[currentStep].video as string; + const media = getOneGameById.games[currentStep]?.video as string; if (steps[currentStep]) { const significationWithEuro = `${steps[currentStep].signification} ${euro}`; @@ -263,7 +264,7 @@ const DisplayGameById = ({ subType }: SubTypeProps) => { if (playContent.responses.length === 0) { return; } - const apiResponse = await sendNewGameResponse(getOneGameById?.content?.game[currentStep].id || 0, selection, playContent.villageId || 0); + const apiResponse = await sendNewGameResponse(getOneGameById?.games[currentStep].id || 0, selection, playContent.villageId || 0); if (!apiResponse) { console.error('Error reaching server'); return; @@ -273,7 +274,7 @@ const DisplayGameById = ({ subType }: SubTypeProps) => { setIsReset(false); setErrorModalOpen(!isSuccess); if (isSuccess || tryCount === 1) { - setGameResponses(await getGameStats(getOneGameById?.content?.game[currentStep].id || 0)); + setGameResponses(await getGameStats(getOneGameById?.games[currentStep].id || 0)); } setTryCount(tryCount + 1); }, @@ -288,7 +289,7 @@ const DisplayGameById = ({ subType }: SubTypeProps) => { tryCount, playContent.villageId, currentStep, - getOneGameById?.content?.game, + getOneGameById?.games, ], ); @@ -300,11 +301,7 @@ const DisplayGameById = ({ subType }: SubTypeProps) => { if (playContent.responses.length === 0 || !gameCreator) { return ( - + ); } @@ -458,7 +455,7 @@ const DisplayGameById = ({ subType }: SubTypeProps) => { diff --git a/types/activity.type.ts b/types/activity.type.ts index 76b3a8a93..a7375ccef 100644 --- a/types/activity.type.ts +++ b/types/activity.type.ts @@ -3,7 +3,6 @@ export interface ActivityContent { id: number; // needed to sort content. type: ActivityContentType; value: string; - game?: unknown; } export type AnyData = Record; @@ -62,6 +61,7 @@ export interface Activity { responseActivityId?: number | null; responseType?: number | null; isVisibleToParent?: boolean; + game?: object | null; } // For activity Reaction, click is not allowed in the images in the Card