flykup_model_development 3.1.1 → 3.1.3
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/orderPayment.model.js +10 -26
- package/package.json +1 -1
|
@@ -58,8 +58,6 @@
|
|
|
58
58
|
|
|
59
59
|
// const OrderPayment = mongoose.model('orderPayment', paymentSchema);
|
|
60
60
|
// export default OrderPayment;
|
|
61
|
-
|
|
62
|
-
// models/OrderPayment.js
|
|
63
61
|
import mongoose from 'mongoose';
|
|
64
62
|
|
|
65
63
|
const paymentSchema = new mongoose.Schema({
|
|
@@ -78,10 +76,11 @@ const paymentSchema = new mongoose.Schema({
|
|
|
78
76
|
enum: ['RAZORPAY', 'CASHFREE'],
|
|
79
77
|
required: true
|
|
80
78
|
},
|
|
81
|
-
|
|
79
|
+
|
|
82
80
|
// Razorpay-specific fields
|
|
83
81
|
razorpayOrderId: {
|
|
84
82
|
type: String,
|
|
83
|
+
// ✅ This field is now required only if the gateway is RAZORPAY
|
|
85
84
|
required: function() {
|
|
86
85
|
return this.paymentGateway === 'RAZORPAY';
|
|
87
86
|
}
|
|
@@ -90,16 +89,18 @@ const paymentSchema = new mongoose.Schema({
|
|
|
90
89
|
type: String,
|
|
91
90
|
default: null
|
|
92
91
|
},
|
|
93
|
-
|
|
92
|
+
|
|
94
93
|
// Cashfree-specific fields
|
|
95
94
|
cfPaymentSessionId: {
|
|
96
95
|
type: String,
|
|
96
|
+
// ✅ This field is now required only if the gateway is CASHFREE
|
|
97
97
|
required: function() {
|
|
98
98
|
return this.paymentGateway === 'CASHFREE';
|
|
99
99
|
}
|
|
100
100
|
},
|
|
101
101
|
cfOrderId: {
|
|
102
102
|
type: String,
|
|
103
|
+
// ✅ This field is now required only if the gateway is CASHFREE
|
|
103
104
|
required: function() {
|
|
104
105
|
return this.paymentGateway === 'CASHFREE';
|
|
105
106
|
}
|
|
@@ -133,10 +134,8 @@ const paymentSchema = new mongoose.Schema({
|
|
|
133
134
|
default: 'PENDING'
|
|
134
135
|
}
|
|
135
136
|
}]
|
|
136
|
-
}, {
|
|
137
|
-
timestamps: true
|
|
138
|
-
// Add this to ensure conditional validation works properly
|
|
139
|
-
validateBeforeSave: true
|
|
137
|
+
}, {
|
|
138
|
+
timestamps: true
|
|
140
139
|
});
|
|
141
140
|
|
|
142
141
|
// Create indexes for better performance
|
|
@@ -144,24 +143,9 @@ paymentSchema.index({ razorpayOrderId: 1 });
|
|
|
144
143
|
paymentSchema.index({ cfOrderId: 1 });
|
|
145
144
|
paymentSchema.index({ orderId: 1 });
|
|
146
145
|
|
|
147
|
-
//
|
|
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
|
-
|
|
146
|
+
// ❌ The pre-save middleware is no longer needed and should be removed.
|
|
163
147
|
|
|
164
148
|
const OrderPayment =
|
|
165
|
-
mongoose.models.OrderPayment || mongoose.model('
|
|
149
|
+
mongoose.models.OrderPayment || mongoose.model('orderPayment', paymentSchema);
|
|
166
150
|
|
|
167
|
-
export default OrderPayment;
|
|
151
|
+
export default OrderPayment;
|