aboutsummaryrefslogtreecommitdiffstats
path: root/apps/Notes/models
diff options
context:
space:
mode:
Diffstat (limited to 'apps/Notes/models')
-rw-r--r--apps/Notes/models/Note.js4
-rw-r--r--apps/Notes/models/NoteList.js29
2 files changed, 21 insertions, 12 deletions
diff --git a/apps/Notes/models/Note.js b/apps/Notes/models/Note.js
index 0f4b3f9..c8cf854 100644
--- a/apps/Notes/models/Note.js
+++ b/apps/Notes/models/Note.js
@@ -11,7 +11,7 @@ noteSchema.statics.getNote = async (id) => {
const content = decrypt(note.content)
- return { ...note, content }
+ return { _id: note._id, content }
}
noteSchema.statics.updateNote = async (id, content) => {
@@ -19,7 +19,7 @@ noteSchema.statics.updateNote = async (id, content) => {
if (!note) throw new Error('Could not update note')
- return { ...note, content }
+ return { _id: note._id, content }
}
noteSchema.pre('save', async function (next) {
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)
}