chore: add logic to add to favorite and archive

This commit is contained in:
mahyargdz
2025-07-10 12:21:12 +03:30
parent 935cc50cb1
commit a761dc1718
3 changed files with 78 additions and 0 deletions
@@ -365,4 +365,62 @@ export class EmailService {
throw error;
}
}
//==============================================
async moveMessageToArchive(userId: string, messageId: number) {
this.logger.log(`Moving message ${messageId} to archive for user: ${userId}`);
try {
const inboxMailboxId = await this.mailboxResolverService.getInboxMailboxId(userId);
const archiveMailboxId = await this.mailboxResolverService.getArchiveMailboxId(userId);
const result = await firstValueFrom(
this.mailServerService.messages.updateMessage(userId, inboxMailboxId, messageId, {
moveTo: archiveMailboxId,
}),
);
this.logger.log(`Message ${messageId} moved to archive successfully`);
return {
success: true,
message: EmailMessage.MESSAGE_MOVED_TO_ARCHIVE_SUCCESSFULLY,
result,
};
} catch (error) {
this.logger.error(
`Failed to move message ${messageId} to archive for user ${userId}: ${error instanceof Error ? error.message : "Unknown error"}`,
);
throw error;
}
}
//==============================================
async moveMessageToFavorite(userId: string, messageId: number) {
this.logger.log(`Moving message ${messageId} to favorite for user: ${userId}`);
try {
const inboxMailboxId = await this.mailboxResolverService.getInboxMailboxId(userId);
const favoriteMailboxId = await this.mailboxResolverService.getFavoriteMailboxId(userId);
const result = await firstValueFrom(
this.mailServerService.messages.updateMessage(userId, inboxMailboxId, messageId, {
moveTo: favoriteMailboxId,
}),
);
this.logger.log(`Message ${messageId} moved to favorite successfully`);
return {
success: true,
message: EmailMessage.MESSAGE_MOVED_TO_FAVORITE_SUCCESSFULLY,
result,
};
} catch (error) {
this.logger.error(
`Failed to move message ${messageId} to favorite for user ${userId}: ${error instanceof Error ? error.message : "Unknown error"}`,
);
throw error;
}
}
}