def broadcast_history_list_helper(broadcast) -> dict: results = { "created_by": user_basic_information_helper(broadcast["created_by"]), "status": 'Completed' if broadcast["total"] == broadcast["processed"] > 0 else ('Sending' if broadcast["total"] > broadcast["processed"] >= broadcast["sent"] > 0 else 'Scheduled'), "tags": broadcast["tags"], "exclude": broadcast["exclude"], "send_to_all": broadcast["send_to_all"], "send_at": broadcast["send_at"], "sent": broadcast["sent"], "processed": broadcast["processed"], "total": broadcast["total"], "id": str(broadcast["_id"]), } return clean_dict_helper(results)
def flow_helper(flow) -> dict: for f in flow.get('flow', []): f['type'] = str(FlowTypeEnumOut(f['type'])) results = { **flow, "id": str(flow["_id"]), } return clean_dict_helper(results)
def bot_user_helper(bot_user) -> dict: return clean_dict_helper({ **bot_user, "id": str(bot_user["_id"]), "last_message": message_helper(bot_user['last_message']) if bot_user.get('last_message') else None })
def convo_message_search_helper(message) -> dict: return { **message, "user": clean_dict_helper(bot_user_helper(message["user"])) if message.get("user") else None, "id": str(message["_id"]), }
def question_helper(question) -> dict: # return { # **question, # "id": str(question["_id"]), # "created_by": str(question["created_by"]) if question.get('created_by') else None, # "updated_by": str(question["updated_by"]) if question.get('updated_by') else None, # "answers": clean_dict_helper(question["answers"]) if question.get('answers') else None # } return clean_dict_helper({ **question, "id": str(question["_id"]), })
def broadcast_history_helper(broadcast) -> dict: results = { **broadcast, "created_by": user_basic_information_helper(broadcast["created_by"]), "status": 'Completed' if broadcast["total"] == broadcast["processed"] > 0 else ('Sending' if broadcast["total"] > broadcast["processed"] >= broadcast["sent"] > 0 else 'Scheduled'), "flow": format_flow_out(broadcast["flow"]["flow"]), "id": str(broadcast["_id"]), "failed": [ bot_user_basic_information_helper(user) for user in broadcast['failed'] ], "targets": [ bot_user_basic_information_helper(user) for user in broadcast['targets'] ] } return clean_dict_helper(results)
def message_helper(message) -> dict: message['type'] = str(FlowTypeEnumOut(message['type'])) return clean_dict_helper({ **message, "id": str(message["_id"]), })
def user_basic_information_helper(user: dict) -> PortalUserBasicSchemaOut: results = { "username": user["username"], "id": str(user["_id"]), } return clean_dict_helper(results)
def broadcast_template_helper(broadcast_template) -> dict: results = { **broadcast_template, "id": str(broadcast_template["_id"]), } return clean_dict_helper(results)
def bot_helper(bot): results = { **bot, "id": str(bot["_id"]), } return clean_dict_helper(results)