flykup_model_development 2.0.4 → 2.0.6

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.
@@ -48,6 +48,17 @@ 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
+ flashSaleId: {
57
+ type: mongoose.Schema.Types.ObjectId,
58
+ ref: 'FlashSale'
59
+ },
60
+ flashPrice: {
61
+ type: Number
51
62
  }
52
63
  }],
53
64
  totalBaseAmount: {
@@ -166,9 +177,9 @@ const orderSchema = new mongoose.Schema(
166
177
  // default: 'ORDERED', // Default should be the initial state
167
178
  required: true
168
179
  },
169
- sourceType: {
180
+ sourceType: {
170
181
  type: String,
171
- enum: ['static', 'shoppable_video', 'livestream', 'auction'],
182
+ enum: ['static', 'shoppable_video', 'livestream', 'auction', 'flash_sale'], // Add flash_sale
172
183
  required: true
173
184
  },
174
185
  sourceRefId: String,
@@ -11,7 +11,7 @@ const ProductListingSchema = new Schema(
11
11
  images: [
12
12
  {
13
13
  key: { type: String, maxLength: 255, default: null },
14
- }
14
+ },
15
15
  ],
16
16
  category: String,
17
17
  subcategory: String,
@@ -44,11 +44,13 @@ const ProductListingSchema = new Schema(
44
44
  countryOfOrigin: String,
45
45
  netQuantity: { type: String, default: null }, // ADDED (String to accommodate units like '500g')
46
46
  packagingType: { type: String, default: null }, // ADDED
47
- weight: { // For shipping calculations
47
+ weight: {
48
+ // For shipping calculations
48
49
  value: { type: Number, default: null },
49
50
  unit: { type: String, default: null },
50
51
  },
51
- dimensions: { // For shipping calculations
52
+ dimensions: {
53
+ // For shipping calculations
52
54
  length: { type: Number, default: null },
53
55
  width: { type: Number, default: null },
54
56
  height: { type: Number, default: null },
@@ -80,9 +82,9 @@ const ProductListingSchema = new Schema(
80
82
  },
81
83
  commissionRate: {
82
84
  type: Number,
83
- min: [0, 'Commission rate cannot be negative.'],
85
+ min: [0, "Commission rate cannot be negative."],
84
86
  // max: [100, 'Commission rate cannot exceed 100%.'], // Max was 25, changed to 100 based on frontend
85
- max: [100, 'Commission rate cannot exceed 100%.'],
87
+ max: [100, "Commission rate cannot exceed 100%."],
86
88
  default: null,
87
89
  // Removed Mongoose-level required validation dependent on allowDropshipping
88
90
  // Let application logic handle this if needed, or adjust validator
@@ -93,33 +95,43 @@ const ProductListingSchema = new Schema(
93
95
  // validate: { ... } // Keep or remove validation as needed
94
96
  },
95
97
  hasReturn: {
96
- type: Boolean,
97
- default: false
98
- },
99
- returnDays: {
100
- type: Number,
101
- min: 0,
102
- default: null
103
- },
104
- size: {
105
- type: String,
106
- default: null
107
- },
98
+ type: Boolean,
99
+ default: false,
100
+ },
101
+ returnDays: {
102
+ type: Number,
103
+ min: 0,
104
+ default: null,
105
+ },
106
+ size: {
107
+ type: String,
108
+ default: null,
109
+ },
108
110
  isActive: {
109
111
  type: Boolean,
110
112
  default: true,
111
- },ratingSummary: {
112
- averageRating: { type: Number, default: 0 },
113
- totalRatings: { type: Number, default: 0 },
114
- ratingDistribution: {
113
+ },
114
+ ratingSummary: {
115
+ averageRating: { type: Number, default: 0 },
116
+ totalRatings: { type: Number, default: 0 },
117
+ ratingDistribution: {
115
118
  1: { type: Number, default: 0 },
116
119
  2: { type: Number, default: 0 },
117
120
  3: { type: Number, default: 0 },
118
121
  4: { type: Number, default: 0 },
119
- 5: { type: Number, default: 0 }
120
- }
121
- },
122
- totalReviews: { type: Number, default: 0 }
122
+ 5: { type: Number, default: 0 },
123
+ },
124
+ },
125
+ flashSale: {
126
+ isActive: { type: Boolean, default: false },
127
+ flashSaleId: { type: mongoose.Schema.Types.ObjectId, ref: 'FlashSale' },
128
+ flashPrice: { type: Number, default: null },
129
+ flashStock: { type: Number, default: 0 },
130
+ originalPrice: { type: Number, default: null },
131
+ endsAt: { type: Date, default: null },
132
+ startsAt: { type: Date, default: null }
133
+ },
134
+ totalReviews: { type: Number, default: 0 },
123
135
  },
124
136
  { timestamps: true }
125
137
  );
@@ -128,5 +140,7 @@ totalReviews: { type: Number, default: 0 }
128
140
  // ProductListingSchema.set('strict', false); // Use with caution
129
141
 
130
142
  // Safe export to prevent OverwriteModelError
131
- const ProductListing = mongoose.models.productlistings || mongoose.model("productlistings", ProductListingSchema);
143
+ const ProductListing =
144
+ mongoose.models.productlistings ||
145
+ mongoose.model("productlistings", ProductListingSchema);
132
146
  export default ProductListing;
@@ -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.6",
4
4
  "main": "index.js",
5
5
  "type": "module",
6
6
  "private": false,