database-connector 2.3.1 → 2.3.3

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/Cart.js CHANGED
@@ -65,6 +65,12 @@ const itemSchema = new Schema(
65
65
  discount: { type: Number, default: 0 },
66
66
  quantity: { type: Number, required: true, default: 1 },
67
67
  discountQuantity: { type: Number, default: 0 },
68
+ discountType: {
69
+ type: String,
70
+ required: true,
71
+ enum: ['percentage', 'amount'],
72
+ default: 'percentage',
73
+ },
68
74
  //price: { type: Number, required: true },
69
75
  //name: { type: String, required: true },
70
76
  //image: { type: String, required: true, default: 'https://via.placeholder.com/150' },
package/models/Order.js CHANGED
@@ -483,16 +483,24 @@ const orderSchema = new mongoose.Schema(
483
483
  );
484
484
  orderSchema.post('save', async function (doc) {
485
485
  try {
486
+ // Fetch the store to get the sellerId
487
+ const Store = mongoose.model('Store');
488
+ const store = await Store.findById(doc.storeId).select('sellerId address');
489
+
490
+ if (!store) {
491
+ console.error('Store not found for order:', doc._id);
492
+ return;
493
+ }
494
+
486
495
  // Create a new Sale document for each item in the order
487
496
  for (const item of doc.items) {
488
497
  const newSale = new Sale({
489
- sellerId: doc.sellerId, // Replace with the actual sellerId
490
- storeId: doc.storeId, // Replace with the actual storeId
498
+ sellerId: store.sellerId,
499
+ storeId: doc.storeId,
491
500
  productId: item.productId,
492
501
  date: doc.createdAt,
493
- region: doc.deliveryAddresse.city
494
- } // Replace with the actual region field from the order
495
- );
502
+ region: doc.deliveryAddresse?.city || doc.deliveryAddresse?.region || store.address?.city || store.address?.region || 'Unknown'
503
+ });
496
504
 
497
505
  await newSale.save();
498
506
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "database-connector",
3
- "version": "2.3.1",
3
+ "version": "2.3.3",
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": {