Skip to content

Commit

Permalink
feat: Added router clear-all-chats
Browse files Browse the repository at this point in the history
  • Loading branch information
icleitoncosta committed Aug 9, 2022
1 parent 26179b8 commit b818bae
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/controller/deviceController.js
Expand Up @@ -263,6 +263,19 @@ export async function clearChat(req, res) {
}
}

export async function clearAllChats(req, res) {
try {
const chats = await req.client.getAllChats();
for (const chat of chats) {
await req.client.clearChat(`${chat.chatId}`);
}
return res.status(201).json({ status: 'success' });
} catch (e) {
req.logger.error(e);
return res.status(500).json({ status: 'error', message: 'Error on clear all chats' });
}
}

export async function archiveChat(req, res) {
const { phone, value = true } = req.body;

Expand Down
1 change: 1 addition & 0 deletions src/routes/index.js
Expand Up @@ -181,6 +181,7 @@ routes.get('/api/:session/get-messages/:phone', verifyToken, statusConnection, D
routes.post('/api/:session/archive-chat', verifyToken, statusConnection, DeviceController.archiveChat);
routes.post('/api/:session/archive-all-chats', verifyToken, statusConnection, DeviceController.archiveAllChats);
routes.post('/api/:session/clear-chat', verifyToken, statusConnection, DeviceController.clearChat);
routes.post('/api/:session/clear-all-chats', verifyToken, statusConnection, DeviceController.clearAllChats);
routes.post('/api/:session/delete-chat', verifyToken, statusConnection, DeviceController.deleteChat);
routes.post('/api/:session/delete-all-chats', verifyToken, statusConnection, DeviceController.deleteAllChats);
routes.post('/api/:session/delete-message', verifyToken, statusConnection, DeviceController.deleteMessage);
Expand Down

0 comments on commit b818bae

Please sign in to comment.