From a9d3686ccc496044cfdee013ccfbece955793052 Mon Sep 17 00:00:00 2001 From: piotrruss Date: Sat, 21 Aug 2021 00:24:01 +0200 Subject: icon focus, notes update timestamp, loading note --- models/NoteList.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'models/NoteList.js') 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) -- cgit v1.2.3