diff --git a/app/api/services/contacts.py b/app/api/services/contacts.py index 20db633..3af1bf0 100644 --- a/app/api/services/contacts.py +++ b/app/api/services/contacts.py @@ -127,17 +127,33 @@ class ContactService(BaseService): @staticmethod def process_save_contacts(data): logger.info(f"Process_save_contacts IN -> : {data}", exc_info=True) - message = data.get('message', '') - subscription_uid = data.get('subscription_uid', '') - title = data.get('title', '') - email = data.get('email', '') - sender = data.get('sender', '') - memSubb = MembersProducts.get_member_product_by_subscription_uid(subscription_uid) - if memSubb: - member_id = memSubb.member_id, - product_id = memSubb.product_id - if message != '' and title != '' and email != '' and sender != '': - logger.info(f"Ready to save data: {data}", exc_info=True) - ProductsContacts.add_product_contact( - member_id, product_id, subscription_uid, title, email, sender, message - ) + try: + + message = data.get('message', '') + subscription_uid = data.get('subscription_uid', '') + title = data.get('title', '') + email = data.get('email', '') + sender = data.get('sender', '') + contact_result = [] + memSubb = MembersProducts.get_member_product_by_subscription_uid(subscription_uid) + if memSubb: + member_id = memSubb.member_id, + product_id = memSubb.product_id + if message != '' and title != '' and email != '' and sender != '': + logger.info(f"Ready to save data: {data}", exc_info=True) + contact_result = ProductsContacts.add_product_contact( + member_id, product_id, subscription_uid, title, email, sender, message + ) + + response_data = { + "last_message": datetime.datetime.utcnow(), + "subscription_uid": subscription_uid, + "result": contact_result, + } + + return ResponseHelper.success(data=response_data) + + except Exception as e: + logger.error(f"An error occurred: {str(e)}", exc_info=True) + return ResponseHelper.internal_server_error() +