@sumaris-net/ngx-components 1.21.0-beta27 → 1.21.0-beta28

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.
@@ -30452,19 +30452,11 @@
30452
30452
  };
30453
30453
  AbstractUserEventService.prototype.save = function (entity, options) {
30454
30454
  return __awaiter(this, void 0, void 0, function () {
30455
- var allData, withContent, json, now;
30455
+ var withContent, json, now;
30456
30456
  var _this = this;
30457
30457
  return __generator(this, function (_b) {
30458
30458
  switch (_b.label) {
30459
30459
  case 0:
30460
- if (!!this.mutations.save) return [3 /*break*/, 2];
30461
- if (!this.mutations.saveAll)
30462
- throw new Error('Not implemented');
30463
- return [4 /*yield*/, this.saveAll([entity], options)];
30464
- case 1:
30465
- allData = _b.sent();
30466
- return [2 /*return*/, allData === null || allData === void 0 ? void 0 : allData[0]];
30467
- case 2:
30468
30460
  this.fillDefaultProperties(entity);
30469
30461
  withContent = !!entity.content;
30470
30462
  json = entity.asObject();
@@ -30501,7 +30493,7 @@
30501
30493
  }
30502
30494
  }
30503
30495
  })];
30504
- case 3:
30496
+ case 1:
30505
30497
  _b.sent();
30506
30498
  return [2 /*return*/, entity];
30507
30499
  }
@@ -30510,55 +30502,10 @@
30510
30502
  };
30511
30503
  AbstractUserEventService.prototype.saveAll = function (entities, opts) {
30512
30504
  return __awaiter(this, void 0, void 0, function () {
30513
- var json, now;
30514
30505
  var _this = this;
30515
30506
  return __generator(this, function (_b) {
30516
- switch (_b.label) {
30517
- case 0:
30518
- if (isEmptyArray(entities))
30519
- return [2 /*return*/, entities];
30520
- if (!this.mutations.saveAll) {
30521
- if (!this.mutations.save)
30522
- throw new Error('Not implemented');
30523
- // Save one by one
30524
- return [2 /*return*/, chainPromises(entities.map(function (entity) { return function () { return _this.save(entity, opts); }; }))];
30525
- }
30526
- json = entities.map(function (entity) {
30527
- _this.fillDefaultProperties(entity);
30528
- return entity.asObject();
30529
- });
30530
- now = Date.now();
30531
- if (this._debug)
30532
- console.debug(this._logPrefix + "Saving user events...", json);
30533
- return [4 /*yield*/, this.graphql.mutate({
30534
- mutation: this.mutations.saveAll,
30535
- variables: {
30536
- data: json
30537
- },
30538
- error: { code: SocialErrorCodes.SAVE_USER_EVENT_ERROR, message: 'SOCIAL.ERROR.SAVE_USER_EVENT_ERROR' },
30539
- update: function (proxy, _b) {
30540
- var data = _b.data;
30541
- // Update entity
30542
- var savedEntities = (data === null || data === void 0 ? void 0 : data.data) || [];
30543
- if (savedEntities.length) {
30544
- if (_this._debug)
30545
- console.debug(_this._logPrefix + "User events saved in " + (Date.now() - now) + "ms", savedEntities);
30546
- entities.forEach(function (entity) {
30547
- var savedEntity = savedEntities.find(function (e) { return EntityUtils.equals(e, entity, 'id'); });
30548
- _this.copyIdAndUpdateDate(savedEntity, entity);
30549
- });
30550
- // Add to cache (assuming all with content)
30551
- _this.insertIntoMutableCachedQueries(proxy, {
30552
- query: _this.queries.loadAllWithContent,
30553
- data: savedEntities
30554
- });
30555
- }
30556
- }
30557
- })];
30558
- case 1:
30559
- _b.sent();
30560
- return [2 /*return*/, entities];
30561
- }
30507
+ return [2 /*return*/, Promise.all(entities
30508
+ .map(function (entity) { return _this.save(entity, opts); }))];
30562
30509
  });
30563
30510
  });
30564
30511
  };
@@ -30724,8 +30671,9 @@
30724
30671
  return target;
30725
30672
  };
30726
30673
  AbstractUserEventService.prototype.defaultMarkAsRead = function (userEvents) {
30674
+ var _a;
30727
30675
  return __awaiter(this, void 0, void 0, function () {
30728
- var localEntities, remoteEntities;
30676
+ var localEntities, remoteEntities, ids, now;
30729
30677
  return __generator(this, function (_b) {
30730
30678
  switch (_b.label) {
30731
30679
  case 0:
@@ -30744,9 +30692,25 @@
30744
30692
  // TODO !!!!!!!!!!!!!
30745
30693
  }
30746
30694
  if (!remoteEntities.length) return [3 /*break*/, 2];
30747
- return [4 /*yield*/, this.saveAll(remoteEntities)];
30695
+ if (!((_a = this.mutations) === null || _a === void 0 ? void 0 : _a.markAsRead)) {
30696
+ console.warn(this._logPrefix + "Mutation query 'markAsRead' not provided, skip.");
30697
+ return [2 /*return*/];
30698
+ }
30699
+ ids = remoteEntities.map(function (value) { return value.id; });
30700
+ now = Date.now();
30701
+ if (this._debug)
30702
+ console.debug(this._logPrefix + "Mark user events as read...", ids);
30703
+ return [4 /*yield*/, this.graphql.mutate({
30704
+ mutation: this.mutations.markAsRead,
30705
+ variables: {
30706
+ ids: ids
30707
+ },
30708
+ error: { code: SocialErrorCodes.SAVE_USER_EVENT_ERROR, message: 'SOCIAL.ERROR.SAVE_USER_EVENT_ERROR' },
30709
+ })];
30748
30710
  case 1:
30749
30711
  _b.sent();
30712
+ if (this._debug)
30713
+ console.debug(this._logPrefix + "User events marked as read in " + (Date.now() - now) + "ms", ids);
30750
30714
  _b.label = 2;
30751
30715
  case 2: return [2 /*return*/];
30752
30716
  }