database-connector 2.5.12 → 2.5.14
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 +13 -0
- package/models/index.js +9 -1
- package/package.json +1 -1
package/models/Subscription.js
CHANGED
|
@@ -506,6 +506,19 @@ subscriptionSchema.post('updateOne', async function () {
|
|
|
506
506
|
}
|
|
507
507
|
});
|
|
508
508
|
|
|
509
|
+
subscriptionSchema.post('findByIdAndUpdate', async function () {
|
|
510
|
+
const options = this.getOptions ? this.getOptions() : this.options;
|
|
511
|
+
if (options?.skipHistory || options?.$locals?.skipHistory || this?.$locals?.skipHistory) return;
|
|
512
|
+
|
|
513
|
+
// Record history from the OLD document (captured in pre hook)
|
|
514
|
+
if (this._oldDoc) {
|
|
515
|
+
const updatedDoc = await this.model.findOne(this.getQuery());
|
|
516
|
+
if (updatedDoc) {
|
|
517
|
+
await recordSubscriptionHistory(this._oldDoc, updatedDoc);
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
});
|
|
521
|
+
|
|
509
522
|
// Indexes for performance optimization
|
|
510
523
|
subscriptionSchema.index({ sellerId: 1 });
|
|
511
524
|
subscriptionSchema.index({ status: 1 });
|
package/models/index.js
CHANGED
|
@@ -29,7 +29,15 @@ const withTransaction = async (fn) => {
|
|
|
29
29
|
await session.commitTransaction();
|
|
30
30
|
return result;
|
|
31
31
|
} catch (err) {
|
|
32
|
-
|
|
32
|
+
if (session.inTransaction()) {
|
|
33
|
+
try {
|
|
34
|
+
await session.abortTransaction();
|
|
35
|
+
} catch (abortErr) {
|
|
36
|
+
// Preserve original error while still surfacing abort failure details
|
|
37
|
+
abortErr.originalError = err;
|
|
38
|
+
throw abortErr;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
33
41
|
throw err;
|
|
34
42
|
} finally {
|
|
35
43
|
session.endSession();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "database-connector",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.14",
|
|
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": {
|