flykup_model_development 3.1.0 → 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.
@@ -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,13 +133,34 @@ 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
 
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
+
144
164
  const OrderPayment =
145
165
  mongoose.models.OrderPayment || mongoose.model('OrderPayment', paymentSchema);
146
166
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flykup_model_development",
3
- "version": "3.1.0",
3
+ "version": "3.1.1",
4
4
  "main": "index.js",
5
5
  "type": "module",
6
6
  "private": false,