added runOnAttributeChange event

This commit is contained in:
azivner
2018-08-09 20:08:00 +02:00
parent 5b15424498
commit ac25770c0e
11 changed files with 80 additions and 30 deletions

View File

@@ -28,6 +28,18 @@ class Attribute extends Entity {
return await repository.getEntity("SELECT * FROM notes WHERE noteId = ?", [this.noteId]);
}
async getTargetNote() {
if (this.type !== 'relation') {
throw new Error(`Attribute ${this.attributeId} is not relation`);
}
if (!this.value) {
return null;
}
return await repository.getEntity("SELECT * FROM notes WHERE noteId = ?", [this.value]);
}
isDefinition() {
return this.type === 'label-definition' || this.type === 'relation-definition';
}

View File

@@ -9,6 +9,22 @@ const ApiToken = require('../entities/api_token');
const Option = require('../entities/option');
const repository = require('../services/repository');
const TABLE_NAME_TO_ENTITY = {
"attributes": Attribute.constructor,
"images": Image.constructor,
"note_images": NoteImage.constructor,
"branches": Branch.constructor,
"notes": Note.constructor,
"note_revisions": NoteRevision.constructor,
"recent_notes": RecentNote.constructor,
"options": Option.constructor,
"api_tokens": ApiToken.constructor,
};
function getEntityFromTableName(tableName) {
return TABLE_NAME_TO_ENTITY[tableName];
}
function createEntityFromRow(row) {
let entity;
@@ -46,8 +62,9 @@ function createEntityFromRow(row) {
return entity;
}
repository.setEntityConstructor(createEntityFromRow);
module.exports = {
createEntityFromRow
};
createEntityFromRow,
getEntityFromTableName
};
repository.setEntityConstructor(module.exports);