aboutsummaryrefslogtreecommitdiffstats
path: root/models/NoteList.js
diff options
context:
space:
mode:
authorGravatar piotrruss <mail@pruss.it> 2021-08-21 00:24:01 +0200
committerGravatar piotrruss <mail@pruss.it> 2021-08-21 00:24:01 +0200
commita9d3686ccc496044cfdee013ccfbece955793052 (patch)
tree52b7772720ff89b1b6f20070a771776f0b3e9367 /models/NoteList.js
parent9f3c030a33edcf57eb832c500253044d107f6e25 (diff)
downloadmy_apps-a9d3686ccc496044cfdee013ccfbece955793052.tar.gz
my_apps-a9d3686ccc496044cfdee013ccfbece955793052.tar.bz2
my_apps-a9d3686ccc496044cfdee013ccfbece955793052.zip
icon focus, notes update timestamp, loading note
Diffstat (limited to 'models/NoteList.js')
-rw-r--r--models/NoteList.js13
1 files changed, 8 insertions, 5 deletions
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)