46 lines
2.5 KiB
JavaScript
46 lines
2.5 KiB
JavaScript
"use strict";
|
|
/**
|
|
* saveable - 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;
|
|
class DbDoc {
|
|
/**
|
|
* class constructor
|
|
*/
|
|
constructor() {
|
|
this.collection = this.constructor['dbCollection'];
|
|
}
|
|
/**
|
|
* saves this instance but not any connected items
|
|
* may lead to data inconsistencies, but is faster
|
|
*/
|
|
save() {
|
|
let saveableObject = {};
|
|
for (let propertyNameString of this.saveableProperties) {
|
|
saveableObject[propertyNameString] = this[propertyNameString];
|
|
}
|
|
switch (this.creationType) {
|
|
case 'db':
|
|
this.collection; // TODO implement collection.update()
|
|
break;
|
|
case 'new':
|
|
this.collection.insertOne(saveableObject);
|
|
}
|
|
}
|
|
/**
|
|
* also store any referenced objects to DB
|
|
* better for data consistency
|
|
*/
|
|
saveDeep() {
|
|
this.save();
|
|
}
|
|
}
|
|
exports.DbDoc = DbDoc;
|
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRkYXRhLmNsYXNzZXMuZGJkb2MuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydGRhdGEuY2xhc3Nlcy5kYmRvYy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBT0E7O0dBRUc7QUFDSCxrQkFBeUIsTUFBa0IsRUFBRSxHQUFXO0lBQ3BELE9BQU8sQ0FBQyxHQUFHLENBQUMsWUFBWSxDQUFDLENBQUE7SUFDekIsRUFBRSxDQUFDLENBQUMsQ0FBQyxNQUFNLENBQUMsa0JBQWtCLENBQUMsQ0FBQyxDQUFDO1FBQUMsTUFBTSxDQUFDLGtCQUFrQixHQUFHLEVBQUUsQ0FBQTtJQUFDLENB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