Spaces:
Running
Running
from fastapi import HTTPException | |
from pydantic import EmailStr | |
from trauma.core.config import settings | |
async def check_unique_fields_existence(name: str, | |
new_value: EmailStr | str, | |
current_value: str | None = None) -> None: | |
if new_value == current_value or not new_value: | |
return | |
account = await settings.DB_CLIENT.accounts.find_one( | |
{name: str(new_value)}, | |
collation={"locale": "en", "strength": 2} | |
) | |
if account: | |
raise HTTPException(status_code=400, detail=f'Account with specified {name} already exists.') | |