trilium/src/entities/note_revision.js

35 lines
916 B
JavaScript
Raw Normal View History

"use strict";
const Entity = require('./entity');
const protected_session = require('../services/protected_session');
2018-04-02 05:38:24 +08:00
const utils = require('../services/utils');
const repository = require('../services/repository');
class NoteRevision extends Entity {
2018-01-30 12:35:36 +08:00
static get tableName() { return "note_revisions"; }
2018-01-31 09:12:19 +08:00
static get primaryKeyName() { return "noteRevisionId"; }
2018-01-30 12:35:36 +08:00
constructor(row) {
super(row);
if (this.isProtected) {
protected_session.decryptNoteRevision(this);
}
}
async getNote() {
return await repository.getEntity("SELECT * FROM notes WHERE noteId = ?", [this.noteId]);
}
beforeSaving() {
2018-04-02 05:38:24 +08:00
if (!this.noteRevisionId) {
this.noteRevisionId = utils.newNoteRevisionId();
}
if (this.isProtected) {
protected_session.encryptNoteRevision(this);
}
}
}
module.exports = NoteRevision;