database-connector 2.3.2 → 2.3.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.
@@ -56,7 +56,37 @@ const mongoose = require('mongoose');
56
56
  * description: Products in this flash deal
57
57
  * discountCode:
58
58
  * type: string
59
- * description: Discount code
59
+ * description: Discount code (main code or template)
60
+ * codeType:
61
+ * type: string
62
+ * enum: [unique, specific]
63
+ * default: unique
64
+ * description: Code type - unique (single code for all) or specific (individual codes per user)
65
+ * campaignObjective:
66
+ * type: string
67
+ * enum: [followers, specific, all]
68
+ * default: followers
69
+ * description: Campaign objective - target followers, specific users, or all users
70
+ * campaignPurpose:
71
+ * type: string
72
+ * enum: [increase_revenue, attract_new_clients]
73
+ * description: Campaign purpose (only when campaignObjective is 'all')
74
+ * targetUserIds:
75
+ * type: array
76
+ * items:
77
+ * type: object
78
+ * properties:
79
+ * userId:
80
+ * type: string
81
+ * description: Reference to target user
82
+ * used:
83
+ * type: boolean
84
+ * default: false
85
+ * description: Whether the user has used the code
86
+ * code:
87
+ * type: string
88
+ * description: Individual promo code (null for unique code type)
89
+ * description: Array of targeted users with their specific codes and usage status
60
90
  * qauntiyFlashDeal:
61
91
  * type: number
62
92
  * default: 0
@@ -65,6 +95,11 @@ const mongoose = require('mongoose');
65
95
  * type: boolean
66
96
  * default: true
67
97
  * description: Whether the flash deal is active
98
+ * history:
99
+ * type: array
100
+ * items:
101
+ * type: object
102
+ * description: History of flash deal updates
68
103
  * createdAt:
69
104
  * type: string
70
105
  * format: date-time
@@ -139,8 +174,42 @@ const FlashDealSchema = new mongoose.Schema(
139
174
  ],
140
175
  discountCode: {
141
176
  type: String,
177
+ required: false,
178
+ },
179
+ codeType: {
180
+ type: String,
181
+ enum: ['unique', 'specific'],
182
+ default: 'unique',
183
+ required: true,
184
+ },
185
+ campaignObjective: {
186
+ type: String,
187
+ enum: ['followers', 'specific', 'all'],
188
+ default: 'followers',
142
189
  required: true,
143
190
  },
191
+ campaignPurpose: {
192
+ type: String,
193
+ enum: ['increase_revenue', 'attract_new_clients'],
194
+ default: null,
195
+ },
196
+ targetUserIds: [
197
+ {
198
+ userId: {
199
+ type: mongoose.Schema.Types.ObjectId,
200
+ ref: 'User',
201
+ required: true,
202
+ },
203
+ used: {
204
+ type: Boolean,
205
+ default: false,
206
+ },
207
+ code: {
208
+ type: String,
209
+ default: null,
210
+ },
211
+ },
212
+ ],
144
213
  qauntiyFlashDeal: {
145
214
  type: Number,
146
215
  required: true,
@@ -150,7 +219,16 @@ const FlashDealSchema = new mongoose.Schema(
150
219
  type: Boolean,
151
220
  required: true,
152
221
  default: true
153
- }
222
+ },
223
+ history: [
224
+ {
225
+ type: mongoose.Schema.Types.Mixed,
226
+ timestamp: {
227
+ type: Date,
228
+ default: Date.now,
229
+ },
230
+ },
231
+ ]
154
232
  },
155
233
  {
156
234
  timestamps: true
package/models/Offer.js CHANGED
@@ -63,6 +63,10 @@ const mongoose = require('mongoose');
63
63
  * enum: [followers, all, specific]
64
64
  * default: all
65
65
  * description: Who can see this offer
66
+ * campaignPurpose:
67
+ * type: string
68
+ * enum: [increase_revenue, attract_new_clients]
69
+ * description: Campaign purpose (only when type is 'all')
66
70
  * userIds:
67
71
  * type: array
68
72
  * items:
@@ -72,6 +76,11 @@ const mongoose = require('mongoose');
72
76
  * type: boolean
73
77
  * default: false
74
78
  * description: Whether to add this offer to the slider
79
+ * history:
80
+ * type: array
81
+ * items:
82
+ * type: object
83
+ * description: History of offer updates
75
84
  * createdAt:
76
85
  * type: string
77
86
  * format: date-time
@@ -151,9 +160,14 @@ const OfferSchema = new mongoose.Schema(
151
160
  },
152
161
  type: {
153
162
  type: String,
154
- default: 'all',
163
+ default: 'followers',
155
164
  enum: ['followers', 'all', 'specific'],
156
165
  },
166
+ campaignPurpose: {
167
+ type: String,
168
+ enum: ['increase_revenue', 'attract_new_clients'],
169
+ default: null,
170
+ },
157
171
  userIds: {
158
172
  type: [mongoose.Schema.Types.ObjectId],
159
173
  ref: 'User',
@@ -163,6 +177,15 @@ const OfferSchema = new mongoose.Schema(
163
177
  type: Boolean,
164
178
  default: false,
165
179
  },
180
+ history: [
181
+ {
182
+ type: mongoose.Schema.Types.Mixed,
183
+ timestamp: {
184
+ type: Date,
185
+ default: Date.now,
186
+ },
187
+ },
188
+ ],
166
189
  },
167
190
  {
168
191
  timestamps: true,
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.2",
3
+ "version": "2.3.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": {