chore: add new route to get favorinte and archive mailboxx messsage

This commit is contained in:
mahyargdz
2025-07-10 12:16:55 +03:30
parent 7ebd83cce3
commit 935cc50cb1
4 changed files with 100 additions and 3 deletions
@@ -193,6 +193,63 @@ export class EmailService {
throw error;
}
}
//==============================================
async getJunkMessages(userId: string, query: MessageListQueryDto) {
try {
const junkMailboxId = await this.mailboxResolverService.getJunkMailboxId(userId);
const { results: junkMails, total: count } = await firstValueFrom(this.mailServerService.messages.listMessages(userId, junkMailboxId, query));
return {
junkMails,
count,
paginate: true,
};
} catch (error) {
this.logger.error(`Failed to get junk messages for user ${userId}: ${error instanceof Error ? error.message : "Unknown error"}`);
throw error;
}
}
//==============================================
async getArchivedMessages(userId: string, query: MessageListQueryDto) {
try {
const archiveMailboxId = await this.mailboxResolverService.getArchiveMailboxId(userId);
const { results: archiveMails, total: count } = await firstValueFrom(
this.mailServerService.messages.listMessages(userId, archiveMailboxId, query),
);
return {
archiveMails,
count,
paginate: true,
};
} catch (error) {
this.logger.error(`Failed to get archive messages for user ${userId}: ${error instanceof Error ? error.message : "Unknown error"}`);
throw error;
}
}
//==============================================
async getFavoriteMessages(userId: string, query: MessageListQueryDto) {
try {
const favoriteMailboxId = await this.mailboxResolverService.getFavoriteMailboxId(userId);
const { results: favoriteMails, total: count } = await firstValueFrom(
this.mailServerService.messages.listMessages(userId, favoriteMailboxId, query),
);
return {
favoriteMails,
count,
paginate: true,
};
} catch (error) {
this.logger.error(`Failed to get junk messages for user ${userId}: ${error instanceof Error ? error.message : "Unknown error"}`);
throw error;
}
}
//==============================================
async getDraftsMessages(userId: string, query: MessageListQueryDto) {
try {