File size: 639 Bytes
c6cc0f2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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.')