aboutsummaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
Diffstat (limited to 'models')
-rw-r--r--models/Note.js2
-rw-r--r--models/NoteList.js13
-rw-r--r--models/User.js2
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()
})