update note implemented

This commit is contained in:
Christian Müller
2015-10-18 09:42:27 +02:00
parent b078891190
commit 8786543ec2
4 changed files with 29 additions and 7 deletions
+3 -2
View File
@@ -11,11 +11,12 @@ var buildPage = (id, title, content) => pageTemplate
module.exports.buildNote = note => buildPage(note.id, note.title, marked(note.text));
module.exports.newNotePage = session => editTemplate
.replace("%METHOD%", "POST")
.replace("%ACTION%", "POST")
.replace("%SESSION%", session)
.replace("%CONTENT%", "Loading...");
module.exports.editNotePage = (session, note) => editTemplate
.replace("%METHOD%", "UPDATE")
.replace("%ACTION%", "UPDATE")
.replace("%SESSION%", session)
.replace("%ID%", note.id)
.replace("%CONTENT%", note.text);
+9 -1
View File
@@ -47,4 +47,12 @@ module.exports.addNote = (note, password) => getFreeId().then(id => Note.create(
id: id,
text: note,
password: password
}));
}));
module.exports.updateNote = (id, password, text) => Note.findById(id).then(note => {
if (!note || note.password !== password) return new Promise((resolve, reject) => {
reject({ message: "Password is wrong" });
});
note.text = text;
return note.save();
});