support for updating entities etc.

This commit is contained in:
azivner
2018-01-29 23:35:36 -05:00
parent 6fa6891496
commit 35c7b54176
6 changed files with 36 additions and 1 deletions

View File

@@ -1,11 +1,18 @@
"use strict";
const Entity = require('./entity');
const protected_session = require('../services/protected_session');
class Note extends Entity {
static get tableName() { return "notes"; }
constructor(repository, row) {
super(repository, row);
if (this.isProtected) {
protected_session.decryptNote(this.dataKey, this);
}
if (this.isJson()) {
this.jsonContent = JSON.parse(this.content);
}
@@ -30,6 +37,14 @@ class Note extends Entity {
async getTrees() {
return this.repository.getEntities("SELECT * FROM note_tree WHERE isDeleted = 0 AND noteId = ?", [this.noteId]);
}
beforeSaving() {
this.content = JSON.stringify(this.jsonContent, null, 4);
if (this.isProtected) {
protected_session.encryptNote(this.dataKey, this);
}
}
}
module.exports = Note;