def get_task(id):
    try:
        if (id): task = Task.find_task(Task, id).json()
        else: task = Task.find_task(Task, request.json.get("id")).json()
        return {'sucess': True, 'erro': False, 'response': task}
    except Exception as e:
        return {'sucess': False, 'erro': True, 'response': str(e)}
def delete_task(id):
    try:
        #Task(request.json.get("id"), request.json.get("nome"), request.json.get("descricao"), request.json.get("status")).delete()
        if (id): Task.find_task(Task, id).delete()
        else: Task.find_task(Task, request.json.get("id")).delete()
        return {'sucess': True, 'erro': False, 'response': 'sucess'}
    except Exception as e:
        print(e)
        return {'sucess': False, 'erro': True, 'response': str(e)}
def update_task():
    try:
        task = Task.find_task(Task, request.json.get("id"))
        task.update(request.json.get("nome"), request.json.get("descricao"),
                    request.json.get("status"))
        return {'sucess': True, 'erro': False, 'response': task.json()}
    except Exception as e:
        return {'sucess': False, 'erro': True, 'response': str(e)}
def change_status(id, type_status):
    try:
        if (id): task = Task.find_task(Task, id)
        else: task = Task.find_task(Task, request.json.get("id"))
        if (type_status):
            task.status = type_status
        else:
            if request.json.get("status") is not None:
                task.status = request.json.get("status")
        task.update(task.name, task.desc, task.status)
        return jsonify({
            'success': True,
            'error': False,
            'response': task.json()
        })
    except Exception as e:
        return jsonify({'success': False, 'error': True, 'response': str(e)})
def update_task():
    try:
        data = request.json
        task = Task.find_task(data.get("id"))
        task.update(data["name"], data["desc"], data['status'])
        return jsonify({
            'success': True,
            'error': False,
            'response': task.json()
        })
    except Exception as e:
        return jsonify({'success': False, 'error': True, 'response': str(e)})
Esempio n. 6
0
def save_lawyer():
    try:
        if (Task.find_task(Task, request.json.get("task_id"))):
            lawyer = Lawyer(request.json.get("oab"),
                            request.json.get("task_id"),
                            request.json.get("nome"))
            lawyer.save()
            response = lawyer.json()
        else:
            response = "task_id não encontrada na tabela task"
        return {'sucess': True, 'erro': False, 'response': response}
    except Exception as e:
        return {'sucess': False, 'erro': True, 'response': str(e)}