trilium/src/entities/entity.js
azivner 5f36856571 * refactoring of repository layer to represent booleans as true/false instead of 1/0
* show list of inherited attributes, fixes #136
* properly work with inheritance
2018-08-07 11:38:00 +02:00

37 lines
823 B
JavaScript

"use strict";
const utils = require('../services/utils');
class Entity {
constructor(row = {}) {
for (const key in row) {
this[key] = row[key];
}
if ('isDeleted' in this) {
this.isDeleted = !!this.isDeleted;
}
}
beforeSaving() {
if (!this[this.constructor.primaryKeyName]) {
this[this.constructor.primaryKeyName] = utils.newEntityId();
}
let contentToHash = "";
for (const propertyName of this.constructor.hashedProperties) {
contentToHash += "|" + this[propertyName];
}
this["hash"] = utils.hash(contentToHash).substr(0, 10);
}
async save() {
await require('../services/repository').updateEntity(this);
return this;
}
}
module.exports = Entity;