Exemplo n.º 1
0
def insert_event():
    post_data = request.get_json()
    user_id = Helps.get_user_id_from_headers()
    department_id = MySql.get_department_of_user(user_id)

    local_start_date = Helps.format_time(post_data.get('start_date'))
    local_end_date = Helps.format_time(post_data.get('end_date'))
    list_type = MySql.get_all_type()

    if Helps.is_check_device_Invalid(post_data, list_type, local_start_date,
                                     local_end_date):
        try:
            event = Event(local_start_date, local_end_date,
                          post_data.get('text'), user_id, department_id)
            MySql.save_to_db(event)
        except IndentationError:
            MySql.rollback()
            return {
                "action": "error",
                "message": "ERROR: Insert database error"
            }
        if Helps.insert_data_child(post_data, list_type, event=event):
            return {
                "action": "success",
                "tid": event.id,
                "message": "Inserted"
            }
        else:
            return {
                "action": "error",
                "message": "ERROR: Insert database error"
            }
    return {"action": "error", "message": "ERROR: The device has been used"}
Exemplo n.º 2
0
def delete_event(event_id):
    user_id = Helps.get_user_id_from_headers()
    event_own_id = list(map(int, event_id.split('_')))
    user_id_of_event = MySql.get_user_id_of_event(event_own_id[0])

    if user_id_of_event is None:
        return {"action": "success", "message": "DELETED"}

    if user_id_of_event == user_id and event_own_id[1] == user_id:
        for a in MySql.get_devices_by_event_id(event_own_id[0]):
            MySql.remove_from_db(a)
        for b in MySql.get_users_by_event_id(event_own_id[0]):
            MySql.remove_from_db(b)
        ev = MySql.get_event_by_id(event_own_id[0])
        MySql.remove_from_db(ev)
        MySql.save_to_db()
        return {"action": "success", "message": "DELETED"}
    if user_id_of_event != user_id and user_id == event_own_id[1]:
        a = MySql.get_event_user_by_event_member(event_own_id[0], user_id)
        MySql.remove_from_db(a)
        MySql.save_to_db()
        return {"action": "success", "message": "DELETED"}
    return {
        "action": "error",
        "message": "Failed to delete other people's events"
    }
Exemplo n.º 3
0
def put_event(event_id):
    post_data = request.get_json()
    user_id = Helps.get_user_id_from_headers()
    event_own_id = list(map(int, event_id.split('_')))
    user_id_of_event = MySql.get_user_id_of_event(event_own_id[0])

    if user_id_of_event == user_id and event_own_id[1] == user_id:
        local_start_date = Helps.format_time(post_data.get('start_date'))
        local_end_date = Helps.format_time(post_data.get('end_date'))
        list_type = MySql.get_all_type()

        if Helps.is_check_device_Invalid(post_data, list_type, local_start_date, local_end_date, event_own_id[0]):
            try:
                MySql.update_event(event_own_id[0], local_start_date, local_end_date, post_data['text'])
                MySql.save_to_db()
            except IndentationError:
                MySql.rollback()
                return {"action": "error", "message": "ERROR: Insert database error"}
            if Helps.insert_data_child(post_data, list_type, event_id=post_data['id_old']):
                return {"action": "success", "tid": post_data['id'], "message": "UPDATED"}
            else:
                return {"action": "error", "message": "ERROR: Insert database error"}
        else:
            return {"action": "error", "message": "ERROR: The device has been used"}
    return {"action": "error", "message": "Failed to update other people's events"}
Exemplo n.º 4
0
def dang_ki():
    user = User('huynhtan06',
                hashlib.sha256('123456'.encode("utf-8")).hexdigest(),
                2,
                first_name="HT06")
    MySql.save_to_db(user)
    print(user.password)
    return {"hello": "ok"}
Exemplo n.º 5
0
def delete_event(event_id):
    user_id = Helps.get_user_id_from_headers()
    event_own_device = list(map(int, event_id.split('_')))
    user_id_of_event = MySql.get_user_id_of_event(event_own_device[0])

    if user_id_of_event is None:
        return {"action": "success", "message": "DELETED"}

    if event_own_device[1] == user_id:
        event_device = MySql.get_event_device_by_id(event_own_device[2])
        MySql.remove_from_db(event_device)
        MySql.save_to_db()
        return {"action": "success", "message": "DELETED"}
    return {"action": "error", "message": "Failed to delete other people's events"}
Exemplo n.º 6
0
def delete_event(event_id):
    user_id = Helps.get_user_id_from_headers()
    user_id_of_ev = MySql.get_user_id_of_event(event_id)
    if user_id_of_ev is None:
        return {"action": "success", "message": "DELETED"}

    if user_id_of_ev == user_id:
        for a in MySql.get_devices_by_event_id(event_id):
            MySql.remove_from_db(a)
        for b in MySql.get_users_by_event_id(event_id):
            MySql.remove_from_db(b)
        ev = MySql.get_event_by_id(event_id)
        MySql.remove_from_db(ev)
        MySql.save_to_db()
        return {"action": "success", "message": "DELETED"}
    else:
        a = MySql.get_event_user_by_event_member(event_id, user_id)
        MySql.remove_from_db(a)
        MySql.save_to_db()
        return {"action": "success", "message": "DELETED"}