From b2e4788ab04b89a277fb34e00069e36f4e0b25c2 Mon Sep 17 00:00:00 2001 From: Antoine Jaussoin Date: Sat, 9 Jul 2022 18:01:45 +0100 Subject: [PATCH] Bug fix: Deleting a session with messages (#411) --- backend/src/db/actions/sessions.ts | 46 +++++++++++++++++++----------- 1 file changed, 29 insertions(+), 17 deletions(-) diff --git a/backend/src/db/actions/sessions.ts b/backend/src/db/actions/sessions.ts index d64058126..5f9bf0610 100644 --- a/backend/src/db/actions/sessions.ts +++ b/backend/src/db/actions/sessions.ts @@ -226,23 +226,35 @@ export async function deleteSessions( ); return false; } - await sessionRepository.query( - `delete from visitors where sessions_id = $1;`, - [sessionId] - ); - await sessionRepository.query(`delete from posts where session_id = $1;`, [ - sessionId, - ]); - await sessionRepository.query( - `delete from columns where session_id = $1;`, - [sessionId] - ); - await sessionRepository.query(`delete from groups where session_id = $1;`, [ - sessionId, - ]); - await sessionRepository.query(`delete from sessions where id = $1;`, [ - sessionId, - ]); + + try { + await sessionRepository.query( + `delete from messages where session_id = $1;`, + [sessionId] + ); + await sessionRepository.query( + `delete from visitors where sessions_id = $1;`, + [sessionId] + ); + await sessionRepository.query( + `delete from posts where session_id = $1;`, + [sessionId] + ); + await sessionRepository.query( + `delete from columns where session_id = $1;`, + [sessionId] + ); + await sessionRepository.query( + `delete from groups where session_id = $1;`, + [sessionId] + ); + await sessionRepository.query(`delete from sessions where id = $1;`, [ + sessionId, + ]); + } catch (err) { + console.error('Could not delete session', sessionId, err); + return false; + } return true; });