diff options
author | 2021-08-21 00:24:01 +0200 | |
---|---|---|
committer | 2021-08-21 00:24:01 +0200 | |
commit | a9d3686ccc496044cfdee013ccfbece955793052 (patch) | |
tree | 52b7772720ff89b1b6f20070a771776f0b3e9367 /models | |
parent | 9f3c030a33edcf57eb832c500253044d107f6e25 (diff) | |
download | my_apps-a9d3686ccc496044cfdee013ccfbece955793052.tar.gz my_apps-a9d3686ccc496044cfdee013ccfbece955793052.tar.bz2 my_apps-a9d3686ccc496044cfdee013ccfbece955793052.zip |
icon focus, notes update timestamp, loading note
Diffstat (limited to 'models')
-rw-r--r-- | models/Note.js | 2 | ||||
-rw-r--r-- | models/NoteList.js | 13 | ||||
-rw-r--r-- | models/User.js | 2 |
3 files changed, 11 insertions, 6 deletions
diff --git a/models/Note.js b/models/Note.js index 3f94e62..4e1956e 100644 --- a/models/Note.js +++ b/models/Note.js @@ -26,7 +26,7 @@ noteSchema.pre('save', async function(next){ const note = this; if (note.isModified('content')) { - note.content = await encrypt(note.content) + note.content = encrypt(note.content) } next() diff --git a/models/NoteList.js b/models/NoteList.js index 1cac218..159364f 100644 --- a/models/NoteList.js +++ b/models/NoteList.js @@ -1,12 +1,13 @@ const {encrypt, decrypt} = require('lib/crypt') const mongoose = require("mongoose") -const decryptTitles = (l) => ({notes: l.notes.map(n => ({ ...n, title: decrypt(n.title)}))}) +const decryptTitles = l => ({notes: l.notes.map(n => ({ ...n, title: decrypt(n.title)}))}) const noteListSchema = new mongoose.Schema({ notes: [{ title: { type: String, + maxlength: 1000, required: true, }, noteId: { @@ -19,7 +20,6 @@ const noteListSchema = new mongoose.Schema({ }] }) - noteListSchema.statics.getList = async (id) => { const newList = await NoteList.findById(id).lean() @@ -50,9 +50,12 @@ 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 ? title : 'No title') } }, - { new: true } + {_id, "notes.noteId": noteId}, + {$set: { + "notes.$.title": encrypt(title ? title : 'No title'), + "notes.$.updated_at": Date.now(), + }}, + {new: true} ).lean() return decryptTitles(noteList) diff --git a/models/User.js b/models/User.js index ecc54cd..fa3303f 100644 --- a/models/User.js +++ b/models/User.js @@ -98,6 +98,8 @@ userSchema.pre('save', async function(next){ user.password = await bcrypt.hash(user.password, 8); } + user.updated_at = Date.now() + next() }) |