Skip to content

Commit

Permalink
Bug fix: Deleting a session with messages (#411)
Browse files Browse the repository at this point in the history
  • Loading branch information
antoinejaussoin authored Jul 9, 2022
1 parent 6c1165a commit b2e4788
Showing 1 changed file with 29 additions and 17 deletions.
46 changes: 29 additions & 17 deletions backend/src/db/actions/sessions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
Expand Down

0 comments on commit b2e4788

Please sign in to comment.