flykup_model_development 3.1.16 → 3.1.18
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/order.modal.js +392 -50
- package/package.json +1 -1
package/models/order.modal.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
// order.
|
|
1
|
+
// order.model.js - CORRECTED SCHEMA STRUCTURE
|
|
2
2
|
import mongoose from 'mongoose';
|
|
3
3
|
import { nanoid } from 'nanoid';
|
|
4
4
|
|
|
5
5
|
const orderSchema = new mongoose.Schema(
|
|
6
6
|
{
|
|
7
|
-
|
|
7
|
+
orderId: {
|
|
8
8
|
type: String,
|
|
9
9
|
required: true,
|
|
10
10
|
unique: true,
|
|
11
|
-
default: () => `ORD-${nanoid(8)}`
|
|
11
|
+
default: () => `FLY-ORD-${nanoid(8)}`
|
|
12
12
|
},
|
|
13
13
|
userId: {
|
|
14
14
|
type: mongoose.Schema.Types.ObjectId,
|
|
@@ -48,15 +48,7 @@ const orderSchema = new mongoose.Schema(
|
|
|
48
48
|
type: String,
|
|
49
49
|
enum: ['CGST+SGST', 'IGST',"NON-GST"],
|
|
50
50
|
required: true
|
|
51
|
-
}
|
|
52
|
-
isFlashSale: {
|
|
53
|
-
type: Boolean,
|
|
54
|
-
default: false
|
|
55
|
-
},
|
|
56
|
-
flashPrice: {
|
|
57
|
-
type: Number,
|
|
58
|
-
default: null // Store the specific flash price used for this item
|
|
59
|
-
}
|
|
51
|
+
}
|
|
60
52
|
}],
|
|
61
53
|
totalBaseAmount: {
|
|
62
54
|
type: Number,
|
|
@@ -84,30 +76,75 @@ const orderSchema = new mongoose.Schema(
|
|
|
84
76
|
amount: Number
|
|
85
77
|
}
|
|
86
78
|
},
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
addressModified: {
|
|
79
|
+
deliveryAddress: {
|
|
80
|
+
name: { type: String, maxLength: 50, trim: true, required: true },
|
|
81
|
+
mobile: { type: String, trim: true, maxLength: 15, required: true },
|
|
82
|
+
alternateMobile: { type: String, trim: true, maxLength: 15, default: null },
|
|
83
|
+
line1: { type: String, trim: true, maxLength: 100, required: true },
|
|
84
|
+
line2: { type: String, trim: true, maxLength: 100, default: "" },
|
|
85
|
+
city: { type: String, trim: true, maxLength: 50, required: true },
|
|
86
|
+
state: { type: String, trim: true, maxLength: 50, required: true },
|
|
87
|
+
pincode: { type: String, maxLength: 6, trim: true, required: true },
|
|
88
|
+
addressType: {
|
|
89
|
+
type: String,
|
|
90
|
+
enum: ['home', 'work', 'other'],
|
|
91
|
+
default: 'home'
|
|
92
|
+
},
|
|
93
|
+
addressModified: {
|
|
103
94
|
type: Boolean,
|
|
104
95
|
default: false
|
|
105
|
-
|
|
106
|
-
|
|
96
|
+
},
|
|
97
|
+
addressModifiedAt: {
|
|
107
98
|
type: Date,
|
|
108
99
|
default: null
|
|
109
|
-
|
|
110
|
-
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
// CORRECT PLACEMENT - TOP LEVEL FIELDS
|
|
103
|
+
logisticsDetails: {
|
|
104
|
+
shipmentMethod: {
|
|
105
|
+
type: String,
|
|
106
|
+
enum: ['self_shipment', 'flykup_logistics'],
|
|
107
|
+
default: 'flykup_logistics'
|
|
108
|
+
},
|
|
109
|
+
awbNumber: String,
|
|
110
|
+
carrier: String,
|
|
111
|
+
carrierId: String,
|
|
112
|
+
trackingNumber: String,
|
|
113
|
+
trackingUrl: String,
|
|
114
|
+
expectedDeliveryDate: Date,
|
|
115
|
+
shipmentBookedAt: Date,
|
|
116
|
+
logisticsResponse: mongoose.Schema.Types.Mixed,
|
|
117
|
+
shipmentBookingStatus: {
|
|
118
|
+
type: String,
|
|
119
|
+
enum: ['pending', 'booked', 'failed'],
|
|
120
|
+
default: 'pending'
|
|
121
|
+
},
|
|
122
|
+
shipmentBookingError: String,
|
|
123
|
+
multipleSellers: {
|
|
124
|
+
type: Boolean,
|
|
125
|
+
default: false
|
|
126
|
+
},
|
|
127
|
+
selectedCourier: {
|
|
128
|
+
courierId: String,
|
|
129
|
+
courierName: String,
|
|
130
|
+
deliveryCharges: Number,
|
|
131
|
+
estimatedDays: Number,
|
|
132
|
+
deliveryDate: String
|
|
133
|
+
}
|
|
134
|
+
},
|
|
135
|
+
packageDetails: {
|
|
136
|
+
totalWeight: Number,
|
|
137
|
+
weightUnit: {
|
|
138
|
+
type: String,
|
|
139
|
+
default: 'grams'
|
|
140
|
+
},
|
|
141
|
+
dimensions: {
|
|
142
|
+
length: Number,
|
|
143
|
+
width: Number,
|
|
144
|
+
height: Number
|
|
145
|
+
},
|
|
146
|
+
volumetricWeight: Number
|
|
147
|
+
},
|
|
111
148
|
pickupAddresses: [{
|
|
112
149
|
sellerUserId: {
|
|
113
150
|
type: mongoose.Schema.Types.ObjectId,
|
|
@@ -144,7 +181,7 @@ const orderSchema = new mongoose.Schema(
|
|
|
144
181
|
}],
|
|
145
182
|
paymentMethod: {
|
|
146
183
|
type: String,
|
|
147
|
-
|
|
184
|
+
enum: ['CARD', 'UPI', 'NETBANKING', 'WALLET', 'COD', "PENDING_PAYMENT", "CASHFREE","RAZORPAY", "Online"],
|
|
148
185
|
required: true
|
|
149
186
|
},
|
|
150
187
|
paymentStatus: {
|
|
@@ -176,7 +213,7 @@ const orderSchema = new mongoose.Schema(
|
|
|
176
213
|
},
|
|
177
214
|
sourceType: {
|
|
178
215
|
type: String,
|
|
179
|
-
enum: ['static', 'shoppable_video', 'livestream', 'auction'
|
|
216
|
+
enum: ['static', 'shoppable_video', 'livestream', 'auction'],
|
|
180
217
|
required: true
|
|
181
218
|
},
|
|
182
219
|
sourceRefId: String,
|
|
@@ -262,19 +299,6 @@ cancelSource: {
|
|
|
262
299
|
enum: ['user', 'seller', 'system'],
|
|
263
300
|
default: 'user'
|
|
264
301
|
},
|
|
265
|
-
flashSaleItems: [{
|
|
266
|
-
productId: {
|
|
267
|
-
type: mongoose.Schema.Types.ObjectId,
|
|
268
|
-
ref: 'productlistings'
|
|
269
|
-
},
|
|
270
|
-
flashSaleId: {
|
|
271
|
-
type: mongoose.Schema.Types.ObjectId,
|
|
272
|
-
ref: 'FlashSale'
|
|
273
|
-
},
|
|
274
|
-
quantity: Number,
|
|
275
|
-
flashPrice: Number,
|
|
276
|
-
originalPrice: Number
|
|
277
|
-
}],
|
|
278
302
|
payment: {
|
|
279
303
|
type: mongoose.Schema.Types.ObjectId,
|
|
280
304
|
ref: 'orderPayment'
|
|
@@ -293,13 +317,331 @@ payment: {
|
|
|
293
317
|
default: 0
|
|
294
318
|
},
|
|
295
319
|
invoiceError: String
|
|
320
|
+
|
|
321
|
+
|
|
322
|
+
|
|
323
|
+
|
|
324
|
+
|
|
325
|
+
|
|
296
326
|
},
|
|
297
|
-
|
|
327
|
+
|
|
298
328
|
{ timestamps: true }
|
|
299
329
|
);
|
|
300
330
|
|
|
301
331
|
|
|
332
|
+
const Order = mongoose.model('Order', orderSchema);
|
|
333
|
+
export default Order;
|
|
302
334
|
|
|
303
335
|
|
|
304
|
-
const Order = mongoose.models.Order || mongoose.model('Order', orderSchema);
|
|
305
|
-
export default Order;
|
|
336
|
+
// const Order = mongoose.models.Order || mongoose.model('Order', orderSchema);
|
|
337
|
+
// export default Order;
|
|
338
|
+
|
|
339
|
+
|
|
340
|
+
|
|
341
|
+
|
|
342
|
+
|
|
343
|
+
// // order.modal.js
|
|
344
|
+
// import mongoose from 'mongoose';
|
|
345
|
+
// import { nanoid } from 'nanoid';
|
|
346
|
+
|
|
347
|
+
// const orderSchema = new mongoose.Schema(
|
|
348
|
+
// {
|
|
349
|
+
// orderId: {
|
|
350
|
+
// type: String,
|
|
351
|
+
// required: true,
|
|
352
|
+
// unique: true,
|
|
353
|
+
// default: () => `ORD-${nanoid(8)}`
|
|
354
|
+
// },
|
|
355
|
+
// userId: {
|
|
356
|
+
// type: mongoose.Schema.Types.ObjectId,
|
|
357
|
+
// ref: 'users',
|
|
358
|
+
// required: true,
|
|
359
|
+
// index: true
|
|
360
|
+
// },
|
|
361
|
+
// products: [{
|
|
362
|
+
// productId: {
|
|
363
|
+
// type: mongoose.Schema.Types.ObjectId,
|
|
364
|
+
// ref: 'productlistings',
|
|
365
|
+
// required: true
|
|
366
|
+
// },
|
|
367
|
+
// sellerUserId: {
|
|
368
|
+
// type: mongoose.Schema.Types.ObjectId,
|
|
369
|
+
// ref: 'users',
|
|
370
|
+
// required: true
|
|
371
|
+
// },
|
|
372
|
+
// quantity: {
|
|
373
|
+
// type: Number,
|
|
374
|
+
// required: true,
|
|
375
|
+
// min: 1
|
|
376
|
+
// },
|
|
377
|
+
// basePrice: {
|
|
378
|
+
// type: Number,
|
|
379
|
+
// required: true
|
|
380
|
+
// },
|
|
381
|
+
// gstRate: {
|
|
382
|
+
// type: Number,
|
|
383
|
+
// required: true
|
|
384
|
+
// },
|
|
385
|
+
// gstAmount: {
|
|
386
|
+
// type: Number,
|
|
387
|
+
// required: true
|
|
388
|
+
// },
|
|
389
|
+
// gstType: {
|
|
390
|
+
// type: String,
|
|
391
|
+
// enum: ['CGST+SGST', 'IGST',"NON-GST"],
|
|
392
|
+
// required: true
|
|
393
|
+
// },
|
|
394
|
+
// isFlashSale: {
|
|
395
|
+
// type: Boolean,
|
|
396
|
+
// default: false
|
|
397
|
+
// },
|
|
398
|
+
// flashPrice: {
|
|
399
|
+
// type: Number,
|
|
400
|
+
// default: null // Store the specific flash price used for this item
|
|
401
|
+
// }
|
|
402
|
+
// }],
|
|
403
|
+
// totalBaseAmount: {
|
|
404
|
+
// type: Number,
|
|
405
|
+
// required: true
|
|
406
|
+
// },
|
|
407
|
+
// totalGstAmount: {
|
|
408
|
+
// type: Number,
|
|
409
|
+
// required: true
|
|
410
|
+
// },
|
|
411
|
+
// totalAmount: {
|
|
412
|
+
// type: Number,
|
|
413
|
+
// required: true
|
|
414
|
+
// },
|
|
415
|
+
// gstSplit: {
|
|
416
|
+
// cgst: {
|
|
417
|
+
// rate: Number,
|
|
418
|
+
// amount: Number
|
|
419
|
+
// },
|
|
420
|
+
// sgst: {
|
|
421
|
+
// rate: Number,
|
|
422
|
+
// amount: Number
|
|
423
|
+
// },
|
|
424
|
+
// igst: {
|
|
425
|
+
// rate: Number,
|
|
426
|
+
// amount: Number
|
|
427
|
+
// }
|
|
428
|
+
// },
|
|
429
|
+
// deliveryAddress: {
|
|
430
|
+
// name: { type: String, maxLength: 50, trim: true, required: true },
|
|
431
|
+
// mobile: { type: String, trim: true, maxLength: 15, required: true },
|
|
432
|
+
// alternateMobile: { type: String, trim: true, maxLength: 15, default: null },
|
|
433
|
+
// line1: { type: String, trim: true, maxLength: 100, required: true },
|
|
434
|
+
// line2: { type: String, trim: true, maxLength: 100, default: "" },
|
|
435
|
+
// city: { type: String, trim: true, maxLength: 50, required: true },
|
|
436
|
+
// state: { type: String, trim: true, maxLength: 50, required: true },
|
|
437
|
+
// pincode: { type: String, maxLength: 6, trim: true, required: true },
|
|
438
|
+
// addressType: {
|
|
439
|
+
// type: String,
|
|
440
|
+
// enum: ['home', 'work', 'other'],
|
|
441
|
+
// default: 'home'
|
|
442
|
+
// },
|
|
443
|
+
// // --- ADD THESE FIELDS INSIDE deliveryAddress ---
|
|
444
|
+
// addressModified: {
|
|
445
|
+
// type: Boolean,
|
|
446
|
+
// default: false
|
|
447
|
+
// },
|
|
448
|
+
// addressModifiedAt: {
|
|
449
|
+
// type: Date,
|
|
450
|
+
// default: null
|
|
451
|
+
// }
|
|
452
|
+
// },
|
|
453
|
+
// pickupAddresses: [{
|
|
454
|
+
// sellerUserId: {
|
|
455
|
+
// type: mongoose.Schema.Types.ObjectId,
|
|
456
|
+
// ref: 'users',
|
|
457
|
+
// required: true
|
|
458
|
+
// },
|
|
459
|
+
// name: String,
|
|
460
|
+
// mobile: String,
|
|
461
|
+
// addressLine1: {
|
|
462
|
+
// type: String,
|
|
463
|
+
// trim: true,
|
|
464
|
+
// maxLength: 150,
|
|
465
|
+
// },
|
|
466
|
+
// addressLine2: {
|
|
467
|
+
// type: String,
|
|
468
|
+
// trim: true,
|
|
469
|
+
// maxLength: 150,
|
|
470
|
+
// },
|
|
471
|
+
// city: {
|
|
472
|
+
// type: String,
|
|
473
|
+
// trim: true,
|
|
474
|
+
// maxLength: 50,
|
|
475
|
+
// },
|
|
476
|
+
// state: {
|
|
477
|
+
// type: String,
|
|
478
|
+
// trim: true,
|
|
479
|
+
// maxLength: 50,
|
|
480
|
+
// },
|
|
481
|
+
// pincode: {
|
|
482
|
+
// type: String,
|
|
483
|
+
// trim: true,
|
|
484
|
+
// maxLength: 6,
|
|
485
|
+
// },
|
|
486
|
+
// }],
|
|
487
|
+
// paymentMethod: {
|
|
488
|
+
// type: String,
|
|
489
|
+
// enum: ['CARD', 'UPI', 'NETBANKING', 'WALLET', 'COD', "PENDING_PAYMENT", "CASHFREE","RAZORPAY", "Online"],
|
|
490
|
+
// required: true
|
|
491
|
+
// },
|
|
492
|
+
// paymentStatus: {
|
|
493
|
+
// type: String,
|
|
494
|
+
// enum: ['PENDING', 'PAID', 'FAILED', 'REFUNDED'],
|
|
495
|
+
// default: 'PENDING',
|
|
496
|
+
// required: true
|
|
497
|
+
// },
|
|
498
|
+
// orderStatus: {
|
|
499
|
+
// type: String,
|
|
500
|
+
// enum: [
|
|
501
|
+
// 'PENDING_PAYMENT',
|
|
502
|
+
// 'ORDERED',
|
|
503
|
+
// 'PACKED',
|
|
504
|
+
// 'SHIPPED',
|
|
505
|
+
// 'OUT_FOR_DELIVERY',
|
|
506
|
+
// 'DELIVERED',
|
|
507
|
+
// 'CANCELLED',
|
|
508
|
+
// 'RETURN_REQUESTED',
|
|
509
|
+
// 'RETURN_APPROVED',
|
|
510
|
+
// 'RETURN_SHIPPED',
|
|
511
|
+
// 'RETURN_RECEIVED',
|
|
512
|
+
// 'REFUNDED',
|
|
513
|
+
// 'REPLACEMENT_SHIPPED',
|
|
514
|
+
// 'REPLACEMENT_DELIVERED'
|
|
515
|
+
// ],
|
|
516
|
+
// // default: 'ORDERED', // Default should be the initial state
|
|
517
|
+
// required: true
|
|
518
|
+
// },
|
|
519
|
+
// sourceType: {
|
|
520
|
+
// type: String,
|
|
521
|
+
// enum: ['static', 'shoppable_video', 'livestream', 'auction','flash_sale'],
|
|
522
|
+
// required: true
|
|
523
|
+
// },
|
|
524
|
+
// sourceRefId: String,
|
|
525
|
+
// deliveryCharge: {
|
|
526
|
+
// type: Number,
|
|
527
|
+
// default: 40
|
|
528
|
+
// },
|
|
529
|
+
// statusTimeline: {
|
|
530
|
+
// ordered: Date,
|
|
531
|
+
// paid: Date,
|
|
532
|
+
// packed: Date,
|
|
533
|
+
// shipped: Date,
|
|
534
|
+
// outForDelivery: Date,
|
|
535
|
+
// delivered: Date,
|
|
536
|
+
// cancelled: Date,
|
|
537
|
+
// returnRequested: Date,
|
|
538
|
+
// returnApproved: Date,
|
|
539
|
+
// returnShipped: Date,
|
|
540
|
+
// returnReceived: Date,
|
|
541
|
+
// refunded: Date,
|
|
542
|
+
// replacementShipped: Date,
|
|
543
|
+
// replacementDelivered: Date
|
|
544
|
+
// },
|
|
545
|
+
// courierDetails: {
|
|
546
|
+
// carrier: String,
|
|
547
|
+
// trackingNumber: String,
|
|
548
|
+
// estimatedDelivery: Date
|
|
549
|
+
// },
|
|
550
|
+
// returnDetails: {
|
|
551
|
+
// reason: String,
|
|
552
|
+
// type: {
|
|
553
|
+
// type: String,
|
|
554
|
+
// enum: ['REFUND', 'REPLACE']
|
|
555
|
+
// },
|
|
556
|
+
// items: [{
|
|
557
|
+
// productId: mongoose.Schema.Types.ObjectId,
|
|
558
|
+
// quantity: Number
|
|
559
|
+
// }]
|
|
560
|
+
// },
|
|
561
|
+
// refundDetails: {
|
|
562
|
+
// amount: Number,
|
|
563
|
+
// method: String,
|
|
564
|
+
// transactionId: String
|
|
565
|
+
// },
|
|
566
|
+
// replacementDetails: {
|
|
567
|
+
// trackingNumber: String,
|
|
568
|
+
// replacementOrderId: mongoose.Schema.Types.ObjectId
|
|
569
|
+
// },
|
|
570
|
+
// returnRequests: [{
|
|
571
|
+
// _id: { type: mongoose.Schema.Types.ObjectId, auto: true },
|
|
572
|
+
// orderItemId: { // Reference to the specific item in the order
|
|
573
|
+
// type: mongoose.Schema.Types.ObjectId,
|
|
574
|
+
// required: true
|
|
575
|
+
// },
|
|
576
|
+
// reason: String,
|
|
577
|
+
// additionalNotes: String,
|
|
578
|
+
// images: [String],
|
|
579
|
+
// status: {
|
|
580
|
+
// type: String,
|
|
581
|
+
// enum: ['PENDING',
|
|
582
|
+
// 'APPROVED',
|
|
583
|
+
// 'REJECTED',
|
|
584
|
+
// 'RETURN_SHIPPED',
|
|
585
|
+
// 'RETURN_RECEIVED',
|
|
586
|
+
// 'REFUNDED'],
|
|
587
|
+
// default: 'PENDING'
|
|
588
|
+
// },
|
|
589
|
+
// shipmentDetails: {
|
|
590
|
+
// carrier: String,
|
|
591
|
+
// trackingNumber: String,
|
|
592
|
+
// receiptImage: String, // S3 key for uploaded image
|
|
593
|
+
// shippedAt: Date
|
|
594
|
+
// },
|
|
595
|
+
// receivedAt: Date,
|
|
596
|
+
// refundProcessedAt: Date,
|
|
597
|
+
// sellerResponse: String,
|
|
598
|
+
// requestedAt: Date,
|
|
599
|
+
// processedAt: Date
|
|
600
|
+
// }],
|
|
601
|
+
// cancelReason: String,
|
|
602
|
+
// cancelSource: {
|
|
603
|
+
// type: String,
|
|
604
|
+
// enum: ['user', 'seller', 'system'],
|
|
605
|
+
// default: 'user'
|
|
606
|
+
// },
|
|
607
|
+
// flashSaleItems: [{
|
|
608
|
+
// productId: {
|
|
609
|
+
// type: mongoose.Schema.Types.ObjectId,
|
|
610
|
+
// ref: 'productlistings'
|
|
611
|
+
// },
|
|
612
|
+
// flashSaleId: {
|
|
613
|
+
// type: mongoose.Schema.Types.ObjectId,
|
|
614
|
+
// ref: 'FlashSale'
|
|
615
|
+
// },
|
|
616
|
+
// quantity: Number,
|
|
617
|
+
// flashPrice: Number,
|
|
618
|
+
// originalPrice: Number
|
|
619
|
+
// }],
|
|
620
|
+
// payment: {
|
|
621
|
+
// type: mongoose.Schema.Types.ObjectId,
|
|
622
|
+
// ref: 'orderPayment'
|
|
623
|
+
// },
|
|
624
|
+
// invoiceKey: {
|
|
625
|
+
// type: String,
|
|
626
|
+
// default: null
|
|
627
|
+
// },
|
|
628
|
+
// invoiceStatus: {
|
|
629
|
+
// type: String,
|
|
630
|
+
// enum: ['pending', 'processing', 'completed', 'failed'],
|
|
631
|
+
// default: 'pending'
|
|
632
|
+
// },
|
|
633
|
+
// invoiceRetries: {
|
|
634
|
+
// type: Number,
|
|
635
|
+
// default: 0
|
|
636
|
+
// },
|
|
637
|
+
// invoiceError: String
|
|
638
|
+
// },
|
|
639
|
+
|
|
640
|
+
// { timestamps: true }
|
|
641
|
+
// );
|
|
642
|
+
|
|
643
|
+
|
|
644
|
+
|
|
645
|
+
|
|
646
|
+
// const Order = mongoose.models.Order || mongoose.model('Order', orderSchema);
|
|
647
|
+
// export default Order;
|