mirror of
https://github.com/zadam/trilium.git
synced 2024-11-15 12:17:01 +08:00
33 lines
No EOL
730 B
JavaScript
33 lines
No EOL
730 B
JavaScript
"use strict";
|
|
|
|
const utils = require('../services/utils');
|
|
|
|
class Entity {
|
|
constructor(row = {}) {
|
|
for (const key in row) {
|
|
this[key] = row[key];
|
|
}
|
|
}
|
|
|
|
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; |