From 48cc2c5053f4a770a39eaf202aadf9a605696965 Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Thu, 28 Dec 2023 23:17:58 -0800 Subject: [PATCH] chore: delete user backend refac --- backend/apps/web/models/chats.py | 9 +++++++++ backend/apps/web/models/users.py | 14 ++++++++------ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/backend/apps/web/models/chats.py b/backend/apps/web/models/chats.py index 8f075e40..ebc17d9a 100644 --- a/backend/apps/web/models/chats.py +++ b/backend/apps/web/models/chats.py @@ -153,5 +153,14 @@ class ChatTable: except: return False + def delete_chats_by_user_id(self, user_id: str) -> bool: + try: + query = Chat.delete().where(Chat.user_id == user_id) + query.execute() # Remove the rows, return number of rows removed. + + return True + except: + return False + Chats = ChatTable(DB) diff --git a/backend/apps/web/models/users.py b/backend/apps/web/models/users.py index 2768f20b..4b790ab2 100644 --- a/backend/apps/web/models/users.py +++ b/backend/apps/web/models/users.py @@ -115,14 +115,16 @@ class UsersTable: def delete_user_by_id(self, id: str) -> bool: try: # Delete User Chats - query = Chat.delete().where(Chat.user_id == id) - query.execute() # Remove the rows, return number of rows removed. + result = Chat.delete_chats_by_user_id(id) - # Delete User - query = User.delete().where(User.id == id) - query.execute() # Remove the rows, return number of rows removed. + if result: + # Delete User + query = User.delete().where(User.id == id) + query.execute() # Remove the rows, return number of rows removed. - return True + return True + else: + return False except: return False