Esempio n. 1
0
def route_unregister_user(user_id: str):
    user = User.objects.get_or_404(id=user_id)
    user.identify(request)

    if user.available:
        abort(500)
    if user.status != User.Status.PENDING:
        abort(500)
    if user.user_images:
        abort(500)

    Alarm.objects(owner=user).delete()
    user.delete()

    return Response("", mimetype="application/json")
Esempio n. 2
0
def list_alarms():
    uid = request.headers.get("uid", None)

    user = User.objects.get_or_404(uid=uid)

    alarm = Alarm.objects(owner=user).first()
    if not alarm:
        alarm = Alarm(owner=user, records=[]).save()

    records = alarm.records

    result = []
    for push in records:
        try:
            push_dict: dict = push.as_dict()
            result.append(push_dict)
        except mongoengine.DoesNotExist:
            nickname = user.nickname
            user_id = str(user.id)
            not_found_user_id = push.user_id
            message = "Not found a user({not_found_user_id}) in alarm of {nickname}({user_id}) ".format(
                not_found_user_id=not_found_user_id,
                nickname=nickname,
                user_id=user_id)
            app.logger.error(message)

    return Response(json.dumps(result), mimetype='application/json')