flykup_model_development 2.0.4 → 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.
Files changed (2) hide show
  1. package/models/stock.model.js +115 -116
  2. package/package.json +1 -1
@@ -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
- // sellerId: {
51
- // type: Schema.Types.ObjectId,
52
- // ref: "sellers",
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
- // productListingId: {
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
- // // Update totalReserved when flashSaleReservations change
107
- // StockSchema.pre('save', function(next) {
108
- // if (this.isModified('flashSaleReservations')) {
109
- // this.totalReserved = this.flashSaleReservations.reduce((total, reservation) => {
110
- // return total + (reservation.status === 'reserved' || reservation.status === 'active' ? reservation.quantity : 0);
111
- // }, 0);
112
- // }
113
- // next();
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
- // // Virtual for available quantity (total - reserved)
117
- // StockSchema.virtual('availableQuantity').get(function() {
118
- // return Math.max(0, this.quantity - this.totalReserved);
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
- // // Ensure virtuals are included in toJSON output
122
- // StockSchema.set('toJSON', { virtuals: true });
123
- // StockSchema.set('toObject', { virtuals: true });
120
+ // Ensure virtuals are included in toJSON output
121
+ StockSchema.set('toJSON', { virtuals: true });
122
+ StockSchema.set('toObject', { virtuals: true });
124
123
 
125
- // const Stock = mongoose.models.stocks || mongoose.model("stocks", StockSchema);
126
- // export default Stock;
124
+ const Stock = mongoose.models.stocks || mongoose.model("stocks", StockSchema);
125
+ export default Stock;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flykup_model_development",
3
- "version": "2.0.4",
3
+ "version": "2.0.5",
4
4
  "main": "index.js",
5
5
  "type": "module",
6
6
  "private": false,