39 lines
1.1 KiB
Python
39 lines
1.1 KiB
Python
import graphene
|
|
from graphene import List
|
|
|
|
from backend.core.repositories import CustomerRepository
|
|
from backend.graphql_api.types import CustomerType
|
|
from backend.graphql_api.inputs import CustomerFilterInput
|
|
|
|
|
|
class CustomerQueries(graphene.ObjectType):
|
|
"""Customer query operations"""
|
|
|
|
customer = graphene.Field(
|
|
CustomerType,
|
|
id=graphene.ID(required=True)
|
|
)
|
|
|
|
customers = graphene.Field(
|
|
List(CustomerType),
|
|
filter=CustomerFilterInput()
|
|
)
|
|
|
|
def resolve_customer(self, info, id):
|
|
return CustomerRepository.get_by_id(id)
|
|
|
|
def resolve_customers(self, info, filter=None):
|
|
if not filter:
|
|
return CustomerRepository.get_all()
|
|
|
|
if filter.is_active is not None:
|
|
return CustomerRepository.get_active() if filter.is_active else CustomerRepository.get_inactive()
|
|
|
|
return CustomerRepository.filter_customers(
|
|
name=filter.name,
|
|
city=filter.city,
|
|
state=filter.state,
|
|
start_date=filter.start_date,
|
|
end_date=filter.end_date
|
|
)
|