database-connector 2.4.6 → 2.4.8

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/CHANGELOG.md CHANGED
@@ -40,11 +40,12 @@
40
40
  - All history tracking done via embedded subscriptionsHistory and upcomingSubscriptions arrays
41
41
  - `planTypeId`: ObjectId reference to PlanType model
42
42
  - `numberOfStores`: Number (default: 1, minimum: 1) - tracks number of stores in subscription
43
+ - `stores`: Array of ObjectIds referencing Store - tracks which specific stores are included in this subscription
43
44
  - `billingAddress`: Mixed object for billing address (Adresse de facturation)
44
45
  - `invoiceRecipient`: Object with type (Person/Company enum) and name fields (Facture au nom de)
45
46
  - `invoiceLink`: String (nullable, default: null) - link to the invoice document
46
47
  - Updated `subscriptionsHistory` and `upcomingSubscriptions` arrays to include complete subscription snapshots
47
- - Both now include all fields: storeId, planId, planTypeId, paymentTypeId, paymentIntentId, reductionOfferId, numberOfStores, billingAddress, invoiceRecipient, invoiceLink
48
+ - Both now include all fields: storeId, planId, planTypeId, paymentTypeId, paymentIntentId, reductionOfferId, numberOfStores, stores, billingAddress, invoiceRecipient, invoiceLink
48
49
  - Makes history tracking consistent and comprehensive
49
50
  - Added `planTypeId` index for performance optimization
50
51
  - Updated history snapshot builder to include all new fields including invoiceLink
@@ -224,7 +225,8 @@ After comprehensive analysis of model usage across all microservices (AuthServic
224
225
  - `paymentManagerId`: For payment manager tracking
225
226
  - `storeId, status` (compound): For store subscription status
226
227
  - `status, endDate` (compound): For active subscription expiration monitoring
227
- - **Justification:** SubscriptionService queries subscriptions by store, status, and expiration dates. Compound indexes optimize active subscription monitoring and store subscription management.
228
+ - `stores`: For queries filtering by specific stores in the subscription
229
+ - **Justification:** SubscriptionService queries subscriptions by store, status, and expiration dates. Compound indexes optimize active subscription monitoring and store subscription management. The stores index enables efficient queries to find subscriptions containing specific stores.
228
230
 
229
231
  **13. UserAction Model** (`UserAction.js`)
230
232
  - **Indexes Added:**
@@ -11,6 +11,7 @@ const buildSubscriptionHistorySnapshot = (subscriptionDoc) => ({
11
11
  paymentIntentId: subscriptionDoc.paymentIntentId,
12
12
  reductionOfferId: subscriptionDoc.reductionOfferId,
13
13
  numberOfStores: subscriptionDoc.numberOfStores,
14
+ stores: subscriptionDoc.stores,
14
15
  billingAddress: subscriptionDoc.billingAddress,
15
16
  invoiceRecipient: subscriptionDoc.invoiceRecipient,
16
17
  invoiceLink: subscriptionDoc.invoiceLink,
@@ -18,6 +19,7 @@ const buildSubscriptionHistorySnapshot = (subscriptionDoc) => ({
18
19
  startDate: subscriptionDoc.startDate,
19
20
  endDate: subscriptionDoc.endDate,
20
21
  notes: subscriptionDoc.notes,
22
+ createdAt: new Date(),
21
23
  });
22
24
 
23
25
  const recordSubscriptionHistory = async (subscriptionDoc) => {
@@ -65,6 +67,11 @@ const recordSubscriptionHistory = async (subscriptionDoc) => {
65
67
  * type: number
66
68
  * default: 1
67
69
  * description: Number of stores in this subscription
70
+ * stores:
71
+ * type: array
72
+ * items:
73
+ * type: string
74
+ * description: Array of store IDs included in this subscription
68
75
  * billingAddress:
69
76
  * type: object
70
77
  * description: Billing address for the subscription
@@ -164,6 +171,15 @@ const subscriptionSchema = new mongoose.Schema(
164
171
  default: 1,
165
172
  min: 1,
166
173
  },
174
+ stores: {
175
+ type: [
176
+ {
177
+ type: mongoose.Schema.Types.ObjectId,
178
+ ref: 'Store',
179
+ },
180
+ ],
181
+ default: [],
182
+ },
167
183
  billingAddress: {
168
184
  type: mongoose.Schema.Types.Mixed,
169
185
  required: false,
@@ -267,6 +283,15 @@ const subscriptionSchema = new mongoose.Schema(
267
283
  type: Number,
268
284
  default: 1,
269
285
  },
286
+ stores: {
287
+ type: [
288
+ {
289
+ type: mongoose.Schema.Types.ObjectId,
290
+ ref: 'Store',
291
+ },
292
+ ],
293
+ default: [],
294
+ },
270
295
  billingAddress: {
271
296
  type: mongoose.Schema.Types.Mixed,
272
297
  required: false,
@@ -299,6 +324,10 @@ const subscriptionSchema = new mongoose.Schema(
299
324
  type: String,
300
325
  default: null,
301
326
  },
327
+ createdAt: {
328
+ type: Date,
329
+ default: Date.now,
330
+ },
302
331
  },
303
332
  ],
304
333
  upcomingSubscriptions: [
@@ -351,6 +380,15 @@ const subscriptionSchema = new mongoose.Schema(
351
380
  type: Number,
352
381
  default: 1,
353
382
  },
383
+ stores: {
384
+ type: [
385
+ {
386
+ type: mongoose.Schema.Types.ObjectId,
387
+ ref: 'Store',
388
+ },
389
+ ],
390
+ default: [],
391
+ },
354
392
  billingAddress: {
355
393
  type: mongoose.Schema.Types.Mixed,
356
394
  required: false,
@@ -416,5 +454,6 @@ subscriptionSchema.index({ planTypeId: 1 });
416
454
  subscriptionSchema.index({ paymentManagerId: 1 });
417
455
  subscriptionSchema.index({ sellerId: 1, status: 1 });
418
456
  subscriptionSchema.index({ status: 1, endDate: 1 });
457
+ subscriptionSchema.index({ stores: 1 });
419
458
 
420
459
  module.exports = mongoose.model('Subscription', subscriptionSchema);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "database-connector",
3
- "version": "2.4.6",
3
+ "version": "2.4.8",
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": {