flykup_model_development 2.0.3 → 2.0.5
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/shoppableVideo.model.js +6 -1
- package/models/stock.model.js +115 -116
- package/package.json +1 -1
|
@@ -34,14 +34,19 @@ const ShoppableVideoSchema = new Schema(
|
|
|
34
34
|
},
|
|
35
35
|
description: {
|
|
36
36
|
type: String,
|
|
37
|
-
required:
|
|
37
|
+
required: false,
|
|
38
38
|
trim: true,
|
|
39
39
|
},
|
|
40
40
|
category: { type: String, required: true, trim: true },
|
|
41
41
|
subcategory: { type: String, required: true, trim: true },
|
|
42
42
|
// thumbnailURL might be set initially or updated by the processing service
|
|
43
|
+
isThumbnailEnabled: {
|
|
44
|
+
type: Boolean,
|
|
45
|
+
default: false, // toggle OFF by default
|
|
46
|
+
},
|
|
43
47
|
thumbnailURL: {
|
|
44
48
|
type: String,
|
|
49
|
+
default: null
|
|
45
50
|
},
|
|
46
51
|
isProductsAvailable : { type : Boolean, required : true, default : true },
|
|
47
52
|
productsListed: {
|
package/models/stock.model.js
CHANGED
|
@@ -1,126 +1,125 @@
|
|
|
1
|
-
import mongoose from "mongoose";
|
|
2
|
-
const { Schema, model } = mongoose;
|
|
3
|
-
|
|
4
|
-
const StockSchema = new Schema(
|
|
5
|
-
{
|
|
6
|
-
sellerId: {
|
|
7
|
-
type: Schema.Types.ObjectId,
|
|
8
|
-
ref: "sellers",
|
|
9
|
-
},
|
|
10
|
-
productListingId: {
|
|
11
|
-
type: Schema.Types.ObjectId,
|
|
12
|
-
ref: "productlistings",
|
|
13
|
-
},
|
|
14
|
-
title: String,
|
|
15
|
-
quantity: {
|
|
16
|
-
type: Number,
|
|
17
|
-
min: 0,
|
|
18
|
-
default: null,
|
|
19
|
-
},
|
|
20
|
-
images: [
|
|
21
|
-
{
|
|
22
|
-
key: { type: String, maxLength: 255, default: null },
|
|
23
|
-
blobName: { type: String, maxLength: 255, default: null },
|
|
24
|
-
azureUrl: { type: String, maxLength: 1024, default: null },
|
|
25
|
-
},
|
|
26
|
-
],
|
|
27
|
-
mfgDate: {
|
|
28
|
-
type: String,
|
|
29
|
-
default: null,
|
|
30
|
-
},
|
|
31
|
-
expDate: {
|
|
32
|
-
type: String,
|
|
33
|
-
default: null,
|
|
34
|
-
},
|
|
35
|
-
},
|
|
36
|
-
{ timestamps: true }
|
|
37
|
-
);
|
|
38
|
-
|
|
39
|
-
const Stock = mongoose.models.stocks || mongoose.model("stocks", StockSchema);
|
|
40
|
-
export default Stock;
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
// models/Stock.js
|
|
44
|
-
// // models/Stock.js
|
|
45
1
|
// import mongoose from "mongoose";
|
|
46
2
|
// const { Schema, model } = mongoose;
|
|
47
3
|
|
|
48
4
|
// const StockSchema = new Schema(
|
|
49
|
-
//
|
|
50
|
-
//
|
|
51
|
-
//
|
|
52
|
-
//
|
|
5
|
+
// {
|
|
6
|
+
// sellerId: {
|
|
7
|
+
// type: Schema.Types.ObjectId,
|
|
8
|
+
// ref: "sellers",
|
|
9
|
+
// },
|
|
10
|
+
// productListingId: {
|
|
11
|
+
// type: Schema.Types.ObjectId,
|
|
12
|
+
// ref: "productlistings",
|
|
13
|
+
// },
|
|
14
|
+
// title: String,
|
|
15
|
+
// quantity: {
|
|
16
|
+
// type: Number,
|
|
17
|
+
// min: 0,
|
|
18
|
+
// default: null,
|
|
19
|
+
// },
|
|
20
|
+
// images: [
|
|
21
|
+
// {
|
|
22
|
+
// key: { type: String, maxLength: 255, default: null },
|
|
23
|
+
// blobName: { type: String, maxLength: 255, default: null },
|
|
24
|
+
// azureUrl: { type: String, maxLength: 1024, default: null },
|
|
25
|
+
// },
|
|
26
|
+
// ],
|
|
27
|
+
// mfgDate: {
|
|
28
|
+
// type: String,
|
|
29
|
+
// default: null,
|
|
30
|
+
// },
|
|
31
|
+
// expDate: {
|
|
32
|
+
// type: String,
|
|
33
|
+
// default: null,
|
|
34
|
+
// },
|
|
53
35
|
// },
|
|
54
|
-
//
|
|
55
|
-
// type: Schema.Types.ObjectId,
|
|
56
|
-
// ref: "productlistings",
|
|
57
|
-
// },
|
|
58
|
-
// title: String,
|
|
59
|
-
// quantity: {
|
|
60
|
-
// type: Number,
|
|
61
|
-
// min: 0,
|
|
62
|
-
// default: 0,
|
|
63
|
-
// },
|
|
64
|
-
// // Track reservations for current and upcoming flash sales
|
|
65
|
-
// flashSaleReservations: [{
|
|
66
|
-
// flashSaleId: {
|
|
67
|
-
// type: Schema.Types.ObjectId,
|
|
68
|
-
// ref: "FlashSale",
|
|
69
|
-
// required: true
|
|
70
|
-
// },
|
|
71
|
-
// productId: {
|
|
72
|
-
// type: Schema.Types.ObjectId,
|
|
73
|
-
// ref: "productlistings",
|
|
74
|
-
// required: true
|
|
75
|
-
// },
|
|
76
|
-
// quantity: {
|
|
77
|
-
// type: Number,
|
|
78
|
-
// min: 0,
|
|
79
|
-
// default: 0
|
|
80
|
-
// },
|
|
81
|
-
// status: {
|
|
82
|
-
// type: String,
|
|
83
|
-
// enum: ['reserved', 'active', 'released', 'sold', 'partially_sold'],
|
|
84
|
-
// default: 'reserved'
|
|
85
|
-
// },
|
|
86
|
-
// reservedAt: {
|
|
87
|
-
// type: Date,
|
|
88
|
-
// default: Date.now
|
|
89
|
-
// },
|
|
90
|
-
// releasedAt: Date,
|
|
91
|
-
// soldQuantity: {
|
|
92
|
-
// type: Number,
|
|
93
|
-
// default: 0
|
|
94
|
-
// }
|
|
95
|
-
// }],
|
|
96
|
-
// // Total reserved quantity (calculated field)
|
|
97
|
-
// totalReserved: {
|
|
98
|
-
// type: Number,
|
|
99
|
-
// min: 0,
|
|
100
|
-
// default: 0
|
|
101
|
-
// }
|
|
102
|
-
// },
|
|
103
|
-
// { timestamps: true }
|
|
36
|
+
// { timestamps: true }
|
|
104
37
|
// );
|
|
105
38
|
|
|
106
|
-
//
|
|
107
|
-
//
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
//
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
39
|
+
// const Stock = mongoose.models.stocks || mongoose.model("stocks", StockSchema);
|
|
40
|
+
// export default Stock;
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
// models/Stock.js
|
|
44
|
+
import mongoose from "mongoose";
|
|
45
|
+
const { Schema, model } = mongoose;
|
|
46
|
+
|
|
47
|
+
const StockSchema = new Schema(
|
|
48
|
+
{
|
|
49
|
+
sellerId: {
|
|
50
|
+
type: Schema.Types.ObjectId,
|
|
51
|
+
ref: "sellers",
|
|
52
|
+
},
|
|
53
|
+
productListingId: {
|
|
54
|
+
type: Schema.Types.ObjectId,
|
|
55
|
+
ref: "productlistings",
|
|
56
|
+
},
|
|
57
|
+
title: String,
|
|
58
|
+
quantity: {
|
|
59
|
+
type: Number,
|
|
60
|
+
min: 0,
|
|
61
|
+
default: 0,
|
|
62
|
+
},
|
|
63
|
+
// Track reservations for current and upcoming flash sales
|
|
64
|
+
flashSaleReservations: [{
|
|
65
|
+
flashSaleId: {
|
|
66
|
+
type: Schema.Types.ObjectId,
|
|
67
|
+
ref: "FlashSale",
|
|
68
|
+
required: true
|
|
69
|
+
},
|
|
70
|
+
productId: {
|
|
71
|
+
type: Schema.Types.ObjectId,
|
|
72
|
+
ref: "productlistings",
|
|
73
|
+
required: true
|
|
74
|
+
},
|
|
75
|
+
quantity: {
|
|
76
|
+
type: Number,
|
|
77
|
+
min: 0,
|
|
78
|
+
default: 0
|
|
79
|
+
},
|
|
80
|
+
status: {
|
|
81
|
+
type: String,
|
|
82
|
+
enum: ['reserved', 'active', 'released', 'sold', 'partially_sold'],
|
|
83
|
+
default: 'reserved'
|
|
84
|
+
},
|
|
85
|
+
reservedAt: {
|
|
86
|
+
type: Date,
|
|
87
|
+
default: Date.now
|
|
88
|
+
},
|
|
89
|
+
releasedAt: Date,
|
|
90
|
+
soldQuantity: {
|
|
91
|
+
type: Number,
|
|
92
|
+
default: 0
|
|
93
|
+
}
|
|
94
|
+
}],
|
|
95
|
+
// Total reserved quantity (calculated field)
|
|
96
|
+
totalReserved: {
|
|
97
|
+
type: Number,
|
|
98
|
+
min: 0,
|
|
99
|
+
default: 0
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
{ timestamps: true }
|
|
103
|
+
);
|
|
104
|
+
|
|
105
|
+
// Update totalReserved when flashSaleReservations change
|
|
106
|
+
StockSchema.pre('save', function(next) {
|
|
107
|
+
if (this.isModified('flashSaleReservations')) {
|
|
108
|
+
this.totalReserved = this.flashSaleReservations.reduce((total, reservation) => {
|
|
109
|
+
return total + (reservation.status === 'reserved' || reservation.status === 'active' ? reservation.quantity : 0);
|
|
110
|
+
}, 0);
|
|
111
|
+
}
|
|
112
|
+
next();
|
|
113
|
+
});
|
|
115
114
|
|
|
116
|
-
//
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
115
|
+
// Virtual for available quantity (total - reserved)
|
|
116
|
+
StockSchema.virtual('availableQuantity').get(function() {
|
|
117
|
+
return Math.max(0, this.quantity - this.totalReserved);
|
|
118
|
+
});
|
|
120
119
|
|
|
121
|
-
//
|
|
122
|
-
|
|
123
|
-
|
|
120
|
+
// Ensure virtuals are included in toJSON output
|
|
121
|
+
StockSchema.set('toJSON', { virtuals: true });
|
|
122
|
+
StockSchema.set('toObject', { virtuals: true });
|
|
124
123
|
|
|
125
|
-
|
|
126
|
-
|
|
124
|
+
const Stock = mongoose.models.stocks || mongoose.model("stocks", StockSchema);
|
|
125
|
+
export default Stock;
|