From dd3b985ce58356e453b0d01dd135eb86eff56e10 Mon Sep 17 00:00:00 2001 From: Alexandre POMMIER Date: Wed, 28 Jun 2023 18:54:54 +0200 Subject: [PATCH] cahnge logout reqeust for nbr session fix key in social maps, --- containers/api/src/app.controller.ts | 9 +++++---- containers/api/src/chat/chat.service.ts | 6 ++++-- containers/react/src/components/Profile/Logout.tsx | 13 +++++-------- containers/react/src/components/Social/Social.tsx | 8 ++++---- containers/react/src/pages/canvas.tsx | 10 +++++----- 5 files changed, 23 insertions(+), 23 deletions(-) diff --git a/containers/api/src/app.controller.ts b/containers/api/src/app.controller.ts index 685952e3..caeec5c3 100644 --- a/containers/api/src/app.controller.ts +++ b/containers/api/src/app.controller.ts @@ -6,7 +6,7 @@ /* By: apommier +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/06/17 01:00:00 by apommier #+# #+# */ -/* Updated: 2023/06/28 17:43:13 by apommier ### ########.fr */ +/* Updated: 2023/06/28 18:49:39 by apommier ### ########.fr */ /* */ /* ************************************************************************** */ @@ -52,9 +52,10 @@ export class AppController { const user = await this.userService.findOne(req.user.username) if(!user) return ; - if (user.sessionNumber === 1) - user.status = 0; - user.sessionNumber--; + if (user.sessionNumber > 0) + user.sessionNumber--; + if (!user.sessionNumber) + user.status = 0; this.userService.save(user); } diff --git a/containers/api/src/chat/chat.service.ts b/containers/api/src/chat/chat.service.ts index 17524f64..126d408a 100644 --- a/containers/api/src/chat/chat.service.ts +++ b/containers/api/src/chat/chat.service.ts @@ -6,7 +6,7 @@ /* By: apommier +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/06/17 01:00:25 by apommier #+# #+# */ -/* Updated: 2023/06/28 17:43:35 by apommier ### ########.fr */ +/* Updated: 2023/06/28 18:20:07 by apommier ### ########.fr */ /* */ /* ************************************************************************** */ @@ -93,7 +93,9 @@ async inviteUser(convId: number, username: string) { const conv = await this.findConv(convId); if (conv.members.find(item => item === username)) - return (1); + return (1); + if (conv.banned.find(item => item === username)) + return (0); conv.members.push(username); this.save(conv); } diff --git a/containers/react/src/components/Profile/Logout.tsx b/containers/react/src/components/Profile/Logout.tsx index 0d11e712..250809d1 100644 --- a/containers/react/src/components/Profile/Logout.tsx +++ b/containers/react/src/components/Profile/Logout.tsx @@ -1,4 +1,3 @@ -import React from "react"; import api from "../../script/axiosApi" @@ -7,18 +6,16 @@ function Logout(){ const logout = async () =>{ try { - await api.post("/logout") + await api.post("/logout"); + localStorage.clear(); + const path = 'http://' + process.env.REACT_APP_BASE_URL + '/'; + window.history.pushState({}, '', path); + window.location.reload(); } catch (err) { console.log(err); } } - logout(); - localStorage.clear(); - const path = 'http://' + process.env.REACT_APP_BASE_URL + '/'; - window.history.pushState({}, '', path); - window.location.reload(); - return (<>) } export default Logout; \ No newline at end of file diff --git a/containers/react/src/components/Social/Social.tsx b/containers/react/src/components/Social/Social.tsx index 20e58fdf..9ffaf693 100644 --- a/containers/react/src/components/Social/Social.tsx +++ b/containers/react/src/components/Social/Social.tsx @@ -47,12 +47,12 @@ function Social (){ - {invite.map(c=> ( - + {invite.map((c: User)=> ( + ))} - {friends.map(c=> ( - + {friends.map((c: User)=> ( + ))} diff --git a/containers/react/src/pages/canvas.tsx b/containers/react/src/pages/canvas.tsx index 7a72d308..fb8113a3 100644 --- a/containers/react/src/pages/canvas.tsx +++ b/containers/react/src/pages/canvas.tsx @@ -98,7 +98,7 @@ function DrawCanvas(option: number, gameParam: GameProps) { socket.on('pong:win', async () => { myScore = maxScore; - await api.post('/status', {status: 1}); + await api.post('/rmGame'); running = false; socket.emit('pong:disconnect', {id: myId}); return ; @@ -376,8 +376,8 @@ socket.on('pong:hisPoint', (data) => { if (gameParam.privateParty && !gameId) //delete invite { try{ - await api.post('/status', {status: 1}); - await api.post("deleteInvite", {username: gameParam.username}) + await api.post('/rmGame'); + await api.post("deleteInvite", {username: gameParam.username}); } catch (err){ console.log(err) @@ -421,13 +421,13 @@ async function draw(timestamp: number) if (myScore === maxScore) { await api.post('/win', data); - await api.post('/status', {status: 1}); + await api.post('/rmGame'); socket.emit('pong:disconnect', {id: myId}); } else { await api.post('/loss', data); - await api.post('/status', {status: 1}); + await api.post('/rmGame'); socket.emit('pong:disconnect', {id: myId}); } window.location.replace("http://" + process.env.REACT_APP_BASE_URL + "/pong");