(20241205) Accepting many token ids to list mails.

This commit is contained in:
2024-12-05 15:07:07 +05:30
parent 9b154a6cce
commit 2c053fa6f2
7 changed files with 19 additions and 11 deletions
+8 -4
View File
@@ -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,
+1 -1
View File
@@ -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
)