from tortoise.queryset import QuerySet

from service.constants.types import PaginationParams


def order_queryset(qs: QuerySet, filters: PaginationParams, default: str) -> QuerySet:
    ordering = [f for f in filters.order.split(",") if f.split("-")[-1] in qs.fields]
    return qs.order_by(*(ordering or (default, )))
