2018-01-29 18:34:59 -05:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
const Entity = require('./entity');
|
2018-04-20 00:12:01 -04:00
|
|
|
const protectedSessionService = require('../services/protected_session');
|
2018-03-31 10:51:37 -04:00
|
|
|
const repository = require('../services/repository');
|
2018-01-29 18:34:59 -05:00
|
|
|
|
2018-08-22 23:37:06 +02:00
|
|
|
/**
|
|
|
|
* NoteRevision represents snapshot of note's title and content at some point in the past. It's used for seamless note versioning.
|
|
|
|
*
|
|
|
|
* @param {string} noteRevisionId
|
|
|
|
* @param {string} noteId
|
|
|
|
* @param {string} type
|
|
|
|
* @param {string} mime
|
|
|
|
* @param {string} title
|
|
|
|
* @param {string} content
|
|
|
|
* @param {string} isProtected
|
2019-03-13 22:43:59 +01:00
|
|
|
* @param {string} dateModifiedFrom
|
|
|
|
* @param {string} dateModifiedTo
|
2019-03-12 20:58:31 +01:00
|
|
|
* @param {string} utcDateModifiedFrom
|
|
|
|
* @param {string} utcDateModifiedTo
|
2018-08-22 23:37:06 +02:00
|
|
|
*
|
|
|
|
* @extends Entity
|
|
|
|
*/
|
2018-01-29 18:34:59 -05:00
|
|
|
class NoteRevision extends Entity {
|
2018-08-16 23:00:04 +02:00
|
|
|
static get entityName() { return "note_revisions"; }
|
2018-01-30 20:12:19 -05:00
|
|
|
static get primaryKeyName() { return "noteRevisionId"; }
|
2019-03-13 22:43:59 +01:00
|
|
|
static get hashedProperties() { return ["noteRevisionId", "noteId", "title", "content", "isProtected", "dateModifiedFrom", "dateModifiedTo", "utcDateModifiedFrom", "utcDateModifiedTo"]; }
|
2018-01-29 23:35:36 -05:00
|
|
|
|
2018-03-31 10:51:37 -04:00
|
|
|
constructor(row) {
|
|
|
|
super(row);
|
|
|
|
|
2018-08-07 11:38:00 +02:00
|
|
|
this.isProtected = !!this.isProtected;
|
|
|
|
|
2018-03-31 10:51:37 -04:00
|
|
|
if (this.isProtected) {
|
2018-04-20 00:12:01 -04:00
|
|
|
protectedSessionService.decryptNoteRevision(this);
|
2018-03-31 10:51:37 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-29 18:34:59 -05:00
|
|
|
async getNote() {
|
2018-03-31 10:51:37 -04:00
|
|
|
return await repository.getEntity("SELECT * FROM notes WHERE noteId = ?", [this.noteId]);
|
|
|
|
}
|
|
|
|
|
|
|
|
beforeSaving() {
|
|
|
|
if (this.isProtected) {
|
2018-04-20 00:12:01 -04:00
|
|
|
protectedSessionService.encryptNoteRevision(this);
|
2018-03-31 10:51:37 -04:00
|
|
|
}
|
2018-08-06 08:59:26 +02:00
|
|
|
|
|
|
|
super.beforeSaving();
|
2018-01-29 18:34:59 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = NoteRevision;
|