docs update

This commit is contained in:
zadam
2022-12-14 23:51:56 +01:00
parent 239c68a33c
commit 8c01a77a7a
7 changed files with 426 additions and 99 deletions

View File

@@ -90,8 +90,9 @@ class Attribute extends AbstractEntity {
return this;
}
init() {
this.validate();
if (this.attributeId) {
this.becca.attributes[this.attributeId] = this;
}
@@ -114,6 +115,16 @@ class Attribute extends AbstractEntity {
}
}
validate() {
if (!["label", "relation"].includes(this.type)) {
throw new Error(`Invalid attribute type '${this.type}' in attribute '${this.attributeId}'`);
}
if (!this.name?.trim()) {
throw new Error(`Invalid empty name in attribute '${this.attributeId}'`);
}
}
get isAffectingSubtree() {
return this.isInheritable
|| (this.type === 'relation' && this.name === 'template');
@@ -141,7 +152,13 @@ class Attribute extends AbstractEntity {
* @returns {Note|null}
*/
getNote() {
return this.becca.getNote(this.noteId);
const note = this.becca.getNote(this.noteId);
if (!note) {
throw new Error(`Note '${this.noteId}' of attribute '${this.attributeId}', type '${this.type}', name '${this.name}' does not exist.`);
}
return note;
}
/**
@@ -185,11 +202,13 @@ class Attribute extends AbstractEntity {
}
beforeSaving() {
if (!this.value) {
if (this.type === 'relation') {
throw new Error(`Cannot save relation ${this.name} since it does not target any note.`);
}
this.validate();
if (this.type === 'relation') {
if (!(this.value in this.becca.notes)) {
throw new Error(`Cannot save relation '${this.name}' since it target not existing note '${this.value}'.`);
}
} else if (!this.value) {
// null value isn't allowed
this.value = "";
}