(20241205) Accepting many token ids to list mails.
This commit is contained in:
@@ -46,7 +46,7 @@ from models.behaviour.base import BaseModel
|
||||
from bson import ObjectId
|
||||
|
||||
# To work with datatypes:
|
||||
from typing import Literal
|
||||
from typing import Literal, List
|
||||
|
||||
# For asynchronous activities:
|
||||
import asyncio
|
||||
@@ -142,7 +142,7 @@ class MailRetrieveModel(BaseModel):
|
||||
async def list_for_token_id(
|
||||
self,
|
||||
mongo_conn: AsyncMongo,
|
||||
token_id: str | ObjectId,
|
||||
token_id: str | ObjectId | List[str | ObjectId],
|
||||
limit: int = 25,
|
||||
skip: int = 0
|
||||
):
|
||||
@@ -150,16 +150,20 @@ class MailRetrieveModel(BaseModel):
|
||||
"""
|
||||
To enlist mails for one account.
|
||||
:param mongo_conn: The instance of the database connector to use to get the mail's data.
|
||||
:param token_id: The id of the document in the database that holds the tokens to access the account.
|
||||
:param token_id: The id(s) of the document in the database that holds the tokens to access the account.
|
||||
:param limit: How many records to fetch.
|
||||
:param skip: How many initial records to skip. useful for pagination.
|
||||
:return: Either the JSON that describes the mails or None if something failed.
|
||||
"""
|
||||
|
||||
# Ensure that the token ids are in expected format:
|
||||
if not isinstance(token_id, list): token_id = [token_id]
|
||||
token_id = [ObjectId(t) for t in token_id]
|
||||
|
||||
# Get the data from the database:
|
||||
mails_list = await mongo_conn.find_many(
|
||||
collection = self.MAIL_COLLECTION,
|
||||
filter = {"tokenId": ObjectId(token_id)},
|
||||
filter = {"tokenId": {"$in": token_id}},
|
||||
projection = {
|
||||
"_id": True,
|
||||
"serviceType": True,
|
||||
|
||||
@@ -389,7 +389,7 @@ class MailSyncModel(BaseModel):
|
||||
db_conn = current_app.sql_writer,
|
||||
mongo_conn = mongo_conn,
|
||||
token_id = token_id,
|
||||
email_id = tokens.email,
|
||||
client_user_id = tokens.client_user_id,
|
||||
token = tokens,
|
||||
session_token = session_token
|
||||
)
|
||||
|
||||
@@ -37,7 +37,7 @@ sys.path.append("..")
|
||||
|
||||
# For making data behaviour_models:
|
||||
from pydantic import BaseModel, Field, field_validator, PastDatetime
|
||||
from typing import Optional, Literal
|
||||
from typing import Optional, Literal, List
|
||||
|
||||
# My utils:
|
||||
from utils_v2.string import regex
|
||||
@@ -101,8 +101,8 @@ class MailListRequestHeaders(BaseModel):
|
||||
|
||||
class MailListByAccountIdRequestData(BaseModel):
|
||||
|
||||
tokenId: str = Field(
|
||||
description = "the account identifier (Mongo ObjectId) granted by 'MailOAuthModel.get_account_identifier'",
|
||||
tokenId: str | List[str] = Field(
|
||||
description = "the account identifier(s) (Mongo ObjectId) granted by 'MailOAuthModel.get_account_identifier'",
|
||||
frozen = True
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user