mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
49 lines
962 B
JavaScript
49 lines
962 B
JavaScript
"use strict";
|
|
|
|
const utils = require('../../utils');
|
|
|
|
let repo = null;
|
|
|
|
class AbstractEntity {
|
|
beforeSaving() {
|
|
this.generateIdIfNecessary();
|
|
}
|
|
|
|
generateIdIfNecessary() {
|
|
if (!this[this.constructor.primaryKeyName]) {
|
|
this[this.constructor.primaryKeyName] = utils.newEntityId();
|
|
}
|
|
}
|
|
|
|
generateHash() {
|
|
let contentToHash = "";
|
|
|
|
for (const propertyName of this.constructor.hashedProperties) {
|
|
contentToHash += "|" + this[propertyName];
|
|
}
|
|
|
|
return utils.hash(contentToHash).substr(0, 10);
|
|
}
|
|
|
|
getUtcDateChanged() {
|
|
// FIXME
|
|
return this.utcDateModified || this.utcDateCreated || "FAKE";
|
|
}
|
|
|
|
get repository() {
|
|
if (!repo) {
|
|
repo = require('../../repository');
|
|
}
|
|
|
|
return repo;
|
|
}
|
|
|
|
save() {
|
|
this.repository.updateEntity(this);
|
|
|
|
return this;
|
|
}
|
|
}
|
|
|
|
module.exports = AbstractEntity;
|