goldstars-services 1.0.48 → 1.0.50
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.
|
@@ -24,13 +24,6 @@ var reservationSchema = new _mongoose.default.Schema({
|
|
|
24
24
|
// Store the specific date of the reservation
|
|
25
25
|
required: true
|
|
26
26
|
},
|
|
27
|
-
timeSlot: {
|
|
28
|
-
type: String,
|
|
29
|
-
// e.g., "7am", "5pm", "9:15am"
|
|
30
|
-
required: true
|
|
31
|
-
// Consider adding an enum later for validation if needed
|
|
32
|
-
// enum: ['7am', '8am', '9:15am', '5pm', '7pm']
|
|
33
|
-
},
|
|
34
27
|
location: {
|
|
35
28
|
type: String,
|
|
36
29
|
// e.g., "Sambil", "Las Virtudes"
|
|
@@ -17,49 +17,57 @@ function _asyncToGenerator(n) { return function () { var t = this, e = arguments
|
|
|
17
17
|
// Needed to check bike status/location
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
|
-
* Checks if a bike is already reserved for a specific
|
|
20
|
+
* Checks if a bike is already reserved for a specific timestamp.
|
|
21
21
|
* @param {string} bikeId - The ID of the bike.
|
|
22
|
-
* @param {Date}
|
|
23
|
-
* @param {string} timeSlot - The reservation time slot.
|
|
22
|
+
* @param {Date} timestamp - The reservation timestamp (UTC Date object).
|
|
24
23
|
* @returns {Promise<boolean>} - True if the bike is already reserved, false otherwise.
|
|
25
24
|
*/
|
|
26
25
|
var isBikeReserved = /*#__PURE__*/function () {
|
|
27
|
-
var _ref = _asyncToGenerator(function* (bikeId,
|
|
26
|
+
var _ref = _asyncToGenerator(function* (bikeId, timestamp) {
|
|
27
|
+
// Ensure timestamp is treated as a Date object if it comes as a string
|
|
28
|
+
var searchTimestamp = new Date(timestamp);
|
|
29
|
+
if (isNaN(searchTimestamp.getTime())) {
|
|
30
|
+
throw new Error('Timestamp inválido proporcionado a isBikeReserved.');
|
|
31
|
+
}
|
|
28
32
|
var existingReservation = yield _reservationModel.default.findOne({
|
|
29
33
|
bikeId,
|
|
30
|
-
|
|
31
|
-
timeSlot
|
|
34
|
+
timestamp: searchTimestamp // Use the timestamp directly
|
|
32
35
|
// Optional: Add status check if cancelled reservations should allow re-booking
|
|
33
36
|
// status: 'confirmed',
|
|
34
37
|
});
|
|
35
38
|
return !!existingReservation;
|
|
36
39
|
});
|
|
37
|
-
return function isBikeReserved(_x, _x2
|
|
40
|
+
return function isBikeReserved(_x, _x2) {
|
|
38
41
|
return _ref.apply(this, arguments);
|
|
39
42
|
};
|
|
40
43
|
}();
|
|
41
44
|
|
|
42
45
|
/**
|
|
43
|
-
* Creates a new reservation.
|
|
46
|
+
* Creates a new reservation using a timestamp.
|
|
44
47
|
* @param {object} reservationData - Data for the new reservation.
|
|
45
48
|
* @param {string} reservationData.userId - User ID.
|
|
46
49
|
* @param {string} reservationData.bikeId - Bike ID.
|
|
47
|
-
* @param {Date} reservationData.
|
|
48
|
-
* @param {string} reservationData.timeSlot - Reservation time slot.
|
|
50
|
+
* @param {Date|string} reservationData.timestamp - Reservation timestamp (UTC Date object or valid date string).
|
|
49
51
|
* @param {string} reservationData.location - Reservation location.
|
|
50
52
|
* @returns {Promise<object>} - The created reservation document.
|
|
51
|
-
* @throws {Error} - If bike not found, is instructor bike, or already reserved.
|
|
53
|
+
* @throws {Error} - If bike not found, is instructor bike, timestamp invalid, or already reserved.
|
|
52
54
|
*/
|
|
53
55
|
var createReservation = /*#__PURE__*/function () {
|
|
54
56
|
var _ref2 = _asyncToGenerator(function* (reservationData) {
|
|
57
|
+
// Destructure timestamp, remove date and timeSlot
|
|
55
58
|
var {
|
|
56
59
|
userId,
|
|
57
60
|
bikeId,
|
|
58
|
-
|
|
59
|
-
timeSlot,
|
|
61
|
+
timestamp,
|
|
60
62
|
location
|
|
61
63
|
} = reservationData;
|
|
62
64
|
|
|
65
|
+
// Validate timestamp
|
|
66
|
+
var reservationTimestamp = new Date(timestamp);
|
|
67
|
+
if (isNaN(reservationTimestamp.getTime())) {
|
|
68
|
+
throw new Error('Timestamp inválido proporcionado para la reserva.');
|
|
69
|
+
}
|
|
70
|
+
|
|
63
71
|
// 1. Validate Bike
|
|
64
72
|
var bike = yield _bikeModel.default.findById(bikeId);
|
|
65
73
|
if (!bike) {
|
|
@@ -68,29 +76,28 @@ var createReservation = /*#__PURE__*/function () {
|
|
|
68
76
|
if (bike.isInstructorBike) {
|
|
69
77
|
throw new Error('La bicicleta del instructor no se puede reservar.');
|
|
70
78
|
}
|
|
71
|
-
// Ensure the bike belongs to the specified location (optional but good practice)
|
|
72
79
|
if (bike.location !== location) {
|
|
73
80
|
throw new Error("La bicicleta ".concat(bike.name, " no pertenece a la ubicaci\xF3n ").concat(location, "."));
|
|
74
81
|
}
|
|
75
82
|
|
|
76
|
-
// 2. Check if already reserved
|
|
77
|
-
var alreadyReserved = yield isBikeReserved(bikeId,
|
|
83
|
+
// 2. Check if already reserved using timestamp
|
|
84
|
+
var alreadyReserved = yield isBikeReserved(bikeId, reservationTimestamp);
|
|
78
85
|
if (alreadyReserved) {
|
|
79
86
|
throw new Error('Esta bicicleta ya está reservada para esta fecha y hora.');
|
|
80
87
|
}
|
|
81
88
|
|
|
82
|
-
// 3. Create Reservation
|
|
89
|
+
// 3. Create Reservation using timestamp
|
|
83
90
|
var newReservation = new _reservationModel.default({
|
|
84
91
|
userId,
|
|
85
92
|
bikeId,
|
|
86
|
-
|
|
87
|
-
|
|
93
|
+
timestamp: reservationTimestamp,
|
|
94
|
+
// Use timestamp
|
|
88
95
|
location
|
|
89
96
|
});
|
|
90
97
|
yield newReservation.save();
|
|
91
98
|
return newReservation;
|
|
92
99
|
});
|
|
93
|
-
return function createReservation(
|
|
100
|
+
return function createReservation(_x3) {
|
|
94
101
|
return _ref2.apply(this, arguments);
|
|
95
102
|
};
|
|
96
103
|
}();
|
|
@@ -162,7 +169,7 @@ var getBikeAvailabilityForSlot = /*#__PURE__*/function () {
|
|
|
162
169
|
});
|
|
163
170
|
return bikesWithStatus;
|
|
164
171
|
});
|
|
165
|
-
return function getBikeAvailabilityForSlot(
|
|
172
|
+
return function getBikeAvailabilityForSlot(_x4, _x5) {
|
|
166
173
|
return _ref3.apply(this, arguments);
|
|
167
174
|
};
|
|
168
175
|
}();
|
|
@@ -202,7 +209,7 @@ var cancelReservation = /*#__PURE__*/function () {
|
|
|
202
209
|
message: 'Reserva cancelada exitosamente.'
|
|
203
210
|
};
|
|
204
211
|
});
|
|
205
|
-
return function cancelReservation(_x7, _x8
|
|
212
|
+
return function cancelReservation(_x6, _x7, _x8) {
|
|
206
213
|
return _ref4.apply(this, arguments);
|
|
207
214
|
};
|
|
208
215
|
}();
|
|
@@ -210,5 +217,5 @@ var _default = exports.default = {
|
|
|
210
217
|
getBikeAvailabilityForSlot,
|
|
211
218
|
createReservation,
|
|
212
219
|
cancelReservation,
|
|
213
|
-
isBikeReserved
|
|
220
|
+
isBikeReserved // Keep exporting isBikeReserved if used elsewhere, otherwise could be removed if only internal
|
|
214
221
|
};
|