From ef8d5215e8115ac47d058a667a93b27bc0887a7f Mon Sep 17 00:00:00 2001 From: piotrruss Date: Fri, 6 May 2022 17:19:48 +0100 Subject: small fixes --- apps/Notes/models/NoteList.js | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) (limited to 'apps/Notes/models/NoteList.js') diff --git a/apps/Notes/models/NoteList.js b/apps/Notes/models/NoteList.js index 0af648a..7bad163 100644 --- a/apps/Notes/models/NoteList.js +++ b/apps/Notes/models/NoteList.js @@ -49,16 +49,25 @@ noteListSchema.statics.removeNote = async (_id, id) => { } noteListSchema.statics.updateList = async (_id, noteId, title) => { - const noteList = await NoteList.findOneAndUpdate( - { _id, 'notes.noteId': noteId }, - { - $set: { - 'notes.$.title': encrypt(title || 'No title'), - 'notes.$.updated_at': Date.now() - } - }, - { new: true } - ).lean() + const noteList = title + ? await NoteList.findOneAndUpdate( + { _id, 'notes.noteId': noteId }, + { + $set: { + 'notes.$.title': encrypt(title || 'No title'), + 'notes.$.updated_at': Date.now() + } + }, + { new: true } + ).lean() : await NoteList.findOneAndUpdate( + { _id, 'notes.noteId': noteId }, + { + $set: { + 'notes.$.updated_at': Date.now() + } + }, + { new: true } + ).lean() return decryptTitles(noteList) } -- cgit v1.2.3