flykup_model_development 3.1.57 → 3.1.59
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/productListing.model.js +4 -0
- package/models/shows.model.js +173 -51
- package/package.json +1 -1
|
@@ -15,6 +15,10 @@ const ProductListingSchema = new Schema(
|
|
|
15
15
|
originalPrice: { type: Number, default: 0 },
|
|
16
16
|
endsAt: { type: Date, default: null },
|
|
17
17
|
startsAt: { type: Date, default: null }
|
|
18
|
+
},
|
|
19
|
+
reserveForLive: {
|
|
20
|
+
type: Boolean,
|
|
21
|
+
default: false
|
|
18
22
|
},
|
|
19
23
|
sku: {
|
|
20
24
|
type: String,
|
package/models/shows.model.js
CHANGED
|
@@ -20,7 +20,6 @@ const giveawayProductSchema = new Schema({
|
|
|
20
20
|
createdAt: { type: Date, default: Date.now }
|
|
21
21
|
});
|
|
22
22
|
|
|
23
|
-
// Live Flash Sale Schema
|
|
24
23
|
const liveFlashSaleSchema = new Schema({
|
|
25
24
|
_id: false,
|
|
26
25
|
productId: {
|
|
@@ -41,7 +40,7 @@ const liveFlashSaleSchema = new Schema({
|
|
|
41
40
|
duration: {
|
|
42
41
|
type: Number,
|
|
43
42
|
required: true,
|
|
44
|
-
enum: [10, 20, 30, 40, 50, 60,240]
|
|
43
|
+
enum: [10, 20, 30, 40, 50, 60, 240]
|
|
45
44
|
},
|
|
46
45
|
initialStock: {
|
|
47
46
|
type: Number,
|
|
@@ -73,14 +72,14 @@ const liveFlashSaleSchema = new Schema({
|
|
|
73
72
|
default: Date.now
|
|
74
73
|
}
|
|
75
74
|
});
|
|
76
|
-
|
|
75
|
+
|
|
76
|
+
// Show Schema with FIXED validation
|
|
77
77
|
const showSchema = new Schema(
|
|
78
78
|
{
|
|
79
79
|
sellerId: {
|
|
80
80
|
type: mongoose.Schema.Types.ObjectId,
|
|
81
81
|
ref: "sellers",
|
|
82
82
|
},
|
|
83
|
-
// === Host Information ===
|
|
84
83
|
host: {
|
|
85
84
|
type: mongoose.Schema.Types.ObjectId,
|
|
86
85
|
required: true,
|
|
@@ -91,7 +90,6 @@ const showSchema = new Schema(
|
|
|
91
90
|
required: true,
|
|
92
91
|
enum: ['sellers', 'dropshippers']
|
|
93
92
|
},
|
|
94
|
-
|
|
95
93
|
title: {
|
|
96
94
|
type: String,
|
|
97
95
|
required: true,
|
|
@@ -122,7 +120,6 @@ const showSchema = new Schema(
|
|
|
122
120
|
type: [String],
|
|
123
121
|
default: [],
|
|
124
122
|
},
|
|
125
|
-
|
|
126
123
|
thumbnailImage: {
|
|
127
124
|
type: String,
|
|
128
125
|
default: null,
|
|
@@ -142,8 +139,6 @@ const showSchema = new Schema(
|
|
|
142
139
|
type: String,
|
|
143
140
|
default: null,
|
|
144
141
|
},
|
|
145
|
-
|
|
146
|
-
// === Stream Layout Configuration ===
|
|
147
142
|
orientation: {
|
|
148
143
|
type: String,
|
|
149
144
|
enum: ['horizontal', 'vertical'],
|
|
@@ -154,7 +149,6 @@ const showSchema = new Schema(
|
|
|
154
149
|
enum: ['side-by-side', 'top-bottom'],
|
|
155
150
|
default: 'side-by-side'
|
|
156
151
|
},
|
|
157
|
-
|
|
158
152
|
showStatus: {
|
|
159
153
|
type: String,
|
|
160
154
|
enum: ['created', 'live', 'cancelled', 'ended'],
|
|
@@ -170,29 +164,52 @@ const showSchema = new Schema(
|
|
|
170
164
|
default: [],
|
|
171
165
|
},
|
|
172
166
|
|
|
167
|
+
// ✅ FIXED: Better validation for buyNowProducts
|
|
173
168
|
buyNowProducts: {
|
|
174
169
|
type: [
|
|
175
170
|
{
|
|
176
171
|
_id: false,
|
|
177
172
|
productId: { type: Schema.Types.ObjectId, ref: "productlistings" },
|
|
178
|
-
productOwnerSellerId: {
|
|
173
|
+
productOwnerSellerId: {
|
|
174
|
+
type: Schema.Types.ObjectId,
|
|
175
|
+
ref: 'sellers',
|
|
176
|
+
required: function() {
|
|
177
|
+
// Only require if productId exists
|
|
178
|
+
return this.productId != null;
|
|
179
|
+
}
|
|
180
|
+
},
|
|
179
181
|
productPrice: { type: Number, min: 0, default: null },
|
|
180
182
|
},
|
|
181
183
|
],
|
|
182
184
|
default: [],
|
|
185
|
+
validate: {
|
|
186
|
+
validator: function(products) {
|
|
187
|
+
// Custom validation to ensure productOwnerSellerId exists when productId exists
|
|
188
|
+
return products.every(product =>
|
|
189
|
+
!product.productId || (product.productId && product.productOwnerSellerId)
|
|
190
|
+
);
|
|
191
|
+
},
|
|
192
|
+
message: 'productOwnerSellerId is required when productId is provided'
|
|
193
|
+
}
|
|
183
194
|
},
|
|
184
|
-
|
|
195
|
+
|
|
196
|
+
auctionProducts: {
|
|
185
197
|
type: [
|
|
186
198
|
{
|
|
187
199
|
_id: false,
|
|
188
200
|
productId: { type: Schema.Types.ObjectId, ref: "productlistings" },
|
|
189
|
-
productOwnerSellerId: {
|
|
201
|
+
productOwnerSellerId: {
|
|
202
|
+
type: Schema.Types.ObjectId,
|
|
203
|
+
ref: 'sellers',
|
|
204
|
+
required: function() {
|
|
205
|
+
return this.productId != null;
|
|
206
|
+
}
|
|
207
|
+
},
|
|
190
208
|
startingPrice: { type: Number, min: 0, default: null },
|
|
191
209
|
reservedPrice: { type: Number, min: 0, default: null },
|
|
192
210
|
auctionNumber: {
|
|
193
211
|
type: Number,
|
|
194
212
|
},
|
|
195
|
-
// BGA Integration - Reference to BGA auction document
|
|
196
213
|
auctionObjectId: {
|
|
197
214
|
type: Schema.Types.ObjectId,
|
|
198
215
|
required: true,
|
|
@@ -208,10 +225,9 @@ const showSchema = new Schema(
|
|
|
208
225
|
default: []
|
|
209
226
|
},
|
|
210
227
|
|
|
211
|
-
// === LIVE FLASH SALE FIELDS (ADD THESE) ===
|
|
212
228
|
liveFlashSales: {
|
|
213
229
|
type: [liveFlashSaleSchema],
|
|
214
|
-
default: []
|
|
230
|
+
default: []
|
|
215
231
|
},
|
|
216
232
|
currentFlashSale: {
|
|
217
233
|
type: Schema.Types.ObjectId,
|
|
@@ -232,9 +248,39 @@ const showSchema = new Schema(
|
|
|
232
248
|
{ timestamps: true }
|
|
233
249
|
);
|
|
234
250
|
|
|
235
|
-
|
|
251
|
+
// ✅ ADD THIS PRE-SAVE MIDDLEWARE TO CLEAN INVALID DATA
|
|
252
|
+
showSchema.pre('save', function(next) {
|
|
236
253
|
const doc = this;
|
|
237
254
|
|
|
255
|
+
// Clean up buyNowProducts - remove items without required fields
|
|
256
|
+
if (doc.buyNowProducts && Array.isArray(doc.buyNowProducts)) {
|
|
257
|
+
doc.buyNowProducts = doc.buyNowProducts.filter(product =>
|
|
258
|
+
product &&
|
|
259
|
+
product.productId &&
|
|
260
|
+
product.productOwnerSellerId
|
|
261
|
+
);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
// Clean up auctionProducts
|
|
265
|
+
if (doc.auctionProducts && Array.isArray(doc.auctionProducts)) {
|
|
266
|
+
doc.auctionProducts = doc.auctionProducts.filter(product =>
|
|
267
|
+
product &&
|
|
268
|
+
product.productId &&
|
|
269
|
+
product.productOwnerSellerId &&
|
|
270
|
+
product.auctionObjectId
|
|
271
|
+
);
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
// Clean up giveawayProducts
|
|
275
|
+
if (doc.giveawayProducts && Array.isArray(doc.giveawayProducts)) {
|
|
276
|
+
doc.giveawayProducts = doc.giveawayProducts.filter(product =>
|
|
277
|
+
product &&
|
|
278
|
+
product.productId &&
|
|
279
|
+
product.productOwnerSellerId &&
|
|
280
|
+
product.giveawayObjectId
|
|
281
|
+
);
|
|
282
|
+
}
|
|
283
|
+
|
|
238
284
|
// Set liveDrop based on product types
|
|
239
285
|
const hasBuyNow = doc.buyNowProducts && doc.buyNowProducts.length > 0;
|
|
240
286
|
const hasAuction = doc.auctionProducts && doc.auctionProducts.length > 0;
|
|
@@ -249,15 +295,22 @@ showSchema.pre('save', function (next) {
|
|
|
249
295
|
next();
|
|
250
296
|
});
|
|
251
297
|
|
|
252
|
-
|
|
298
|
+
// ✅ ADD THIS PRE-VALIDATION MIDDLEWARE FOR EXTRA SAFETY
|
|
299
|
+
showSchema.pre('validate', function(next) {
|
|
300
|
+
// Ensure all arrays exist (prevent undefined errors)
|
|
301
|
+
if (!this.buyNowProducts) this.buyNowProducts = [];
|
|
302
|
+
if (!this.auctionProducts) this.auctionProducts = [];
|
|
303
|
+
if (!this.giveawayProducts) this.giveawayProducts = [];
|
|
304
|
+
if (!this.liveFlashSales) this.liveFlashSales = [];
|
|
305
|
+
|
|
306
|
+
next();
|
|
307
|
+
});
|
|
253
308
|
|
|
309
|
+
const Show = mongoose.model("shows", showSchema);
|
|
254
310
|
export default Show;
|
|
255
311
|
|
|
256
312
|
|
|
257
313
|
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
314
|
// import mongoose from "mongoose";
|
|
262
315
|
// const { Schema } = mongoose;
|
|
263
316
|
|
|
@@ -266,41 +319,90 @@ export default Show;
|
|
|
266
319
|
// productId: { type: Schema.Types.ObjectId, ref: "productlistings", required: true },
|
|
267
320
|
// productOwnerSellerId: { type: Schema.Types.ObjectId, ref: 'sellers', required: true },
|
|
268
321
|
// productTitle: { type: String },
|
|
269
|
-
|
|
270
|
-
// // BGA Integration Fields
|
|
271
322
|
// giveawayObjectId: { type: Schema.Types.ObjectId, required: true, index: true },
|
|
272
323
|
// giveawayStatus: {
|
|
273
324
|
// type: String,
|
|
274
325
|
// enum: ['preparing', 'ready', 'active', 'ended', 'failed'],
|
|
275
326
|
// default: 'preparing'
|
|
276
327
|
// },
|
|
277
|
-
//
|
|
328
|
+
// requireAutoFollow: {
|
|
278
329
|
// type: Boolean,
|
|
279
330
|
// default: false
|
|
280
331
|
// },
|
|
281
|
-
|
|
282
332
|
// activatedAt: { type: Date, default: null },
|
|
283
333
|
// createdAt: { type: Date, default: Date.now }
|
|
284
334
|
// });
|
|
285
335
|
|
|
336
|
+
// // Live Flash Sale Schema
|
|
337
|
+
// const liveFlashSaleSchema = new Schema({
|
|
338
|
+
// _id: false,
|
|
339
|
+
// productId: {
|
|
340
|
+
// type: Schema.Types.ObjectId,
|
|
341
|
+
// ref: "productlistings",
|
|
342
|
+
// required: true
|
|
343
|
+
// },
|
|
344
|
+
// stockId: {
|
|
345
|
+
// type: Schema.Types.ObjectId,
|
|
346
|
+
// ref: "stocks",
|
|
347
|
+
// required: true
|
|
348
|
+
// },
|
|
349
|
+
// flashPrice: {
|
|
350
|
+
// type: Number,
|
|
351
|
+
// required: true,
|
|
352
|
+
// min: 1
|
|
353
|
+
// },
|
|
354
|
+
// duration: {
|
|
355
|
+
// type: Number,
|
|
356
|
+
// required: true,
|
|
357
|
+
// enum: [10, 20, 30, 40, 50, 60,240]
|
|
358
|
+
// },
|
|
359
|
+
// initialStock: {
|
|
360
|
+
// type: Number,
|
|
361
|
+
// required: true,
|
|
362
|
+
// min: 1
|
|
363
|
+
// },
|
|
364
|
+
// currentStock: {
|
|
365
|
+
// type: Number,
|
|
366
|
+
// required: true,
|
|
367
|
+
// min: 0
|
|
368
|
+
// },
|
|
369
|
+
// sold: {
|
|
370
|
+
// type: Number,
|
|
371
|
+
// default: 0
|
|
372
|
+
// },
|
|
373
|
+
// status: {
|
|
374
|
+
// type: String,
|
|
375
|
+
// enum: ['scheduled', 'active', 'ended', 'cancelled'],
|
|
376
|
+
// default: 'scheduled'
|
|
377
|
+
// },
|
|
378
|
+
// startTime: Date,
|
|
379
|
+
// endTime: Date,
|
|
380
|
+
// flashSaleId: {
|
|
381
|
+
// type: Schema.Types.ObjectId,
|
|
382
|
+
// ref: 'FlashSale'
|
|
383
|
+
// },
|
|
384
|
+
// createdAt: {
|
|
385
|
+
// type: Date,
|
|
386
|
+
// default: Date.now
|
|
387
|
+
// }
|
|
388
|
+
// });
|
|
286
389
|
// // Show Schema
|
|
287
390
|
// const showSchema = new Schema(
|
|
288
391
|
// {
|
|
289
|
-
|
|
290
|
-
//
|
|
291
|
-
//
|
|
292
|
-
//
|
|
293
|
-
// },
|
|
392
|
+
// sellerId: {
|
|
393
|
+
// type: mongoose.Schema.Types.ObjectId,
|
|
394
|
+
// ref: "sellers",
|
|
395
|
+
// },
|
|
294
396
|
// // === Host Information ===
|
|
295
|
-
// host: {
|
|
397
|
+
// host: {
|
|
296
398
|
// type: mongoose.Schema.Types.ObjectId,
|
|
297
399
|
// required: true,
|
|
298
|
-
// refPath: 'hostModel'
|
|
400
|
+
// refPath: 'hostModel'
|
|
299
401
|
// },
|
|
300
|
-
// hostModel: {
|
|
402
|
+
// hostModel: {
|
|
301
403
|
// type: String,
|
|
302
404
|
// required: true,
|
|
303
|
-
// enum: ['sellers', 'dropshippers']
|
|
405
|
+
// enum: ['sellers', 'dropshippers']
|
|
304
406
|
// },
|
|
305
407
|
|
|
306
408
|
// title: {
|
|
@@ -315,7 +417,7 @@ export default Show;
|
|
|
315
417
|
// },
|
|
316
418
|
// scheduledAt: {
|
|
317
419
|
// type: Date,
|
|
318
|
-
// index: true
|
|
420
|
+
// index: true
|
|
319
421
|
// },
|
|
320
422
|
// category: {
|
|
321
423
|
// type: String,
|
|
@@ -335,11 +437,11 @@ export default Show;
|
|
|
335
437
|
// },
|
|
336
438
|
|
|
337
439
|
// thumbnailImage: {
|
|
338
|
-
// type: String,
|
|
440
|
+
// type: String,
|
|
339
441
|
// default: null,
|
|
340
442
|
// },
|
|
341
443
|
// previewVideo: {
|
|
342
|
-
// type: String,
|
|
444
|
+
// type: String,
|
|
343
445
|
// default: null,
|
|
344
446
|
// },
|
|
345
447
|
// language: {
|
|
@@ -350,21 +452,21 @@ export default Show;
|
|
|
350
452
|
// default: false,
|
|
351
453
|
// },
|
|
352
454
|
// streamUrl: {
|
|
353
|
-
// type: String,
|
|
455
|
+
// type: String,
|
|
354
456
|
// default: null,
|
|
355
457
|
// },
|
|
356
458
|
|
|
357
|
-
// // === Stream Layout Configuration
|
|
358
|
-
//
|
|
359
|
-
//
|
|
360
|
-
//
|
|
361
|
-
//
|
|
362
|
-
//
|
|
363
|
-
//
|
|
364
|
-
//
|
|
365
|
-
//
|
|
366
|
-
//
|
|
367
|
-
//
|
|
459
|
+
// // === Stream Layout Configuration ===
|
|
460
|
+
// orientation: {
|
|
461
|
+
// type: String,
|
|
462
|
+
// enum: ['horizontal', 'vertical'],
|
|
463
|
+
// default: 'horizontal'
|
|
464
|
+
// },
|
|
465
|
+
// layout: {
|
|
466
|
+
// type: String,
|
|
467
|
+
// enum: ['side-by-side', 'top-bottom'],
|
|
468
|
+
// default: 'side-by-side'
|
|
469
|
+
// },
|
|
368
470
|
|
|
369
471
|
// showStatus: {
|
|
370
472
|
// type: String,
|
|
@@ -387,12 +489,12 @@ export default Show;
|
|
|
387
489
|
// _id: false,
|
|
388
490
|
// productId: { type: Schema.Types.ObjectId, ref: "productlistings" },
|
|
389
491
|
// productOwnerSellerId: { type: Schema.Types.ObjectId, ref: 'sellers', required: true },
|
|
390
|
-
// productPrice: { type: Number, min: 0, default: null },
|
|
492
|
+
// productPrice: { type: Number, min: 0, default: null },
|
|
391
493
|
// },
|
|
392
494
|
// ],
|
|
393
495
|
// default: [],
|
|
394
496
|
// },
|
|
395
|
-
//
|
|
497
|
+
// auctionProducts: {
|
|
396
498
|
// type: [
|
|
397
499
|
// {
|
|
398
500
|
// _id: false,
|
|
@@ -402,6 +504,12 @@ export default Show;
|
|
|
402
504
|
// reservedPrice: { type: Number, min: 0, default: null },
|
|
403
505
|
// auctionNumber: {
|
|
404
506
|
// type: Number,
|
|
507
|
+
// },
|
|
508
|
+
// // BGA Integration - Reference to BGA auction document
|
|
509
|
+
// auctionObjectId: {
|
|
510
|
+
// type: Schema.Types.ObjectId,
|
|
511
|
+
// required: true,
|
|
512
|
+
// index: true
|
|
405
513
|
// }
|
|
406
514
|
// },
|
|
407
515
|
// ],
|
|
@@ -413,6 +521,17 @@ export default Show;
|
|
|
413
521
|
// default: []
|
|
414
522
|
// },
|
|
415
523
|
|
|
524
|
+
// // === LIVE FLASH SALE FIELDS (ADD THESE) ===
|
|
525
|
+
// liveFlashSales: {
|
|
526
|
+
// type: [liveFlashSaleSchema],
|
|
527
|
+
// default: [] // This ensures it's always an array
|
|
528
|
+
// },
|
|
529
|
+
// currentFlashSale: {
|
|
530
|
+
// type: Schema.Types.ObjectId,
|
|
531
|
+
// ref: 'FlashSale',
|
|
532
|
+
// default: null
|
|
533
|
+
// },
|
|
534
|
+
|
|
416
535
|
// enabledProductTypes: {
|
|
417
536
|
// buyNow: { type: Boolean, default: false },
|
|
418
537
|
// auction: { type: Boolean, default: false },
|
|
@@ -445,4 +564,7 @@ export default Show;
|
|
|
445
564
|
|
|
446
565
|
// const Show = mongoose.model("shows", showSchema);
|
|
447
566
|
|
|
448
|
-
// export default Show;
|
|
567
|
+
// export default Show;
|
|
568
|
+
|
|
569
|
+
|
|
570
|
+
|