✨ Add order stats
This commit is contained in:
1 parent
6fa6bf1334
commit
771e0c2a3b
10 files changed
+336
-27
No files matched your search
+20
-1
@@ -1,8 +1,18 @@
|
||||
import strawberry
|
||||
import strawberry_django
|
||||
|
||||
from main import models
|
||||
from main.api import mutations
|
||||
from main.api.types import Order, OrderOrdering, Product, Transaction, TransactionOrdering, User
|
||||
from main.api.types import (
|
||||
Order,
|
||||
OrderOrdering,
|
||||
OrderStats,
|
||||
OrderStatsByTime,
|
||||
Product,
|
||||
Transaction,
|
||||
TransactionOrdering,
|
||||
User,
|
||||
)
|
||||
|
||||
|
||||
@strawberry.type
|
||||
@@ -13,6 +23,15 @@ 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 order_stats(self) -> OrderStats:
|
||||
return OrderStats(
|
||||
yearly=[OrderStatsByTime(**stat) for stat in models.Order.objects.count_by_year().order_by("period")],
|
||||
monthly=[OrderStatsByTime(**stat) for stat in models.Order.objects.count_by_month().order_by("period")],
|
||||
dayly=[OrderStatsByTime(**stat) for stat in models.Order.objects.count_by_weekday().order_by("period")],
|
||||
hourly=[OrderStatsByTime(**stat) for stat in models.Order.objects.count_by_hour().order_by("period")],
|
||||
)
|
||||
|
||||
|
||||
@strawberry.type
|
||||
class Mutation:
|
||||
|
||||
Reference in new issue
Block a user