chore: add logic to add to favorite and archive
This commit is contained in:
@@ -197,6 +197,8 @@ export const enum EmailMessage {
|
||||
DRAFT_UPDATED_SUCCESSFULLY = "پیش نویس با موفقیت به روز رسانی شد",
|
||||
DRAFT_SENT_SUCCESSFULLY = "پیش نویس با موفقیت ارسال شد",
|
||||
DRAFT_DELETED_SUCCESSFULLY = "پیش نویس با موفقیت حذف شد",
|
||||
MESSAGE_MOVED_TO_ARCHIVE_SUCCESSFULLY = "پیام با موفقیت به آرشیو منتقل شد",
|
||||
MESSAGE_MOVED_TO_FAVORITE_SUCCESSFULLY = "پیام با موفقیت به علاقه مندی ها منتقل شد",
|
||||
}
|
||||
|
||||
export const enum SmsMessage {
|
||||
|
||||
@@ -145,4 +145,22 @@ export class EmailController {
|
||||
deleteDraft(@UserDec("wildduckUserId") userId: string, @Param() params: MessageParamDto) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
//==============================================
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user