flykup_model_development 3.1.53 → 3.1.55

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.
@@ -1,26 +1,21 @@
1
-
2
-
3
-
4
-
5
- // backend/models/ProductListing.js (or similar path)
6
1
  import mongoose from "mongoose";
7
2
  const { Schema } = mongoose;
8
3
 
9
4
  const ProductListingSchema = new Schema(
10
5
  {
11
6
  sellerId: { type: Schema.Types.ObjectId, ref: "sellers" },
12
- stockId: { type: Schema.Types.ObjectId, ref: "stocks" },
7
+ stockId: { type: Schema.Types.ObjectId, ref: "stocks" }, // ✅ KEEP THIS - for main inventory management
13
8
  title: String,
14
9
  description: String,
15
- flashSale: {
16
- isActive: { type: Boolean, default: false },
17
- flashSaleId: { type: mongoose.Schema.Types.ObjectId, ref: 'FlashSale' },
18
- flashPrice: { type: Number, default: 0 },
19
- flashStock: { type: Number, default: 0 },
20
- originalPrice: { type: Number, default: 0 },
21
- endsAt: { type: Date, default: null },
22
- startsAt: { type: Date, default: null }
23
- },
10
+ flashSale: {
11
+ isActive: { type: Boolean, default: false },
12
+ flashSaleId: { type: mongoose.Schema.Types.ObjectId, ref: 'FlashSale' },
13
+ flashPrice: { type: Number, default: 0 },
14
+ // REMOVED: flashStock field - now using main quantity
15
+ originalPrice: { type: Number, default: 0 },
16
+ endsAt: { type: Date, default: null },
17
+ startsAt: { type: Date, default: null }
18
+ },
24
19
  sku: {
25
20
  type: String,
26
21
  required: true,
@@ -54,7 +49,7 @@ const ProductListingSchema = new Schema(
54
49
  min: 0,
55
50
  default: null,
56
51
  },
57
- logisticsType: {
52
+ logisticsType: {
58
53
  type: String,
59
54
  enum: ["flykupLogistics", "selfShipment"],
60
55
  default: null,
@@ -65,47 +60,45 @@ const ProductListingSchema = new Schema(
65
60
  default: null,
66
61
  },
67
62
  estimatedDeliveryDate: {
68
- type: Number, // Change from Date to Number
63
+ type: Number,
69
64
  min: 0,
70
65
  default: null,
71
66
  },
72
-
73
- // --- ADDED/UPDATED FIELDS FROM FRONTEND ---
74
- brand: { type: String, default: null }, // ADDED
67
+ brand: { type: String, default: null },
75
68
  manufacturer: String,
76
- manufacturerAddress: String, // ADDED in frontend, already exists here
69
+ manufacturerAddress: String,
77
70
  countryOfOrigin: String,
78
- netQuantity: { type: String, default: null }, // ADDED (String to accommodate units like '500g')
79
- packagingType: { type: String, default: null }, // ADDED
80
- weight: { // For shipping calculations
71
+ netQuantity: { type: String, default: null },
72
+ packagingType: { type: String, default: null },
73
+ weight: {
81
74
  value: { type: Number, default: null },
82
75
  unit: { type: String, default: null },
83
76
  },
84
- dimensions: { // For shipping calculations
77
+ dimensions: {
85
78
  length: { type: Number, default: null },
86
79
  width: { type: Number, default: null },
87
80
  height: { type: Number, default: null },
88
81
  },
89
- expiryDate: { type: Date, default: null }, // ADDED in frontend, already exists here (changed to allow null)
90
- shelfLife: { type: String, default: null }, // ADDED in frontend, already exists here (changed to allow null)
91
- batchNumber: { type: String, default: null }, // ADDED in frontend, already exists here (changed to allow null)
92
- gstRate: { type: Number, default: null }, // Changed to allow null if needed
82
+ expiryDate: { type: Date, default: null },
83
+ shelfLife: { type: String, default: null },
84
+ batchNumber: { type: String, default: null },
85
+ gstRate: { type: Number, default: null },
93
86
  sellerName: String,
94
- sellerContact: { type: String, default: null }, // ADDED
95
- sellerGSTIN: { type: String, default: null }, // ADDED
87
+ sellerContact: { type: String, default: null },
88
+ sellerGSTIN: { type: String, default: null },
96
89
  returnPolicy: [String],
97
90
  warranty: {
98
- hasWarranty: { type: Boolean, default: false }, // Default added
99
- duration: { type: String, default: null }, // Default added
91
+ hasWarranty: { type: Boolean, default: false },
92
+ duration: { type: String, default: null },
100
93
  },
101
- fssaiLicenseNo: { type: String, default: null }, // ADDED in frontend, already exists here (changed to allow null)
102
- bisCertification: { type: String, default: null }, // ADDED in frontend, already exists here (changed to allow null)
103
- importerName: { type: String, default: null }, // Default added
104
- importerAddress: { type: String, default: null }, // Default added
105
- importerGSTIN: { type: String, default: null }, // Default added
106
- eWasteCompliance: { type: Boolean, default: false }, // Default added
107
- recyclablePackaging: { type: Boolean, default: false }, // Default added
108
- hazardousMaterials: { type: String, default: null }, // Default added
94
+ fssaiLicenseNo: { type: String, default: null },
95
+ bisCertification: { type: String, default: null },
96
+ importerName: { type: String, default: null },
97
+ importerAddress: { type: String, default: null },
98
+ importerGSTIN: { type: String, default: null },
99
+ eWasteCompliance: { type: Boolean, default: false },
100
+ recyclablePackaging: { type: Boolean, default: false },
101
+ hazardousMaterials: { type: String, default: null },
109
102
  allowDropshipping: {
110
103
  type: Boolean,
111
104
  default: false,
@@ -114,65 +107,47 @@ const ProductListingSchema = new Schema(
114
107
  commissionRate: {
115
108
  type: Number,
116
109
  min: [0, 'Commission rate cannot be negative.'],
117
- // max: [100, 'Commission rate cannot exceed 100%.'], // Max was 25, changed to 100 based on frontend
118
110
  max: [100, 'Commission rate cannot exceed 100%.'],
119
111
  default: null,
120
- // Removed Mongoose-level required validation dependent on allowDropshipping
121
- // Let application logic handle this if needed, or adjust validator
122
- // required: [
123
- // function () { return this.allowDropshipping === true; },
124
- // 'Commission rate is required when allowing dropshipping.'
125
- // ],
126
- // validate: { ... } // Keep or remove validation as needed
127
112
  },
128
113
  hasReturn: {
129
- type: Boolean,
130
- default: false
131
- },
132
- returnDays: {
133
- type: Number,
134
- min: 0,
135
- default: null
136
- },
137
- size: {
138
- type: String,
139
- default: null
140
- },
114
+ type: Boolean,
115
+ default: false
116
+ },
117
+ returnDays: {
118
+ type: Number,
119
+ min: 0,
120
+ default: null
121
+ },
122
+ size: {
123
+ type: String,
124
+ default: null
125
+ },
141
126
  isActive: {
142
127
  type: Boolean,
143
128
  default: true,
144
- },ratingSummary: {
145
- averageRating: { type: Number, default: 0 },
146
- totalRatings: { type: Number, default: 0 },
147
- ratingDistribution: {
148
- 1: { type: Number, default: 0 },
149
- 2: { type: Number, default: 0 },
150
- 3: { type: Number, default: 0 },
151
- 4: { type: Number, default: 0 },
152
- 5: { type: Number, default: 0 }
153
- }
154
- },
155
- totalReviews: { type: Number, default: 0 }
129
+ },
130
+ ratingSummary: {
131
+ averageRating: { type: Number, default: 0 },
132
+ totalRatings: { type: Number, default: 0 },
133
+ ratingDistribution: {
134
+ 1: { type: Number, default: 0 },
135
+ 2: { type: Number, default: 0 },
136
+ 3: { type: Number, default: 0 },
137
+ 4: { type: Number, default: 0 },
138
+ 5: { type: Number, default: 0 }
139
+ }
140
+ },
141
+ totalReviews: { type: Number, default: 0 }
156
142
  },
157
143
  { timestamps: true }
158
144
  );
159
- ProductListingSchema.index({ title: 'text', description: 'text', category: 'text' });
160
145
 
146
+ ProductListingSchema.index({ title: 'text', description: 'text', category: 'text' });
161
147
 
162
- // Safe export to prevent OverwriteModelError
163
148
  const ProductListing = mongoose.models.productlistings || mongoose.model("productlistings", ProductListingSchema);
164
149
  export default ProductListing;
165
150
 
166
-
167
-
168
-
169
-
170
-
171
-
172
-
173
-
174
-
175
-
176
151
  // // backend/models/ProductListing.js (or similar path)
177
152
  // import mongoose from "mongoose";
178
153
  // const { Schema } = mongoose;
@@ -192,25 +167,11 @@ export default ProductListing;
192
167
  // endsAt: { type: Date, default: null },
193
168
  // startsAt: { type: Date, default: null }
194
169
  // },
195
-
196
- // //new fields added
197
-
198
- // returnPolicy: {
199
- // hasReturn: { type: Boolean, default: false },
200
- // returnType: {
201
- // type: [String],
202
- // enum: ['refund', 'replacement'],
203
- // default: []
204
- // },
205
- // returnDays: { type: Number, min: 0, default: null },
206
- // terms: [String] // Keep existing terms for backward compatibility
207
- // },
208
170
  // sku: {
209
171
  // type: String,
210
172
  // required: true,
211
- // match: [/^[A-Za-z0-9-]{6,}$/, 'SKU must be at least 6 alphanumeric characters']
173
+ // index: true
212
174
  // },
213
- // // ----------end of new fields added
214
175
  // images: [
215
176
  // {
216
177
  // key: { type: String, maxLength: 255, default: null },
@@ -239,7 +200,22 @@ export default ProductListing;
239
200
  // min: 0,
240
201
  // default: null,
241
202
  // },
242
-
203
+ // logisticsType: {
204
+ // type: String,
205
+ // enum: ["flykupLogistics", "selfShipment"],
206
+ // default: null,
207
+ // },
208
+ // deliveryCharge: {
209
+ // type: Number,
210
+ // min: 0,
211
+ // default: null,
212
+ // },
213
+ // estimatedDeliveryDate: {
214
+ // type: Number, // Change from Date to Number
215
+ // min: 0,
216
+ // default: null,
217
+ // },
218
+
243
219
  // // --- ADDED/UPDATED FIELDS FROM FRONTEND ---
244
220
  // brand: { type: String, default: null }, // ADDED
245
221
  // manufacturer: String,
@@ -324,13 +300,10 @@ export default ProductListing;
324
300
  // },
325
301
  // totalReviews: { type: Number, default: 0 }
326
302
  // },
327
-
328
-
329
-
330
303
  // { timestamps: true }
331
304
  // );
332
305
  // ProductListingSchema.index({ title: 'text', description: 'text', category: 'text' });
333
- // ProductListingSchema.index({ sellerId: 1, sku: 1 }, { unique: true });
306
+
334
307
 
335
308
  // // Safe export to prevent OverwriteModelError
336
309
  // const ProductListing = mongoose.models.productlistings || mongoose.model("productlistings", ProductListingSchema);
@@ -339,4 +312,3 @@ export default ProductListing;
339
312
 
340
313
 
341
314
 
342
-
@@ -1,90 +1,101 @@
1
-
2
- // models/Stock.js
1
+ // models/Stock.js - Simplified
3
2
  import mongoose from "mongoose";
4
3
  const { Schema } = mongoose;
5
4
 
6
- // Sub-schema for manual stock updates
7
- const StockUpdateHistorySchema = new Schema({
8
- change: { type: Number, required: true }, // e.g., +50 or -10
9
- previousQuantity: { type: Number, required: true },
10
- newQuantity: { type: Number, required: true },
11
- reason: { type: String, default: "Manual update by seller" },
12
- updatedAt: { type: Date, default: Date.now }
13
- });
14
-
15
-
16
- const StockSchema = new Schema(
5
+ const stockSchema = new mongoose.Schema(
17
6
  {
18
- sellerId: {
19
- type: Schema.Types.ObjectId,
20
- ref: "sellers",
21
- },
22
7
  productListingId: {
23
8
  type: Schema.Types.ObjectId,
24
9
  ref: "productlistings",
10
+ required: true,
11
+ unique: true
12
+ },
13
+ quantity: {
14
+ type: Number,
15
+ default: 0,
16
+ min: 0
25
17
  },
26
18
  title: String,
27
19
  images: [{
28
20
  key: String,
29
21
  url: String
30
22
  }],
31
- quantity: {
23
+ // ❌ REMOVED: totalReserved, flashSaleReservations
24
+ lowStockThreshold: {
32
25
  type: Number,
33
- min: 0,
34
- default: 0,
26
+ default: 10
35
27
  },
36
- // History for manual stock adjustments
37
- stockUpdateHistory: [StockUpdateHistorySchema],
38
-
39
- // Track reservations for flash sales
40
- flashSaleReservations: [{
41
- flashSaleId: {
42
- type: Schema.Types.ObjectId,
43
- ref: "FlashSale",
44
- required: true
45
- },
46
- quantity: { type: Number, min: 0, default: 0 },
47
- status: {
48
- type: String,
49
- enum: ['reserved', 'active', 'released', 'sold', 'partially_sold'],
50
- default: 'reserved'
51
- },
52
- source: {
53
- type: String,
54
- enum: ['normal', 'live_stream'],
55
- default: 'normal'
56
- },
57
- reservedAt: { type: Date, default: Date.now },
58
- releasedAt: Date,
59
- soldQuantity: { type: Number, default: 0 }
60
- }],
61
- totalReserved: {
28
+ reorderQuantity: {
62
29
  type: Number,
63
- min: 0,
64
- default: 0
65
- }
30
+ default: 50
31
+ },
32
+ isInStock: {
33
+ type: Boolean,
34
+ default: true
35
+ },
36
+ lastRestocked: {
37
+ type: Date,
38
+ default: null
39
+ },
40
+ stockUpdateHistory: [{
41
+ change: Number,
42
+ previousQuantity: Number,
43
+ newQuantity: Number,
44
+ reason: String,
45
+ updatedAt: { type: Date, default: Date.now }
46
+ }]
66
47
  },
67
48
  { timestamps: true }
68
49
  );
69
50
 
70
- // Pre-save hook to calculate totalReserved
71
- StockSchema.pre('save', function(next) {
72
- if (this.isModified('flashSaleReservations')) {
73
- this.totalReserved = this.flashSaleReservations.reduce((total, reservation) => {
74
- return total + (['reserved', 'active'].includes(reservation.status) ? reservation.quantity : 0);
75
- }, 0);
76
- }
77
- next();
78
- });
51
+ const Stock = mongoose.models.stocks || mongoose.model("stocks", stockSchema);
52
+ export default Stock;
53
+
54
+
55
+ // // models/Stock.js - Simplified version without flash sale reservations
56
+ // import mongoose from "mongoose";
57
+ // const { Schema } = mongoose;
58
+
59
+ // const stockSchema = new mongoose.Schema(
60
+ // {
61
+ // productListingId: {
62
+ // type: Schema.Types.ObjectId,
63
+ // ref: "productlistings",
64
+ // required: true,
65
+ // unique: true
66
+ // },
67
+ // quantity: {
68
+ // type: Number,
69
+ // default: 0,
70
+ // min: 0
71
+ // },
72
+ // // REMOVED: totalReserved field since we don't need reservations
73
+ // // REMOVED: flashSaleReservations array completely
74
+ // lowStockThreshold: {
75
+ // type: Number,
76
+ // default: 10
77
+ // },
78
+ // reorderQuantity: {
79
+ // type: Number,
80
+ // default: 50
81
+ // },
82
+ // isInStock: {
83
+ // type: Boolean,
84
+ // default: true
85
+ // },
86
+ // lastRestocked: {
87
+ // type: Date,
88
+ // default: null
89
+ // }
90
+ // },
91
+ // { timestamps: true }
92
+ // );
79
93
 
80
- // Virtual for available quantity
81
- StockSchema.virtual('availableQuantity').get(function() {
82
- return Math.max(0, this.quantity - this.totalReserved);
83
- });
94
+ // // Indexes
95
+ // stockSchema.index({ productListingId: 1 });
96
+ // stockSchema.index({ isInStock: 1 });
97
+ // stockSchema.index({ quantity: 1 });
84
98
 
85
- // Ensure virtuals are included in JSON output
86
- StockSchema.set('toJSON', { virtuals: true });
87
- StockSchema.set('toObject', { virtuals: true });
99
+ // const Stock = mongoose.models.stocks || mongoose.model("stocks", stockSchema);
100
+ // export default Stock;
88
101
 
89
- const Stock = mongoose.models.stocks || mongoose.model("stocks", StockSchema);
90
- export default Stock;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flykup_model_development",
3
- "version": "3.1.53",
3
+ "version": "3.1.55",
4
4
  "main": "index.js",
5
5
  "type": "module",
6
6
  "private": false,