def get_tasks(workspace, id): """Get all tasks for a team""" team = Team.query.filter(Team.workspace_name == workspace, Team.id == id).first() tasks = team.tasks data = [conv_obj_to_dict(task) for task in tasks] return jsonify({"data": data})
def get_team(workspace, id): """Get a single team""" team = Team.query.filter(Team.workspace_name == workspace, Team.id == id).first() if not team: return jsonify({"errors": "team not found"}), 404 return jsonify({"data": conv_obj_to_dict(team, ['name'])})
def update_task(workspace, id, task_id): """Update task""" form = TaskUpdateForm(csrf_enabled=False, data=request.json) if form.validate(): task = Task.query.filter(Task.team == id, Task.id == task_id).first() update_obj_with_data(task, form.data) ret_task = conv_obj_to_dict(task) db.session.commit() return jsonify({"data": ret_task}) return jsonify({"errors": form.errors}), 400
def add_workspace_user(workspace_formatted_name): """Add a workspace user""" try: form = WorkspaceUserAddForm(csrf_enabled=False, data=request.json) if form.validate(): workspace_formatted_name = form.data["workspace_formatted_name"] user_id = form.data["user_id"] workspace_user = WorkspaceUser(user_id=user_id, workspace_formatted_name=workspace_formatted_name) db.session.add(workspace_user) db.session.commit() ret_workspace_user=conv_obj_to_dict(workspace_user) return jsonify({"data": ret_workspace_user}), 201 return jsonify({"errors": form.errors}), 400 except IntegrityError as e: return jsonify({"errors": "Workspace User already exists"}), 400
def add_task(workspace, id): """Add a task""" form = TaskAddForm(csrf_enabled=False, data=request.json) if form.validate(): creator_id = form.data.get('creator_id', None) assignee_id = form.data.get('assignee_id', None) title = form.data.get('title', None) description = form.data.get('description', None) priority = form.data.get('priority', None) status = form.data.get('status', None) queue = form.data.get('queue', None) team = form.data.get('team', None) task = Task(creator_id=creator_id,assignee_id=assignee_id,title=title,description=description,priority=priority,status=status,queue=queue,team=team) ret_task = conv_obj_to_dict(task) db.session.add(task) db.session.commit() return jsonify({"data": ret_task}), 201 return jsonify({"errors": form.errors}), 400
def get_task(workspace, id, task_id): """Get a single task""" task = Task.query.filter(Task.team == id, Task.id == task_id).first() if not task: return jsonify({"errors": "task not found"}), 404 return jsonify({"data": conv_obj_to_dict(task)})
def get_teams(workspace): """Get all teams""" teams = Team.query.filter(Team.workspace_name == workspace).all() return jsonify({"data": [conv_obj_to_dict(team) for team in teams]})
def get_workspace_users(workspace_formatted_name): """Get all users for a workspace""" workspace_users = WorkspaceUser.query.filter(WorkspaceUser.workspace_formatted_name == workspace_formatted_name).all() return jsonify({"data": [conv_obj_to_dict(user) for user in workspace_users]})