2018-11-08 10:11:00 +01:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
const Entity = require('./entity');
|
|
|
|
const repository = require('../services/repository');
|
|
|
|
const dateUtils = require('../services/date_utils');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This class represents link from one note to another in the form of hyperlink or image reference. Note that
|
|
|
|
* this is different concept than attribute/relation.
|
|
|
|
*
|
|
|
|
* @param {string} linkId
|
|
|
|
* @param {string} noteId
|
|
|
|
* @param {string} targetNoteId
|
|
|
|
* @param {string} type
|
|
|
|
* @param {boolean} isDeleted
|
2019-03-12 20:58:31 +01:00
|
|
|
* @param {string} utcDateModified
|
|
|
|
* @param {string} utcDateCreated
|
2018-11-08 10:11:00 +01:00
|
|
|
*
|
|
|
|
* @extends Entity
|
|
|
|
*/
|
|
|
|
class Link extends Entity {
|
2019-06-09 11:16:00 +02:00
|
|
|
static get entityName() { return "links"; }
|
2018-11-08 10:11:00 +01:00
|
|
|
static get primaryKeyName() { return "linkId"; }
|
2019-03-12 20:58:31 +01:00
|
|
|
static get hashedProperties() { return ["linkId", "noteId", "targetNoteId", "type", "isDeleted", "utcDateCreated", "utcDateModified"]; }
|
2018-11-08 10:11:00 +01:00
|
|
|
|
|
|
|
async getNote() {
|
|
|
|
return await repository.getEntity("SELECT * FROM notes WHERE noteId = ?", [this.noteId]);
|
|
|
|
}
|
|
|
|
|
|
|
|
async getTargetNote() {
|
|
|
|
return await repository.getEntity("SELECT * FROM notes WHERE noteId = ?", [this.targetNoteId]);
|
|
|
|
}
|
|
|
|
|
|
|
|
beforeSaving() {
|
|
|
|
if (!this.isDeleted) {
|
|
|
|
this.isDeleted = false;
|
|
|
|
}
|
|
|
|
|
2019-03-12 20:58:31 +01:00
|
|
|
if (!this.utcDateCreated) {
|
2019-03-13 22:43:59 +01:00
|
|
|
this.utcDateCreated = dateUtils.utcNowDateTime();
|
2018-11-08 10:11:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
super.beforeSaving();
|
|
|
|
|
|
|
|
if (this.isChanged) {
|
2019-03-13 22:43:59 +01:00
|
|
|
this.utcDateModified = dateUtils.utcNowDateTime();
|
2018-11-08 10:11:00 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = Link;
|