Pular para conteúdo

Contact

Contact

Bases: BaseModel

Source code in contact/contact.py
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
class Contact(BaseModel):
    name: str
    email: Optional[str]
    phone: Optional[str]
    id_botconversa: Optional[str]

    @root_validator(pre=True)
    @classmethod
    def checkAtLeastOneContact(cls, values):
        """Make sure there is at least one of the contact fields options are defined."""

        if (
            'email' not in values
            and 'phone' not in values
            and 'id_botconversa' not in values
        ):
            raise ContactMissingError(
                name=values['name'],
                message='Contacts must have at least one of these contact methods [email, phone, id_botconversa]',
            )
        return values

    @validator('phone')
    @classmethod
    def phoneValid(cls, value):
        data = DataValidator(value)
        if not data.isPhone():
            raise PhoneFormatError(
                value=value, message="It's Not a Valid Phone Number"
            )
        return value

    @validator('email')
    @classmethod
    def emailValid(cls, value):
        data = DataValidator(value)
        if not data.isEmail():
            raise EmailFormatError(
                value=value, message="It's Not a Valid Email Address."
            )
        return value

checkAtLeastOneContact(values) classmethod

Make sure there is at least one of the contact fields options are defined.

Source code in contact/contact.py
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
@root_validator(pre=True)
@classmethod
def checkAtLeastOneContact(cls, values):
    """Make sure there is at least one of the contact fields options are defined."""

    if (
        'email' not in values
        and 'phone' not in values
        and 'id_botconversa' not in values
    ):
        raise ContactMissingError(
            name=values['name'],
            message='Contacts must have at least one of these contact methods [email, phone, id_botconversa]',
        )
    return values

ContactMissingError

Bases: Exception

Custom error that is raised when a contact doesn't have any of the contact methods.

Source code in contact/contact.py
13
14
15
16
17
18
19
class ContactMissingError(Exception):
    """Custom error that is raised when a contact doesn't have any of the contact methods."""

    def __init__(self, name: str, message: str) -> None:
        self.name = name
        self.message = message
        super().__init__(message)