예제 #1
0
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)
예제 #2
0
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)
예제 #3
0
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
    })
예제 #4
0
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"]),
    }
예제 #5
0
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"]),
    })
예제 #6
0
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)
예제 #7
0
def message_helper(message) -> dict:
    message['type'] = str(FlowTypeEnumOut(message['type']))
    return clean_dict_helper({
        **message,
        "id": str(message["_id"]),
    })
예제 #8
0
def user_basic_information_helper(user: dict) -> PortalUserBasicSchemaOut:
    results = {
        "username": user["username"],
        "id": str(user["_id"]),
    }
    return clean_dict_helper(results)
예제 #9
0
def broadcast_template_helper(broadcast_template) -> dict:
    results = {
        **broadcast_template,
        "id": str(broadcast_template["_id"]),
    }
    return clean_dict_helper(results)
예제 #10
0
def bot_helper(bot):
    results = {
        **bot,
        "id": str(bot["_id"]),
    }
    return clean_dict_helper(results)