mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 09:58:32 +02:00
support for updating entities etc.
This commit is contained in:
parent
6fa6891496
commit
35c7b54176
@ -3,6 +3,8 @@
|
||||
const Entity = require('./entity');
|
||||
|
||||
class Attribute extends Entity {
|
||||
static get tableName() { return "attributes"; }
|
||||
|
||||
async getNote() {
|
||||
return this.repository.getEntity("SELECT * FROM notes WHERE noteId = ?", [this.noteId]);
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ const utils = require('../services/utils');
|
||||
|
||||
class Entity {
|
||||
constructor(repository, row) {
|
||||
utils.assertArguments(repository, row)
|
||||
utils.assertArguments(repository, row);
|
||||
|
||||
this.repository = repository;
|
||||
|
||||
|
@ -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;
|
@ -3,6 +3,8 @@
|
||||
const Entity = require('./entity');
|
||||
|
||||
class NoteRevision extends Entity {
|
||||
static get tableName() { return "note_revisions"; }
|
||||
|
||||
async getNote() {
|
||||
return this.repository.getEntity("SELECT * FROM notes WHERE noteId = ?", [this.noteId]);
|
||||
}
|
||||
|
@ -3,6 +3,8 @@
|
||||
const Entity = require('./entity');
|
||||
|
||||
class NoteTree extends Entity {
|
||||
static get tableName() { return "note_tree"; }
|
||||
|
||||
async getNote() {
|
||||
return this.repository.getEntity("SELECT * FROM note_tree WHERE isDeleted = 0 AND noteId = ?", [this.noteId]);
|
||||
}
|
||||
|
@ -57,6 +57,20 @@ class Repository {
|
||||
|
||||
return entity;
|
||||
}
|
||||
|
||||
async updateEntity(entity) {
|
||||
if (entity.beforeSaving) {
|
||||
entity.beforeSaving();
|
||||
}
|
||||
|
||||
const clone = {...entity};
|
||||
|
||||
delete clone.dataKey;
|
||||
delete clone.jsonContent;
|
||||
delete clone.repository;
|
||||
|
||||
await sql.replace(entity.constructor.tableName, entity);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Repository;
|
Loading…
x
Reference in New Issue
Block a user