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
+2
View File
@@ -197,6 +197,8 @@ export const enum EmailMessage {
DRAFT_UPDATED_SUCCESSFULLY = "پیش نویس با موفقیت به روز رسانی شد", DRAFT_UPDATED_SUCCESSFULLY = "پیش نویس با موفقیت به روز رسانی شد",
DRAFT_SENT_SUCCESSFULLY = "پیش نویس با موفقیت ارسال شد", DRAFT_SENT_SUCCESSFULLY = "پیش نویس با موفقیت ارسال شد",
DRAFT_DELETED_SUCCESSFULLY = "پیش نویس با موفقیت حذف شد", DRAFT_DELETED_SUCCESSFULLY = "پیش نویس با موفقیت حذف شد",
MESSAGE_MOVED_TO_ARCHIVE_SUCCESSFULLY = "پیام با موفقیت به آرشیو منتقل شد",
MESSAGE_MOVED_TO_FAVORITE_SUCCESSFULLY = "پیام با موفقیت به علاقه مندی ها منتقل شد",
} }
export const enum SmsMessage { export const enum SmsMessage {
+18
View File
@@ -145,4 +145,22 @@ export class EmailController {
deleteDraft(@UserDec("wildduckUserId") userId: string, @Param() params: MessageParamDto) { deleteDraft(@UserDec("wildduckUserId") userId: string, @Param() params: MessageParamDto) {
return this.emailService.deleteDraft(userId, Number(params.messageId)); return this.emailService.deleteDraft(userId, Number(params.messageId));
} }
@Patch("messages/:messageId/archive")
@ApiOperation({ summary: "Move a message to archive mailbox" })
@ApiResponse({ status: 200, description: "Message moved to archive successfully" })
@ApiResponse({ status: 404, description: "Message not found" })
@ApiResponse({ status: 403, description: "Not authorized to move message" })
moveMessageToArchive(@UserDec("wildduckUserId") userId: string, @Param() params: MessageParamDto) {
return this.emailService.moveMessageToArchive(userId, Number(params.messageId));
}
@Patch("messages/:messageId/favorite")
@ApiOperation({ summary: "Move a message to favorite mailbox" })
@ApiResponse({ status: 200, description: "Message moved to favorite successfully" })
@ApiResponse({ status: 404, description: "Message not found" })
@ApiResponse({ status: 403, description: "Not authorized to move message" })
moveMessageToFavorite(@UserDec("wildduckUserId") userId: string, @Param() params: MessageParamDto) {
return this.emailService.moveMessageToFavorite(userId, Number(params.messageId));
}
} }
@@ -365,4 +365,62 @@ export class EmailService {
throw error; 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;
}
}
} }