chore: add new route for the restore from trash

This commit is contained in:
mahyargdz
2025-07-12 12:17:49 +03:30
parent 352cdde13f
commit 97383d25f6
3 changed files with 51 additions and 0 deletions
@@ -663,4 +663,45 @@ export class EmailService {
throw error;
}
}
//==============================================
async moveMessageToInboxFromTrash(userId: string, messageId: number) {
this.logger.log(`Moving message ${messageId} from trash to inbox for user: ${userId}`);
try {
const inboxMailboxId = await this.mailboxResolverService.getInboxMailboxId(userId);
const trashMailboxId = await this.mailboxResolverService.getTrashMailboxId(userId);
const result = await firstValueFrom(
this.mailServerService.messages.updateMessage(userId, trashMailboxId, messageId, {
moveTo: inboxMailboxId,
}),
);
// Emit WebSocket notification
const payload: EmailMovePayload = {
messageId,
userId,
fromMailboxId: trashMailboxId,
toMailboxId: inboxMailboxId,
fromMailboxName: "Trash",
toMailboxName: "Inbox",
timestamp: new Date().toISOString(),
};
await this.emailGateway.notifyMessageMoved(payload);
this.logger.log(`Message ${messageId} moved from trash to inbox successfully`);
return {
success: true,
message: EmailMessage.MESSAGE_MOVED_TO_INBOX_FROM_TRASH_SUCCESSFULLY,
result,
};
} catch (error) {
this.logger.error(
`Failed to move message ${messageId} from trash to inbox for user ${userId}: ${error instanceof Error ? error.message : "Unknown error"}`,
);
throw error;
}
}
}