Link entity migrated to Attribute, WIP

This commit is contained in:
zadam
2019-08-19 20:12:00 +02:00
parent fd9b79e115
commit 3cb421143f
22 changed files with 172 additions and 174 deletions

View File

@@ -1,6 +1,5 @@
const Note = require('../entities/note');
const NoteRevision = require('../entities/note_revision');
const Link = require('../entities/link');
const Branch = require('../entities/branch');
const Attribute = require('../entities/attribute');
const RecentNote = require('../entities/recent_note');
@@ -16,7 +15,6 @@ const ENTITY_NAME_TO_ENTITY = {
"recent_notes": RecentNote,
"options": Option,
"api_tokens": ApiToken,
"links": Link
};
function getEntityFromEntityName(entityName) {
@@ -36,9 +34,6 @@ function createEntityFromRow(row) {
else if (row.noteRevisionId) {
entity = new NoteRevision(row);
}
else if (row.linkId) {
entity = new Link(row);
}
else if (row.branchId && row.notePath) {
entity = new RecentNote(row);
}

View File

@@ -1,51 +0,0 @@
"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
* @param {string} utcDateModified
* @param {string} utcDateCreated
*
* @extends Entity
*/
class Link extends Entity {
static get entityName() { return "links"; }
static get primaryKeyName() { return "linkId"; }
static get hashedProperties() { return ["linkId", "noteId", "targetNoteId", "type", "isDeleted", "utcDateCreated", "utcDateModified"]; }
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;
}
if (!this.utcDateCreated) {
this.utcDateCreated = dateUtils.utcNowDateTime();
}
super.beforeSaving();
if (this.isChanged) {
this.utcDateModified = dateUtils.utcNowDateTime();
}
}
}
module.exports = Link;

View File

@@ -628,10 +628,17 @@ class Note extends Entity {
/**
* Get list of links coming out of this note.
*
* @returns {Promise<Link[]>}
* @deprecated - not intended for general use
* @returns {Promise<Attribute[]>}
*/
async getLinks() {
return await repository.getEntities("SELECT * FROM links WHERE noteId = ? AND isDeleted = 0", [this.noteId]);
return await repository.getEntities(`
SELECT *
FROM attributes
WHERE noteId = ? AND
isDeleted = 0 AND
type = 'relation' AND
name IN ('internal-link', 'image-link', 'relation-map-link')`, [this.noteId]);
}
/**