2018-01-30 07:34:59 +08:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
const Entity = require('./entity');
|
2018-04-20 12:12:01 +08:00
|
|
|
const protectedSessionService = require('../services/protected_session');
|
2018-03-31 22:51:37 +08:00
|
|
|
const repository = require('../services/repository');
|
2018-01-30 07:34:59 +08:00
|
|
|
|
|
|
|
class NoteRevision extends Entity {
|
2018-08-17 05:00:04 +08:00
|
|
|
static get entityName() { return "note_revisions"; }
|
2018-01-31 09:12:19 +08:00
|
|
|
static get primaryKeyName() { return "noteRevisionId"; }
|
2018-08-07 17:38:00 +08:00
|
|
|
static get hashedProperties() { return ["noteRevisionId", "noteId", "title", "content", "isProtected", "dateModifiedFrom", "dateModifiedTo"]; }
|
2018-01-30 12:35:36 +08:00
|
|
|
|
2018-03-31 22:51:37 +08:00
|
|
|
constructor(row) {
|
|
|
|
super(row);
|
|
|
|
|
2018-08-07 17:38:00 +08:00
|
|
|
this.isProtected = !!this.isProtected;
|
|
|
|
|
2018-03-31 22:51:37 +08:00
|
|
|
if (this.isProtected) {
|
2018-04-20 12:12:01 +08:00
|
|
|
protectedSessionService.decryptNoteRevision(this);
|
2018-03-31 22:51:37 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-30 07:34:59 +08:00
|
|
|
async getNote() {
|
2018-03-31 22:51:37 +08:00
|
|
|
return await repository.getEntity("SELECT * FROM notes WHERE noteId = ?", [this.noteId]);
|
|
|
|
}
|
|
|
|
|
|
|
|
beforeSaving() {
|
|
|
|
if (this.isProtected) {
|
2018-04-20 12:12:01 +08:00
|
|
|
protectedSessionService.encryptNoteRevision(this);
|
2018-03-31 22:51:37 +08:00
|
|
|
}
|
2018-08-06 14:59:26 +08:00
|
|
|
|
|
|
|
super.beforeSaving();
|
2018-01-30 07:34:59 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = NoteRevision;
|