database-connector 2.3.0 → 2.3.2

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
@@ -4,6 +4,9 @@
4
4
 
5
5
  ### Added
6
6
 
7
+ #### Added Transaction method to all models
8
+ - Added a static `withTransaction(fn)` method to all models to facilitate running operations within MongoDB transactions. This method accepts a function `fn` that contains the operations to be executed in a transaction.
9
+
7
10
  #### Database Indexes for Performance Optimization
8
11
 
9
12
  After comprehensive analysis of model usage across all microservices (AuthService, CartService, CategoryService, NotificationService, OfferService, OrderService, ProductService, SalesAnalyticsService, SearchExplorationService, StoreService, SubscriptionService, and UserService), the following database indexes have been added to optimize query performance:
package/models/Cart.js CHANGED
@@ -22,6 +22,10 @@ const { Schema, model } = require('mongoose');
22
22
  * type: string
23
23
  * variantId:
24
24
  * type: string
25
+ * offerId:
26
+ * type: string
27
+ * nullable: true
28
+ * description: Reference to an offer (optional)
25
29
  * discount:
26
30
  * type: number
27
31
  * default: 0
@@ -57,9 +61,16 @@ const itemSchema = new Schema(
57
61
  {
58
62
  productId: { type: Schema.Types.ObjectId, ref: 'Product', required: true },
59
63
  variantId: { type: String, required: true },
64
+ offer: { type: Schema.Types.ObjectId, ref: 'Offer', default: null },
60
65
  discount: { type: Number, default: 0 },
61
66
  quantity: { type: Number, required: true, default: 1 },
62
67
  discountQuantity: { type: Number, default: 0 },
68
+ discountType: {
69
+ type: String,
70
+ required: true,
71
+ enum: ['percentage', 'amount'],
72
+ default: 'percentage',
73
+ },
63
74
  //price: { type: Number, required: true },
64
75
  //name: { type: String, required: true },
65
76
  //image: { type: String, required: true, default: 'https://via.placeholder.com/150' },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "database-connector",
3
- "version": "2.3.0",
3
+ "version": "2.3.2",
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": {