database-connector 2.2.2 → 2.2.4
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/Store.js +6 -0
- package/models/Subscription.js +28 -0
- package/package.json +1 -1
package/models/Store.js
CHANGED
|
@@ -60,6 +60,9 @@ const { getBaseURL, getDefaultStoreImagePath } = require('../config');
|
|
|
60
60
|
* description:
|
|
61
61
|
* type: string
|
|
62
62
|
* description: Store description
|
|
63
|
+
* registrationNumber:
|
|
64
|
+
* type: string
|
|
65
|
+
* description: Store registration number
|
|
63
66
|
* isActive:
|
|
64
67
|
* type: boolean
|
|
65
68
|
* default: true
|
|
@@ -269,6 +272,9 @@ const storeSchema = new mongoose.Schema(
|
|
|
269
272
|
type: String,
|
|
270
273
|
required: true,
|
|
271
274
|
},
|
|
275
|
+
registrationNumber: {
|
|
276
|
+
type: String,
|
|
277
|
+
},
|
|
272
278
|
ratingCount: {
|
|
273
279
|
type: Number,
|
|
274
280
|
default: 0,
|
package/models/Subscription.js
CHANGED
|
@@ -33,6 +33,14 @@ const recordSubscriptionHistory = async (subscriptionDoc) => {
|
|
|
33
33
|
);
|
|
34
34
|
};
|
|
35
35
|
|
|
36
|
+
const deleteSubscriptionHistories = async (subscriptionId) => {
|
|
37
|
+
if (!subscriptionId) return;
|
|
38
|
+
// Lazy-load to avoid require ordering issues
|
|
39
|
+
// eslint-disable-next-line global-require
|
|
40
|
+
const SubscriptionHistory = require('./SubscriptionHistory');
|
|
41
|
+
await SubscriptionHistory.deleteMany({ subscriptionId });
|
|
42
|
+
};
|
|
43
|
+
|
|
36
44
|
/**
|
|
37
45
|
* @swagger
|
|
38
46
|
* components:
|
|
@@ -261,6 +269,26 @@ subscriptionSchema.post('updateOne', async function () {
|
|
|
261
269
|
await recordSubscriptionHistory(updatedDoc);
|
|
262
270
|
});
|
|
263
271
|
|
|
272
|
+
// Cascade delete: remove all histories when a subscription is deleted
|
|
273
|
+
subscriptionSchema.pre('deleteOne', { document: true, query: false }, async function () {
|
|
274
|
+
await deleteSubscriptionHistories(this._id);
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
subscriptionSchema.post('findOneAndDelete', async function (doc) {
|
|
278
|
+
if (!doc) return;
|
|
279
|
+
await deleteSubscriptionHistories(doc._id);
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
subscriptionSchema.pre('deleteOne', { document: false, query: true }, async function () {
|
|
283
|
+
const filter = this.getFilter();
|
|
284
|
+
const docs = await this.model.find(filter).select('_id');
|
|
285
|
+
if (!docs || docs.length === 0) return;
|
|
286
|
+
const ids = docs.map((d) => d._id);
|
|
287
|
+
// eslint-disable-next-line global-require
|
|
288
|
+
const SubscriptionHistory = require('./SubscriptionHistory');
|
|
289
|
+
await SubscriptionHistory.deleteMany({ subscriptionId: { $in: ids } });
|
|
290
|
+
});
|
|
291
|
+
|
|
264
292
|
// Indexes for performance optimization
|
|
265
293
|
subscriptionSchema.index({ storeId: 1 });
|
|
266
294
|
subscriptionSchema.index({ status: 1 });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "database-connector",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.4",
|
|
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": {
|