database-connector 2.4.11 → 2.4.13
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/models/Subscription.js +9 -6
- package/package.json +1 -1
package/models/Subscription.js
CHANGED
|
@@ -29,7 +29,7 @@ const recordSubscriptionHistory = async (subscriptionDoc) => {
|
|
|
29
29
|
|
|
30
30
|
await subscriptionDoc.updateOne(
|
|
31
31
|
{ $push: { subscriptionsHistory: historySnapshot } },
|
|
32
|
-
{ skipHistory: true }
|
|
32
|
+
{ $locals: { skipHistory: true } }
|
|
33
33
|
);
|
|
34
34
|
};
|
|
35
35
|
|
|
@@ -429,21 +429,24 @@ const subscriptionSchema = new mongoose.Schema(
|
|
|
429
429
|
|
|
430
430
|
// Auto-record history snapshots to embedded subscriptionsHistory array
|
|
431
431
|
subscriptionSchema.post('save', async function (doc, next) {
|
|
432
|
-
// For save operations, check the $locals
|
|
433
|
-
if (doc
|
|
434
|
-
if (this
|
|
432
|
+
// For save operations, check the $locals and save options where custom options are stored
|
|
433
|
+
if (doc?.$locals?.skipHistory) return next();
|
|
434
|
+
if (this?.$locals?.skipHistory) return next();
|
|
435
|
+
if (this?.$__?.saveOptions?.skipHistory) return next();
|
|
435
436
|
await recordSubscriptionHistory(doc);
|
|
436
437
|
next();
|
|
437
438
|
});
|
|
438
439
|
|
|
439
440
|
subscriptionSchema.post('findOneAndUpdate', async function () {
|
|
440
|
-
|
|
441
|
+
const options = this.getOptions ? this.getOptions() : this.options;
|
|
442
|
+
if (options?.skipHistory || options?.$locals?.skipHistory || this?.$locals?.skipHistory) return;
|
|
441
443
|
const updatedDoc = await this.model.findOne(this.getQuery());
|
|
442
444
|
await recordSubscriptionHistory(updatedDoc);
|
|
443
445
|
});
|
|
444
446
|
|
|
445
447
|
subscriptionSchema.post('updateOne', async function () {
|
|
446
|
-
|
|
448
|
+
const options = this.getOptions ? this.getOptions() : this.options;
|
|
449
|
+
if (options?.skipHistory || options?.$locals?.skipHistory || this?.$locals?.skipHistory) return;
|
|
447
450
|
const updatedDoc = await this.model.findOne(this.getQuery());
|
|
448
451
|
await recordSubscriptionHistory(updatedDoc);
|
|
449
452
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "database-connector",
|
|
3
|
-
"version": "2.4.
|
|
3
|
+
"version": "2.4.13",
|
|
4
4
|
"description": "MongoDB models package with Mongoose schemas for e-commerce applications. Includes User, Product, Store, Order and more with built-in validation and virtual properties.",
|
|
5
5
|
"main": "models/index.js",
|
|
6
6
|
"scripts": {
|