Notes/src/entities/note_revision.js
2018-04-01 17:38:24 -04:00

35 lines
916 B
JavaScript

"use strict";
const Entity = require('./entity');
const protected_session = require('../services/protected_session');
const utils = require('../services/utils');
const repository = require('../services/repository');
class NoteRevision extends Entity {
static get tableName() { return "note_revisions"; }
static get primaryKeyName() { return "noteRevisionId"; }
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() {
if (!this.noteRevisionId) {
this.noteRevisionId = utils.newNoteRevisionId();
}
if (this.isProtected) {
protected_session.encryptNoteRevision(this);
}
}
}
module.exports = NoteRevision;