@likewatt/models 1.70.1 → 1.72.1

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.
@@ -16,6 +16,7 @@ const uuid_1 = require("uuid");
16
16
  const swagger_1 = require("@nestjs/swagger");
17
17
  const class_validator_1 = require("class-validator");
18
18
  const comments_1 = require("./internal/comments");
19
+ const class_transformer_1 = require("class-transformer");
19
20
  let Objective = class Objective {
20
21
  };
21
22
  exports.Objective = Objective;
@@ -437,7 +438,8 @@ __decorate([
437
438
  (0, swagger_1.ApiPropertyOptional)({ type: comments_1.Comments }),
438
439
  (0, mongoose_1.Prop)({ type: comments_1.CommentsSchema, required: false }),
439
440
  (0, class_validator_1.IsOptional)(),
440
- (0, class_validator_1.IsArray)(),
441
+ (0, class_validator_1.ValidateNested)(),
442
+ (0, class_transformer_1.Type)(() => comments_1.Comments),
441
443
  __metadata("design:type", comments_1.Comments)
442
444
  ], Scenario.prototype, "comments", void 0);
443
445
  __decorate([
@@ -514,7 +516,10 @@ __decorate([
514
516
  __metadata("design:type", String)
515
517
  ], Scenario.prototype, "message", void 0);
516
518
  __decorate([
517
- (0, swagger_1.ApiPropertyOptional)({ example: 'handled', description: 'Type d\'erreur d\'optimisation (infeasible, handled, timeout, unknown)' }),
519
+ (0, swagger_1.ApiPropertyOptional)({
520
+ example: 'handled',
521
+ description: "Type d'erreur d'optimisation (infeasible, handled, timeout, unknown)",
522
+ }),
518
523
  (0, mongoose_1.Prop)(),
519
524
  (0, class_validator_1.IsOptional)(),
520
525
  (0, class_validator_1.IsString)(),
package/dist/core/Site.js CHANGED
@@ -609,7 +609,8 @@ __decorate([
609
609
  (0, swagger_1.ApiPropertyOptional)({ type: comments_1.Comments }),
610
610
  (0, mongoose_1.Prop)({ type: comments_1.CommentsSchema, required: false }),
611
611
  (0, class_validator_1.IsOptional)(),
612
- (0, class_validator_1.IsArray)(),
612
+ (0, class_validator_1.ValidateNested)(),
613
+ (0, class_transformer_1.Type)(() => comments_1.Comments),
613
614
  __metadata("design:type", comments_1.Comments)
614
615
  ], Site.prototype, "comments", void 0);
615
616
  __decorate([
@@ -666,3 +667,63 @@ exports.SiteSchema.pre('save', function (next) {
666
667
  }
667
668
  next();
668
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
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@likewatt/models",
3
- "version": "1.70.1",
3
+ "version": "1.72.1",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "scripts": {