2016-09-13 20:53:21 +00:00
|
|
|
"use strict";
|
2016-11-17 23:42:25 +00:00
|
|
|
/**
|
|
|
|
* sva - saveable decorator to be used on class properties
|
|
|
|
*/
|
|
|
|
function saveable(target, key) {
|
|
|
|
console.log('called sva');
|
|
|
|
if (!target.saveableProperties) {
|
|
|
|
target.saveableProperties = [];
|
|
|
|
}
|
|
|
|
target.saveableProperties.push(key);
|
|
|
|
}
|
|
|
|
exports.saveable = saveable;
|
2016-09-13 20:53:21 +00:00
|
|
|
class DbDoc {
|
2016-11-17 23:42:25 +00:00
|
|
|
/**
|
|
|
|
* class constructor
|
|
|
|
*/
|
2016-09-13 23:02:11 +00:00
|
|
|
constructor() {
|
|
|
|
this.collection = this.constructor['dbCollection'];
|
2016-09-13 20:53:21 +00:00
|
|
|
}
|
2016-11-17 23:42:25 +00:00
|
|
|
/**
|
|
|
|
* saves this instance but not any connected items
|
|
|
|
* may lead to data inconsistencies, but is faster
|
|
|
|
*/
|
2016-09-13 20:53:21 +00:00
|
|
|
save() {
|
2016-11-17 23:42:25 +00:00
|
|
|
let saveableObject = {};
|
|
|
|
for (let propertyNameString of this.saveableProperties) {
|
|
|
|
saveableObject[propertyNameString] = this[propertyNameString];
|
|
|
|
}
|
2016-09-13 20:53:21 +00:00
|
|
|
}
|
2016-11-17 23:42:25 +00:00
|
|
|
/**
|
|
|
|
* also store any referenced objects to DB
|
|
|
|
* better for data consistency
|
|
|
|
*/
|
2016-09-13 20:53:21 +00:00
|
|
|
saveDeep() {
|
2016-11-17 23:42:25 +00:00
|
|
|
this.save();
|
2016-09-13 20:53:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
exports.DbDoc = DbDoc;
|
2016-11-17 23:42:25 +00:00
|
|
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRkYXRhLmNsYXNzZXMuZGJkb2MuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydGRh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