@likewatt/models 1.71.0 → 1.72.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core/Site.js +60 -0
- package/dist/core/internal/comments.js +16 -0
- package/package.json +1 -1
package/dist/core/Site.js
CHANGED
|
@@ -667,3 +667,63 @@ exports.SiteSchema.pre('save', function (next) {
|
|
|
667
667
|
}
|
|
668
668
|
next();
|
|
669
669
|
});
|
|
670
|
+
const getCollectiveSiteModel = (conn) => {
|
|
671
|
+
if (!conn || !conn.modelNames().includes('CollectiveSite'))
|
|
672
|
+
return null;
|
|
673
|
+
return conn.model('CollectiveSite');
|
|
674
|
+
};
|
|
675
|
+
exports.SiteSchema.post('save', async function (doc) {
|
|
676
|
+
if (!doc.collectiveSiteId || !doc._id)
|
|
677
|
+
return;
|
|
678
|
+
const CollectiveSiteModel = getCollectiveSiteModel(doc.db);
|
|
679
|
+
if (!CollectiveSiteModel)
|
|
680
|
+
return;
|
|
681
|
+
await CollectiveSiteModel.updateOne({ _id: doc.collectiveSiteId }, { $addToSet: { sites: doc._id } }).exec();
|
|
682
|
+
});
|
|
683
|
+
exports.SiteSchema.pre('findOneAndUpdate', async function () {
|
|
684
|
+
var _a, _b;
|
|
685
|
+
const self = this;
|
|
686
|
+
const update = self.getUpdate();
|
|
687
|
+
if (!update)
|
|
688
|
+
return;
|
|
689
|
+
const set = (_a = update.$set) !== null && _a !== void 0 ? _a : update;
|
|
690
|
+
const touchesCollective = 'collectiveSiteId' in set;
|
|
691
|
+
if (!touchesCollective)
|
|
692
|
+
return;
|
|
693
|
+
const newRaw = set.collectiveSiteId;
|
|
694
|
+
const newId = typeof newRaw === 'string' && newRaw.length > 0 ? newRaw : null;
|
|
695
|
+
const oldDoc = await self.model
|
|
696
|
+
.findOne(self.getQuery())
|
|
697
|
+
.select('_id collectiveSiteId')
|
|
698
|
+
.lean()
|
|
699
|
+
.exec();
|
|
700
|
+
if (!oldDoc)
|
|
701
|
+
return;
|
|
702
|
+
const oldId = (_b = oldDoc.collectiveSiteId) !== null && _b !== void 0 ? _b : null;
|
|
703
|
+
if (oldId === newId)
|
|
704
|
+
return;
|
|
705
|
+
self._collectiveSiteSync = {
|
|
706
|
+
siteId: oldDoc._id,
|
|
707
|
+
oldId: oldId !== null && oldId !== void 0 ? oldId : undefined,
|
|
708
|
+
newId,
|
|
709
|
+
};
|
|
710
|
+
});
|
|
711
|
+
exports.SiteSchema.post('findOneAndUpdate', async function (doc) {
|
|
712
|
+
var _a;
|
|
713
|
+
const self = this;
|
|
714
|
+
const sync = self._collectiveSiteSync;
|
|
715
|
+
if (!sync)
|
|
716
|
+
return;
|
|
717
|
+
const siteId = (_a = sync.siteId) !== null && _a !== void 0 ? _a : doc === null || doc === void 0 ? void 0 : doc._id;
|
|
718
|
+
if (!siteId)
|
|
719
|
+
return;
|
|
720
|
+
const CollectiveSiteModel = getCollectiveSiteModel(self.model.db);
|
|
721
|
+
if (!CollectiveSiteModel)
|
|
722
|
+
return;
|
|
723
|
+
if (sync.oldId) {
|
|
724
|
+
await CollectiveSiteModel.updateOne({ _id: sync.oldId }, { $pull: { sites: siteId } }).exec();
|
|
725
|
+
}
|
|
726
|
+
if (sync.newId) {
|
|
727
|
+
await CollectiveSiteModel.updateOne({ _id: sync.newId }, { $addToSet: { sites: siteId } }).exec();
|
|
728
|
+
}
|
|
729
|
+
});
|
|
@@ -18,81 +18,97 @@ exports.Comments = Comments;
|
|
|
18
18
|
__decorate([
|
|
19
19
|
(0, mongoose_1.Prop)({ required: false }),
|
|
20
20
|
(0, class_validator_1.IsString)(),
|
|
21
|
+
(0, class_validator_1.IsOptional)(),
|
|
21
22
|
__metadata("design:type", String)
|
|
22
23
|
], Comments.prototype, "CostPerMonth", void 0);
|
|
23
24
|
__decorate([
|
|
24
25
|
(0, mongoose_1.Prop)({ required: false }),
|
|
25
26
|
(0, class_validator_1.IsString)(),
|
|
27
|
+
(0, class_validator_1.IsOptional)(),
|
|
26
28
|
__metadata("design:type", String)
|
|
27
29
|
], Comments.prototype, "DailyProfile", void 0);
|
|
28
30
|
__decorate([
|
|
29
31
|
(0, mongoose_1.Prop)({ required: false }),
|
|
30
32
|
(0, class_validator_1.IsString)(),
|
|
33
|
+
(0, class_validator_1.IsOptional)(),
|
|
31
34
|
__metadata("design:type", String)
|
|
32
35
|
], Comments.prototype, "EnergyBalance", void 0);
|
|
33
36
|
__decorate([
|
|
34
37
|
(0, mongoose_1.Prop)({ required: false }),
|
|
35
38
|
(0, class_validator_1.IsString)(),
|
|
39
|
+
(0, class_validator_1.IsOptional)(),
|
|
36
40
|
__metadata("design:type", String)
|
|
37
41
|
], Comments.prototype, "LineBalanceSheet", void 0);
|
|
38
42
|
__decorate([
|
|
39
43
|
(0, mongoose_1.Prop)({ required: false }),
|
|
40
44
|
(0, class_validator_1.IsString)(),
|
|
45
|
+
(0, class_validator_1.IsOptional)(),
|
|
41
46
|
__metadata("design:type", String)
|
|
42
47
|
], Comments.prototype, "LoadCurve", void 0);
|
|
43
48
|
__decorate([
|
|
44
49
|
(0, mongoose_1.Prop)({ required: false }),
|
|
45
50
|
(0, class_validator_1.IsString)(),
|
|
51
|
+
(0, class_validator_1.IsOptional)(),
|
|
46
52
|
__metadata("design:type", String)
|
|
47
53
|
], Comments.prototype, "ScenarioTable", void 0);
|
|
48
54
|
__decorate([
|
|
49
55
|
(0, mongoose_1.Prop)({ required: false }),
|
|
50
56
|
(0, class_validator_1.IsString)(),
|
|
57
|
+
(0, class_validator_1.IsOptional)(),
|
|
51
58
|
__metadata("design:type", String)
|
|
52
59
|
], Comments.prototype, "TotalCost", void 0);
|
|
53
60
|
__decorate([
|
|
54
61
|
(0, mongoose_1.Prop)({ required: false }),
|
|
55
62
|
(0, class_validator_1.IsString)(),
|
|
63
|
+
(0, class_validator_1.IsOptional)(),
|
|
56
64
|
__metadata("design:type", String)
|
|
57
65
|
], Comments.prototype, "TotalEnergy", void 0);
|
|
58
66
|
__decorate([
|
|
59
67
|
(0, mongoose_1.Prop)({ required: false }),
|
|
60
68
|
(0, class_validator_1.IsString)(),
|
|
69
|
+
(0, class_validator_1.IsOptional)(),
|
|
61
70
|
__metadata("design:type", String)
|
|
62
71
|
], Comments.prototype, "Grid_EnergeticMix", void 0);
|
|
63
72
|
__decorate([
|
|
64
73
|
(0, mongoose_1.Prop)({ required: false }),
|
|
65
74
|
(0, class_validator_1.IsString)(),
|
|
75
|
+
(0, class_validator_1.IsOptional)(),
|
|
66
76
|
__metadata("design:type", String)
|
|
67
77
|
], Comments.prototype, "LineBalanceSheetFromPopUp", void 0);
|
|
68
78
|
__decorate([
|
|
69
79
|
(0, mongoose_1.Prop)({ required: false }),
|
|
70
80
|
(0, class_validator_1.IsString)(),
|
|
81
|
+
(0, class_validator_1.IsOptional)(),
|
|
71
82
|
__metadata("design:type", String)
|
|
72
83
|
], Comments.prototype, "Opex", void 0);
|
|
73
84
|
__decorate([
|
|
74
85
|
(0, mongoose_1.Prop)({ required: false }),
|
|
75
86
|
(0, class_validator_1.IsString)(),
|
|
87
|
+
(0, class_validator_1.IsOptional)(),
|
|
76
88
|
__metadata("design:type", String)
|
|
77
89
|
], Comments.prototype, "PV_EnergeticMix", void 0);
|
|
78
90
|
__decorate([
|
|
79
91
|
(0, mongoose_1.Prop)({ required: false }),
|
|
80
92
|
(0, class_validator_1.IsString)(),
|
|
93
|
+
(0, class_validator_1.IsOptional)(),
|
|
81
94
|
__metadata("design:type", String)
|
|
82
95
|
], Comments.prototype, "TechSummary", void 0);
|
|
83
96
|
__decorate([
|
|
84
97
|
(0, mongoose_1.Prop)({ required: false }),
|
|
85
98
|
(0, class_validator_1.IsString)(),
|
|
99
|
+
(0, class_validator_1.IsOptional)(),
|
|
86
100
|
__metadata("design:type", String)
|
|
87
101
|
], Comments.prototype, "VanFromPopUp", void 0);
|
|
88
102
|
__decorate([
|
|
89
103
|
(0, mongoose_1.Prop)({ required: false }),
|
|
90
104
|
(0, class_validator_1.IsString)(),
|
|
105
|
+
(0, class_validator_1.IsOptional)(),
|
|
91
106
|
__metadata("design:type", String)
|
|
92
107
|
], Comments.prototype, "Van", void 0);
|
|
93
108
|
__decorate([
|
|
94
109
|
(0, mongoose_1.Prop)({ required: false }),
|
|
95
110
|
(0, class_validator_1.IsString)(),
|
|
111
|
+
(0, class_validator_1.IsOptional)(),
|
|
96
112
|
__metadata("design:type", String)
|
|
97
113
|
], Comments.prototype, "ConsumerEnergyBalance", void 0);
|
|
98
114
|
exports.Comments = Comments = __decorate([
|