flykup_model_development 3.1.54 → 3.1.56
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 +1 -1
- package/models/stock.model.js +46 -79
- package/package.json +1 -1
|
@@ -11,7 +11,7 @@ const ProductListingSchema = new Schema(
|
|
|
11
11
|
isActive: { type: Boolean, default: false },
|
|
12
12
|
flashSaleId: { type: mongoose.Schema.Types.ObjectId, ref: 'FlashSale' },
|
|
13
13
|
flashPrice: { type: Number, default: 0 },
|
|
14
|
-
|
|
14
|
+
// ❌ REMOVED: flashStock field - now using main quantity
|
|
15
15
|
originalPrice: { type: Number, default: 0 },
|
|
16
16
|
endsAt: { type: Date, default: null },
|
|
17
17
|
startsAt: { type: Date, default: null }
|
package/models/stock.model.js
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
|
-
// models/Stock.js - Simplified
|
|
1
|
+
// models/Stock.js - Simplified
|
|
2
2
|
import mongoose from "mongoose";
|
|
3
3
|
const { Schema } = mongoose;
|
|
4
4
|
|
|
5
5
|
const stockSchema = new mongoose.Schema(
|
|
6
6
|
{
|
|
7
|
+
sellerId: {
|
|
8
|
+
type: Schema.Types.ObjectId,
|
|
9
|
+
ref: "sellers",
|
|
10
|
+
},
|
|
7
11
|
productListingId: {
|
|
8
12
|
type: Schema.Types.ObjectId,
|
|
9
13
|
ref: "productlistings",
|
|
@@ -15,8 +19,12 @@ const stockSchema = new mongoose.Schema(
|
|
|
15
19
|
default: 0,
|
|
16
20
|
min: 0
|
|
17
21
|
},
|
|
18
|
-
|
|
19
|
-
|
|
22
|
+
title: String,
|
|
23
|
+
images: [{
|
|
24
|
+
key: String,
|
|
25
|
+
url: String
|
|
26
|
+
}],
|
|
27
|
+
// ❌ REMOVED: totalReserved, flashSaleReservations
|
|
20
28
|
lowStockThreshold: {
|
|
21
29
|
type: Number,
|
|
22
30
|
default: 10
|
|
@@ -32,107 +40,66 @@ const stockSchema = new mongoose.Schema(
|
|
|
32
40
|
lastRestocked: {
|
|
33
41
|
type: Date,
|
|
34
42
|
default: null
|
|
35
|
-
}
|
|
43
|
+
},
|
|
44
|
+
stockUpdateHistory: [{
|
|
45
|
+
change: Number,
|
|
46
|
+
previousQuantity: Number,
|
|
47
|
+
newQuantity: Number,
|
|
48
|
+
reason: String,
|
|
49
|
+
updatedAt: { type: Date, default: Date.now }
|
|
50
|
+
}]
|
|
36
51
|
},
|
|
37
52
|
{ timestamps: true }
|
|
38
53
|
);
|
|
39
54
|
|
|
40
|
-
// Indexes
|
|
41
|
-
stockSchema.index({ productListingId: 1 });
|
|
42
|
-
stockSchema.index({ isInStock: 1 });
|
|
43
|
-
stockSchema.index({ quantity: 1 });
|
|
44
|
-
|
|
45
55
|
const Stock = mongoose.models.stocks || mongoose.model("stocks", stockSchema);
|
|
46
56
|
export default Stock;
|
|
47
57
|
|
|
48
58
|
|
|
49
|
-
|
|
50
|
-
// // models/Stock.js
|
|
59
|
+
// // models/Stock.js - Simplified version without flash sale reservations
|
|
51
60
|
// import mongoose from "mongoose";
|
|
52
61
|
// const { Schema } = mongoose;
|
|
53
62
|
|
|
54
|
-
//
|
|
55
|
-
// const StockUpdateHistorySchema = new Schema({
|
|
56
|
-
// change: { type: Number, required: true }, // e.g., +50 or -10
|
|
57
|
-
// previousQuantity: { type: Number, required: true },
|
|
58
|
-
// newQuantity: { type: Number, required: true },
|
|
59
|
-
// reason: { type: String, default: "Manual update by seller" },
|
|
60
|
-
// updatedAt: { type: Date, default: Date.now }
|
|
61
|
-
// });
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
// const StockSchema = new Schema(
|
|
63
|
+
// const stockSchema = new mongoose.Schema(
|
|
65
64
|
// {
|
|
66
|
-
// sellerId: {
|
|
67
|
-
// type: Schema.Types.ObjectId,
|
|
68
|
-
// ref: "sellers",
|
|
69
|
-
// },
|
|
70
65
|
// productListingId: {
|
|
71
66
|
// type: Schema.Types.ObjectId,
|
|
72
67
|
// ref: "productlistings",
|
|
68
|
+
// required: true,
|
|
69
|
+
// unique: true
|
|
73
70
|
// },
|
|
74
|
-
// title: String,
|
|
75
|
-
// images: [{
|
|
76
|
-
// key: String,
|
|
77
|
-
// url: String
|
|
78
|
-
// }],
|
|
79
71
|
// quantity: {
|
|
80
72
|
// type: Number,
|
|
81
|
-
// min: 0,
|
|
82
73
|
// default: 0,
|
|
74
|
+
// min: 0
|
|
83
75
|
// },
|
|
84
|
-
// //
|
|
85
|
-
//
|
|
86
|
-
|
|
87
|
-
//
|
|
88
|
-
//
|
|
89
|
-
//
|
|
90
|
-
//
|
|
91
|
-
// ref: "FlashSale",
|
|
92
|
-
// required: true
|
|
93
|
-
// },
|
|
94
|
-
// quantity: { type: Number, min: 0, default: 0 },
|
|
95
|
-
// status: {
|
|
96
|
-
// type: String,
|
|
97
|
-
// enum: ['reserved', 'active', 'released', 'sold', 'partially_sold'],
|
|
98
|
-
// default: 'reserved'
|
|
99
|
-
// },
|
|
100
|
-
// source: {
|
|
101
|
-
// type: String,
|
|
102
|
-
// enum: ['normal', 'live_stream'],
|
|
103
|
-
// default: 'normal'
|
|
104
|
-
// },
|
|
105
|
-
// reservedAt: { type: Date, default: Date.now },
|
|
106
|
-
// releasedAt: Date,
|
|
107
|
-
// soldQuantity: { type: Number, default: 0 }
|
|
108
|
-
// }],
|
|
109
|
-
// totalReserved: {
|
|
76
|
+
// // REMOVED: totalReserved field since we don't need reservations
|
|
77
|
+
// // REMOVED: flashSaleReservations array completely
|
|
78
|
+
// lowStockThreshold: {
|
|
79
|
+
// type: Number,
|
|
80
|
+
// default: 10
|
|
81
|
+
// },
|
|
82
|
+
// reorderQuantity: {
|
|
110
83
|
// type: Number,
|
|
111
|
-
//
|
|
112
|
-
//
|
|
84
|
+
// default: 50
|
|
85
|
+
// },
|
|
86
|
+
// isInStock: {
|
|
87
|
+
// type: Boolean,
|
|
88
|
+
// default: true
|
|
89
|
+
// },
|
|
90
|
+
// lastRestocked: {
|
|
91
|
+
// type: Date,
|
|
92
|
+
// default: null
|
|
113
93
|
// }
|
|
114
94
|
// },
|
|
115
95
|
// { timestamps: true }
|
|
116
96
|
// );
|
|
117
97
|
|
|
118
|
-
// //
|
|
119
|
-
//
|
|
120
|
-
//
|
|
121
|
-
//
|
|
122
|
-
// return total + (['reserved', 'active'].includes(reservation.status) ? reservation.quantity : 0);
|
|
123
|
-
// }, 0);
|
|
124
|
-
// }
|
|
125
|
-
// next();
|
|
126
|
-
// });
|
|
127
|
-
|
|
128
|
-
// // Virtual for available quantity
|
|
129
|
-
// StockSchema.virtual('availableQuantity').get(function() {
|
|
130
|
-
// return Math.max(0, this.quantity - this.totalReserved);
|
|
131
|
-
// });
|
|
98
|
+
// // Indexes
|
|
99
|
+
// stockSchema.index({ productListingId: 1 });
|
|
100
|
+
// stockSchema.index({ isInStock: 1 });
|
|
101
|
+
// stockSchema.index({ quantity: 1 });
|
|
132
102
|
|
|
133
|
-
//
|
|
134
|
-
//
|
|
135
|
-
// StockSchema.set('toObject', { virtuals: true });
|
|
103
|
+
// const Stock = mongoose.models.stocks || mongoose.model("stocks", stockSchema);
|
|
104
|
+
// export default Stock;
|
|
136
105
|
|
|
137
|
-
// const Stock = mongoose.models.stocks || mongoose.model("stocks", StockSchema);
|
|
138
|
-
// export default Stock;
|