chore: add new route for the restore from trash
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user