flykup_model_development 3.0.9 → 3.1.1

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.
@@ -291,9 +291,7 @@ payment: {
291
291
  );
292
292
 
293
293
 
294
- const Order = mongoose.model('Order', orderSchema);
295
- export default Order;
296
294
 
297
295
 
298
- // const Order = mongoose.models.Order || mongoose.model('Order', orderSchema);
299
- // export default Order;
296
+ const Order = mongoose.models.Order || mongoose.model('Order', orderSchema);
297
+ export default Order;
@@ -59,7 +59,6 @@
59
59
  // const OrderPayment = mongoose.model('orderPayment', paymentSchema);
60
60
  // export default OrderPayment;
61
61
 
62
-
63
62
  // models/OrderPayment.js
64
63
  import mongoose from 'mongoose';
65
64
 
@@ -134,12 +133,35 @@ const paymentSchema = new mongoose.Schema({
134
133
  default: 'PENDING'
135
134
  }
136
135
  }]
137
- }, { timestamps: true });
136
+ }, {
137
+ timestamps: true,
138
+ // Add this to ensure conditional validation works properly
139
+ validateBeforeSave: true
140
+ });
138
141
 
139
142
  // Create indexes for better performance
140
143
  paymentSchema.index({ razorpayOrderId: 1 });
141
144
  paymentSchema.index({ cfOrderId: 1 });
142
145
  paymentSchema.index({ orderId: 1 });
143
146
 
144
- const OrderPayment = mongoose.model('orderPayment', paymentSchema);
145
- export default OrderPayment;
147
+ // Add a pre-save middleware to handle conditional validation
148
+ paymentSchema.pre('save', function(next) {
149
+ // If using Razorpay, remove Cashfree fields
150
+ if (this.paymentGateway === 'RAZORPAY') {
151
+ this.cfPaymentSessionId = undefined;
152
+ this.cfOrderId = undefined;
153
+ }
154
+ // If using Cashfree, remove Razorpay fields
155
+ else if (this.paymentGateway === 'CASHFREE') {
156
+ this.razorpayOrderId = undefined;
157
+ this.razorpayPaymentId = undefined;
158
+ }
159
+ next();
160
+ });
161
+
162
+
163
+
164
+ const OrderPayment =
165
+ mongoose.models.OrderPayment || mongoose.model('OrderPayment', paymentSchema);
166
+
167
+ export default OrderPayment;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flykup_model_development",
3
- "version": "3.0.9",
3
+ "version": "3.1.1",
4
4
  "main": "index.js",
5
5
  "type": "module",
6
6
  "private": false,