✨ UserDetail and UserList views

This commit is contained in:
Nikolai R Kristiansen committed 2022-02-12 12:58:04 +01:00
1 parent ec0549154d
commit e2a84c25a6
16 files changed
+201 -22

No files matched your search

+6
View File
@@ -1,5 +1,7 @@
import strawberry
import strawberry_django
from django.contrib.auth.models import User as DjangoUser
from strawberry import ID
from main import models
from main.api import mutations
@@ -23,6 +25,10 @@ class Query:
order_list: list[Order] = strawberry_django.field(pagination=True, order=OrderOrdering)
transaction_list: list[Transaction] = strawberry_django.field(pagination=True, order=TransactionOrdering)
@strawberry.field
def user(self, user_id: ID) -> User:
return DjangoUser.objects.get(pk=user_id)
@strawberry.field
def order_stats(self) -> OrderStats:
return OrderStats(
+11 -2
View File
@@ -36,15 +36,24 @@ class Product:
user_counts: JSONScalar
@strawberry.type
class TopMonth:
period: str
count: int
sum: int
@strawberry_django.type(models.UserProfile)
class UserProfile:
id: auto
balance: auto
image: auto
last_purchase_date: datetime
order_sum_total: float
@strawberry.field()
def last_purchase_date(self) -> datetime:
return self.last_purchase_date()
def top_months(self) -> list[TopMonth]:
return [TopMonth(**month) for month in self.top_months()]
@strawberry_django.type(UserModel)