Hello, I'm trying to check first if a customer exists in the database using get_one_or_none, but I don't think the current repository has access to the base model.
#controller.py
@post(
path=urls.REGISTER_CUSTOMER,
dependencies={"customer_transaction": Provide(provide_customer_service)},
guards=[requires_account_management_user]
)
async def register_customer(self, data: CustomerRegisterSchema, request: Request[EmployeeModel, Token, Any],
customer_transaction: CustomerService) -> Response:
user_data = CustomerModel(
first_name=data.first_name,
last_name=data.last_name,
email=data.email,
phone=data.phone,
hashed_password=await hash_password(data.password),
user_type=UserType[data.user_type],
company=data.company,
shortname=data.shortname,
contact_emails=data.contact_emails,
address=data.address,
representative_id=request.user.id
)
user = customer_transaction.get_one_or_none(email=data.email) #returns coroutine object
user = await customer_transaction.get_one_or_none(email=data.email) #returns None
if user:
return Response(status_code=400, content="Customer already exists")
await customer_transaction.create(user_data)
return Response(status_code=200, content="Customer created successfully")