Skip to content

models/mattermostdb.py

models.mattermostdb

MattermostUsersDB

MattermostUsersDB

Bases: DBBase

MattermostUsersDB Collection

Sync user datas from Mattermost for mapping.

Source code in models/mattermostdb.py
class MattermostUsersDB(DBBase):
    ''' MattermostUsersDB Collection

    Sync user datas from Mattermost for mapping.

    '''

    def __init__(self) -> None:
        super().__init__('mattermost_users')

    def index(self) -> None:
        ''' To make collection's index

        Indexs:
            - `email`

        '''
        self.create_index([('email', 1), ])

    def add(self, data: dict[str, Any]) -> dict[str, Any]:
        ''' Save data from `/users` api

        Args:
            data (dict): The data responsed from api.

        Returns:
            Return the inserted / updated data.

        '''
        return self.find_one_and_update(
            {'_id': data['id']},
            {'$set': data},
            upsert=True,
            return_document=ReturnDocument.AFTER,
        )

add

add(data: dict[str, Any]) -> dict[str, Any]

Save data from /users api

Parameters:

Name Type Description Default
data dict

The data responsed from api.

required

Returns:

Type Description
dict[str, Any]

Return the inserted / updated data.

Source code in models/mattermostdb.py
def add(self, data: dict[str, Any]) -> dict[str, Any]:
    ''' Save data from `/users` api

    Args:
        data (dict): The data responsed from api.

    Returns:
        Return the inserted / updated data.

    '''
    return self.find_one_and_update(
        {'_id': data['id']},
        {'$set': data},
        upsert=True,
        return_document=ReturnDocument.AFTER,
    )

index

index() -> None

To make collection's index

Indexs
  • email
Source code in models/mattermostdb.py
def index(self) -> None:
    ''' To make collection's index

    Indexs:
        - `email`

    '''
    self.create_index([('email', 1), ])