goldstars-services 1.0.69 → 1.0.70
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.
|
@@ -11,7 +11,8 @@ var reservationSchema = new _mongoose.default.Schema({
|
|
|
11
11
|
type: _mongoose.default.Schema.Types.ObjectId,
|
|
12
12
|
ref: 'User',
|
|
13
13
|
// Assuming your user model is named 'User'
|
|
14
|
-
|
|
14
|
+
// Ahora opcional para permitir reservas administrativas sin usuario asignado
|
|
15
|
+
required: false
|
|
15
16
|
},
|
|
16
17
|
bikeId: {
|
|
17
18
|
type: _mongoose.default.Schema.Types.ObjectId,
|
|
@@ -66,28 +66,31 @@ var createReservation = /*#__PURE__*/function () {
|
|
|
66
66
|
|
|
67
67
|
// --- BEGIN NEW VALIDATIONS ---
|
|
68
68
|
|
|
69
|
-
// 1.
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
69
|
+
// 1. Validaciones por usuario solo aplican cuando hay usuario asociado
|
|
70
|
+
if (userId) {
|
|
71
|
+
// 1.a Check if user already has a reservation for this EXACT timestamp
|
|
72
|
+
var existingReservationSameSlot = yield _reservationModel.default.findOne({
|
|
73
|
+
userId,
|
|
74
|
+
timestamp: reservationTimestamp
|
|
75
|
+
});
|
|
76
|
+
if (existingReservationSameSlot) {
|
|
77
|
+
throw new Error('Ya tienes una reserva agendada para esta fecha y hora.');
|
|
78
|
+
}
|
|
77
79
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
80
|
+
// 1.b Check if user already has an UPCOMING reservation
|
|
81
|
+
var now = new Date();
|
|
82
|
+
var existingUpcomingReservation = yield _reservationModel.default.findOne({
|
|
83
|
+
userId,
|
|
84
|
+
timestamp: {
|
|
85
|
+
$gte: now
|
|
86
|
+
} // Find reservations where the timestamp is now or in the future
|
|
87
|
+
});
|
|
88
|
+
if (existingUpcomingReservation) {
|
|
89
|
+
// Optional: Provide more details about the existing reservation if needed
|
|
90
|
+
// const existingTime = existingUpcomingReservation.timestamp.toLocaleString('es-VE');
|
|
91
|
+
// throw new Error(`Ya tienes una reserva activa para ${existingTime}. Debes esperar a que pase para agendar otra.`);
|
|
92
|
+
throw new Error('Ya tienes una reserva activa. Debes esperar a que pase para agendar otra.');
|
|
93
|
+
}
|
|
91
94
|
}
|
|
92
95
|
|
|
93
96
|
// --- END NEW VALIDATIONS ---
|