Skip to content

Commit

Permalink
Add loader for Box.displayUnit
Browse files Browse the repository at this point in the history
  • Loading branch information
pylipp committed Sep 26, 2024
1 parent f4b867d commit 2af0920
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions back/boxtribute_server/authz.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"standard_product",
"tag_relation",
"transaction",
"unit",
"user",
)

Expand Down
5 changes: 5 additions & 0 deletions back/boxtribute_server/business_logic/warehouse/box/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ async def resolve_box_location(box_obj, info):
return


@box.field("displayUnit")
def resolve_box_unit(box_obj, info):
return info.context["unit_loader"].load(box_obj.display_unit_id)


@box.field("measureValue")
def resolve_box_measure_value(box_obj, _):
if box_obj.display_unit_id is None:
Expand Down
2 changes: 2 additions & 0 deletions back/boxtribute_server/graph_ql/execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
SizesForSizeRangeLoader,
TagsForBoxLoader,
TransferAgreementLoader,
UnitLoader,
UnitsForDimensionLoader,
UserLoader,
)
Expand Down Expand Up @@ -55,6 +56,7 @@ async def run():
"tags_for_box_loader": TagsForBoxLoader(),
"transfer_agreement_loader": TransferAgreementLoader(),
"units_for_dimension_loader": UnitsForDimensionLoader(),
"unit_loader": UnitLoader(),
"user_loader": UserLoader(),
}

Expand Down
5 changes: 5 additions & 0 deletions back/boxtribute_server/graph_ql/loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ def __init__(self):
super().__init__(Size)


class UnitLoader(SimpleDataLoader):
def __init__(self):
super().__init__(Unit)


class OrganisationLoader(SimpleDataLoader):
def __init__(self):
super().__init__(Organisation)
Expand Down
1 change: 1 addition & 0 deletions back/test/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ def _create_jwt_payload(
"transfer_agreement:create",
"transfer_agreement:edit",
"transfer_agreement_detail:read",
"unit:read",
]
else:
payload[f"{JWT_CLAIM_PREFIX}/permissions"] = permissions
Expand Down

0 comments on commit 2af0920

Please sign in to comment.