33 lines
850 B
Python
33 lines
850 B
Python
from typing import Optional
|
|
from sqlalchemy import select
|
|
from database import models
|
|
from graphql_schema.entities.resolvers.base import BaseQueryResolver
|
|
from graphql_schema.entities.types.types import Organization
|
|
|
|
|
|
class OrganizationQueryResolver(BaseQueryResolver):
|
|
|
|
def __init__(self):
|
|
super().__init__(Organization, models.Organization)
|
|
|
|
def get_query(
|
|
self,
|
|
object_id: int | None = None,
|
|
order_by: list | None = None,
|
|
**kwargs
|
|
):
|
|
query = (
|
|
select(models.Organization)
|
|
.filter(models.Organization.deleted.is_(False))
|
|
)
|
|
|
|
if not order_by:
|
|
order_by = [models.Organization.name]
|
|
|
|
query = query.order_by(*order_by)
|
|
|
|
if object_id:
|
|
query = query.where(models.Organization.id == object_id)
|
|
|
|
return query
|