Skip to content

Commit

Permalink
no load option on task queries
Browse files Browse the repository at this point in the history
  • Loading branch information
FLiotta committed Oct 11, 2020
1 parent 929fedf commit c4a8c62
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
5 changes: 3 additions & 2 deletions server/app/routes/list_routes.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from flask import jsonify, g, request, Blueprint
from sqlalchemy.orm import noload
from ..db import db
from ..middlewares import protected_route
from ..models import Lists, Tasks
Expand Down Expand Up @@ -50,7 +51,7 @@ def edit_list_title(list_id):
user_id = g.user.get('id')
title = req_data.get('title')

requested_list = Lists.query.filter_by(id=list_id).first()
requested_list = Lists.query.options(noload('tasks')).filter_by(id=list_id).first()

if requested_list is None:
return jsonify(msg="List not found"), 404
Expand Down Expand Up @@ -106,7 +107,7 @@ def sort_list_tasks(list_id):
if order is None:
return jsonify(msg="Missing params"), 400

requested_tasks = Tasks.query.filter_by(
requested_tasks = Tasks.query.options(noload('priority')).filter_by(
list_id=list_id, user_id=user_id).all()

for task in requested_tasks:
Expand Down
7 changes: 4 additions & 3 deletions server/app/routes/task_routes.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from flask import jsonify, g, request, Blueprint
from sqlalchemy.orm import noload
from ..middlewares import protected_route
from ..models import Tasks, Lists
from ..db import db
Expand Down Expand Up @@ -57,7 +58,7 @@ def update_task_list(task_id):
if list_id is None or task_id is None or new_position is None:
return jsonify(msg="Missing params"), 400

tasks = Tasks.query.filter((Tasks.list_id==list_id) | (Tasks.id==task_id)).order_by(Tasks.position).all()
tasks = Tasks.query.options(noload('priority')).filter((Tasks.list_id==list_id) | (Tasks.id==task_id)).order_by(Tasks.position).all()

temp_task = None

Expand Down Expand Up @@ -87,7 +88,7 @@ def update_task_description(task_id):
if description is None:
return jsonify(msg="Missing param: description"), 400

requested_task = Tasks.query.filter_by(id=task_id).first()
requested_task = Tasks.query.options(noload('priority')).filter_by(id=task_id).first()

if user_id != requested_task.user_id:
return jsonify(msg="You can't perform this action."), 403
Expand Down Expand Up @@ -133,7 +134,7 @@ def update_task_title(task_id):
if new_title is None:
return jsonify(msg="Missing param: title"), 400

requested_task = Tasks.query.filter_by(id=task_id).first()
requested_task = Tasks.query.options(noload('priority')).filter_by(id=task_id).first()

if user_id != requested_task.user_id:
return jsonify(msg="You can't perform this action."), 403
Expand Down

0 comments on commit c4a8c62

Please sign in to comment.