Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed shop-to-price update endpoint, not working properly before #28

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions server/apis/v1/shops_to_prices.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@
{"active": fields.Boolean(required=True, description="Whether a Shop to Price relation is in stock.")},
)


parser = api.parser()
parser.add_argument("range", location="args", help="Pagination: default=[0,19]")
parser.add_argument("sort", location="args", help='Sort: default=["name","ASC"]')
Expand Down Expand Up @@ -193,15 +192,25 @@ def put(self, id):
# Todo increase validation -> if the update is correct
price = Price.query.filter(Price.id == api.payload["price_id"]).first()
shop = Shop.query.filter(Shop.id == api.payload["shop_id"]).first()
kind = Kind.query.filter(Kind.id == api.payload["kind_id"]).first()
product = Product.query.filter(Product.id == api.payload["product_id"]).first()
kind = Kind.query.filter(Kind.id == api.payload["kind_id"]).first() if api.payload["kind_id"] != "" else None
product = (
Product.query.filter(Product.id == api.payload["product_id"]).first()
if api.payload["product_id"] != ""
else None
)

if not price or not shop:
abort(400, "Price or Shop not found")

if (product and kind) or not product and not kind:
abort(400, "One Cannabis or one Horeca product has to be provided")

# Delete keys if kind or product is None so update will not fail
if kind is None:
del api.payload["kind_id"]
if product is None:
del api.payload["product_id"]

# Ok we survived all that: let's save it:
item = update(item, api.payload)
invalidateShopCache(item.shop_id)
Expand Down