fng-audit 0.12.0-beta.221 → 0.12.0-beta.223

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.
@@ -534,74 +534,70 @@ function plugin(schema, options) {
534
534
  Document middleware. "this" is the document
535
535
  */
536
536
  schema.pre("save", function (next) {
537
- return __awaiter(this, void 0, void 0, function () {
538
- var user, auditRec, xtra, that_1;
539
- return __generator(this, function (_a) {
540
- switch (_a.label) {
541
- case 0:
542
- if (!(this._noAudit || !exports.Audit)) return [3 /*break*/, 1];
543
- next();
544
- return [3 /*break*/, 7];
545
- case 1:
546
- if (!this.isNew) return [3 /*break*/, 6];
547
- user = getPseudoField('user', this) || getPseudoField('_usr', this);
548
- if (!user) return [3 /*break*/, 4];
549
- auditRec = {
550
- c: this.constructor.modelName,
551
- cId: this._id,
552
- op: 'create',
553
- user: user
554
- };
555
- if (!(typeof auditOptions.addPropFunc === "function")) return [3 /*break*/, 3];
556
- return [4 /*yield*/, auditOptions.addPropFunc(auditRec, this, null, null, {})];
557
- case 2:
558
- xtra = _a.sent();
537
+ function doTheCreate(theAuditRec) {
538
+ exports.Audit.create(theAuditRec)
539
+ .then(function () {
540
+ // nothing to do
541
+ })
542
+ .catch(function (err) {
543
+ console.log("Error creating audit object: ".concat(err.message));
544
+ })
545
+ .finally(function () {
546
+ next();
547
+ });
548
+ }
549
+ if (this._noAudit || !exports.Audit) {
550
+ next();
551
+ }
552
+ else if (this.isNew) {
553
+ // No point in auditing if we don't have a user, as the document itself does the job
554
+ var user = getPseudoField('user', this) || getPseudoField('_usr', this);
555
+ if (user) {
556
+ var auditRec_1 = {
557
+ c: this.constructor.modelName,
558
+ cId: this._id,
559
+ op: 'create',
560
+ user: user
561
+ };
562
+ if (typeof auditOptions.addPropFunc === "function") {
563
+ auditOptions.addPropFunc(auditRec_1, this, null, null, {})
564
+ .then(function (xtra) {
559
565
  if (xtra) {
560
- auditRec.xtra = xtra;
566
+ auditRec_1.xtra = xtra;
561
567
  }
562
- _a.label = 3;
563
- case 3:
564
- exports.Audit.create(auditRec)
565
- .then(function () {
566
- // nothing to do
567
- })
568
- .catch(function (err) {
569
- console.log("Error creating audit object: ".concat(err.message));
570
- })
571
- .finally(function () {
572
- next();
573
- });
574
- return [3 /*break*/, 5];
575
- case 4:
576
- next();
577
- _a.label = 5;
578
- case 5: return [3 /*break*/, 7];
579
- case 6:
580
- that_1 = this;
581
- try {
582
- getHiddenFields(that_1.constructor.collection.collectionName, options);
583
- that_1.constructor.findOne({ _id: that_1._id })
584
- .then(function (original) {
585
- auditFromObject(that_1, original, that_1, options, next);
586
- })
587
- .catch(function (err) {
588
- if (auditOptions.errorHandler) {
589
- auditOptions.errorHandler(err.message);
590
- }
591
- next();
592
- });
593
- }
594
- catch (e) {
595
- if (auditOptions.errorHandler) {
596
- auditOptions.errorHandler(e.message);
597
- }
598
- next();
599
- }
600
- _a.label = 7;
601
- case 7: return [2 /*return*/];
568
+ doTheCreate(auditRec_1);
569
+ });
602
570
  }
603
- });
604
- });
571
+ else {
572
+ doTheCreate(auditRec_1);
573
+ }
574
+ }
575
+ else {
576
+ next();
577
+ }
578
+ }
579
+ else {
580
+ var that_1 = this;
581
+ try {
582
+ getHiddenFields(that_1.constructor.collection.collectionName, options);
583
+ that_1.constructor.findOne({ _id: that_1._id })
584
+ .then(function (original) {
585
+ auditFromObject(that_1, original, that_1, options, next);
586
+ })
587
+ .catch(function (err) {
588
+ if (auditOptions.errorHandler) {
589
+ auditOptions.errorHandler(err.message);
590
+ }
591
+ next();
592
+ });
593
+ }
594
+ catch (e) {
595
+ if (auditOptions.errorHandler) {
596
+ auditOptions.errorHandler(e.message);
597
+ }
598
+ next();
599
+ }
600
+ }
605
601
  });
606
602
  // prior to mongoose 7, pre("remove") was used to intercept deleted documents. in mongoose 7, remove() no longer
607
603
  // exists, and instead, deleteOne() is used both to delete a document that has already been retrieved from the
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fng-audit",
3
- "version": "0.12.0-beta.221",
3
+ "version": "0.12.0-beta.223",
4
4
  "description": "Client part of forms-angular audit plugin",
5
5
  "homepage": "https://www.forms-angular.org/#/plugins",
6
6
  "files": [
@@ -26,7 +26,7 @@
26
26
  "@types/mocha": "10.0.1",
27
27
  "angular": "^1.8.3",
28
28
  "chai": "4.3.7",
29
- "forms-angular": "0.12.0-beta.221",
29
+ "forms-angular": "0.12.0-beta.223",
30
30
  "grunt": "^1.5.3",
31
31
  "grunt-angular-templates": "^1.2.0",
32
32
  "grunt-contrib-concat": "2.1.0",