From 48d33906fc16f053bc4453dd7e037a6c7ed21a08 Mon Sep 17 00:00:00 2001 From: SebClem Date: Wed, 26 Oct 2022 14:09:10 +0200 Subject: [PATCH] :hammer: Message can be readed --- nextcloud_backup/backend/src/routes/messages.ts | 10 +++++++++- .../backend/src/tools/messageManager.ts | 13 +++++++++++++ .../frontend/src/components/MessageBar.vue | 14 ++++++++++---- .../frontend/src/components/NavbarComponent.vue | 11 ++++++++--- .../frontend/src/services/messageService.ts | 4 ++++ 5 files changed, 44 insertions(+), 8 deletions(-) diff --git a/nextcloud_backup/backend/src/routes/messages.ts b/nextcloud_backup/backend/src/routes/messages.ts index 58c512e..dd920ea 100644 --- a/nextcloud_backup/backend/src/routes/messages.ts +++ b/nextcloud_backup/backend/src/routes/messages.ts @@ -5,6 +5,14 @@ const messageRouter = express.Router(); messageRouter.get('/', (req, res, next)=>{ res.json(messageManager.get()) -}) +}); + +messageRouter.patch('/:messageId/readed', (req, res, next)=>{ + if(messageManager.markReaded(req.params.messageId)){ + res.json(messageManager.get()); + }else{ + res.status(404).send(); + } +}); export default messageRouter; diff --git a/nextcloud_backup/backend/src/tools/messageManager.ts b/nextcloud_backup/backend/src/tools/messageManager.ts index b0915ad..7b9d0f3 100644 --- a/nextcloud_backup/backend/src/tools/messageManager.ts +++ b/nextcloud_backup/backend/src/tools/messageManager.ts @@ -40,6 +40,19 @@ class MessageManager { public get(){ return this.messages; } + + public getById(id: string){ + return this.messages.find(value=>value.id == id); + } + + public markReaded(id: string){ + const index = this.messages.findIndex(value=>value.id == id); + if(index == -1){ + return false; + } + this.messages[index].viewed = true; + return true; + } } diff --git a/nextcloud_backup/frontend/src/components/MessageBar.vue b/nextcloud_backup/frontend/src/components/MessageBar.vue index 71f527c..147499a 100644 --- a/nextcloud_backup/frontend/src/components/MessageBar.vue +++ b/nextcloud_backup/frontend/src/components/MessageBar.vue @@ -36,7 +36,7 @@