32 lines
951 B
Python
32 lines
951 B
Python
|
from typing import Tuple, Union
|
||
|
from mysql.connector import Error as mysqlError
|
||
|
|
||
|
import app.db.user_db as user_db
|
||
|
from app.models.user_model import User
|
||
|
|
||
|
import app.messages.api_responses.user_responses as response
|
||
|
import app.messages.api_errors as errors
|
||
|
from app.mail.mail import send_mail
|
||
|
|
||
|
|
||
|
from app.messages.mail_responses.user_email import USER_EMAIL_SUCCESSFULLY_DELETED_ACCOUNT
|
||
|
|
||
|
def delete_user(user_id: str) -> Tuple[Union[dict, str], int]:
|
||
|
"""
|
||
|
Deletes a user account.
|
||
|
|
||
|
:param user_id: User ID.
|
||
|
:type user_id: str
|
||
|
:return: Tuple containing a dictionary and an HTTP status code.
|
||
|
:rtype: Tuple[Union[dict, str], int]
|
||
|
"""
|
||
|
|
||
|
try:
|
||
|
user: User = user_db.fetch_by_id(user_id=user_id)
|
||
|
user_db.delete_user(user)
|
||
|
send_mail(USER_EMAIL_SUCCESSFULLY_DELETED_ACCOUNT, user.email)
|
||
|
except mysqlError as e:
|
||
|
return errors.UNKNOWN_DATABASE_ERROR(e)
|
||
|
|
||
|
return response.USER_DELETED_SUCCESSFULLY
|