goldstars-services 1.0.50 → 1.0.52
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.
|
@@ -19,16 +19,16 @@ var reservationSchema = new _mongoose.default.Schema({
|
|
|
19
19
|
// Assuming your bike model is named 'Bike'
|
|
20
20
|
required: true
|
|
21
21
|
},
|
|
22
|
-
|
|
22
|
+
timestamp: {
|
|
23
|
+
// Changed from 'date' to 'timestamp'
|
|
23
24
|
type: Date,
|
|
24
|
-
// Store the specific
|
|
25
|
+
// Store the specific UTC datetime of the reservation
|
|
25
26
|
required: true
|
|
26
27
|
},
|
|
27
28
|
location: {
|
|
28
29
|
type: String,
|
|
29
30
|
// e.g., "Sambil", "Las Virtudes"
|
|
30
31
|
required: true,
|
|
31
|
-
// Consider adding an enum later for validation
|
|
32
32
|
enum: ['Sambil Paraguaná', 'C.C Las Virtudes']
|
|
33
33
|
}
|
|
34
34
|
// Optional: Add a status field if needed (e.g., 'confirmed', 'cancelled')
|
|
@@ -42,17 +42,17 @@ var reservationSchema = new _mongoose.default.Schema({
|
|
|
42
42
|
});
|
|
43
43
|
|
|
44
44
|
// Optional: Add indexes for faster querying based on common lookups
|
|
45
|
+
// Updated index to use 'timestamp'
|
|
45
46
|
reservationSchema.index({
|
|
46
47
|
bikeId: 1,
|
|
47
|
-
|
|
48
|
-
timeSlot: 1
|
|
48
|
+
timestamp: 1
|
|
49
49
|
}, {
|
|
50
50
|
unique: true
|
|
51
51
|
}); // Prevent double booking the same bike/slot
|
|
52
52
|
reservationSchema.index({
|
|
53
53
|
userId: 1,
|
|
54
|
-
|
|
55
|
-
}); // Quickly find user's reservations for a
|
|
54
|
+
timestamp: 1
|
|
55
|
+
}); // Quickly find user's reservations for a timestamp
|
|
56
56
|
|
|
57
57
|
var Reservation = _mongoose.default.model('Reservation', reservationSchema);
|
|
58
58
|
var _default = exports.default = Reservation;
|
|
@@ -24,14 +24,13 @@ function _asyncToGenerator(n) { return function () { var t = this, e = arguments
|
|
|
24
24
|
*/
|
|
25
25
|
var isBikeReserved = /*#__PURE__*/function () {
|
|
26
26
|
var _ref = _asyncToGenerator(function* (bikeId, timestamp) {
|
|
27
|
-
// Ensure timestamp is treated as a Date object if it comes as a string
|
|
28
27
|
var searchTimestamp = new Date(timestamp);
|
|
29
28
|
if (isNaN(searchTimestamp.getTime())) {
|
|
30
29
|
throw new Error('Timestamp inválido proporcionado a isBikeReserved.');
|
|
31
30
|
}
|
|
32
31
|
var existingReservation = yield _reservationModel.default.findOne({
|
|
33
32
|
bikeId,
|
|
34
|
-
timestamp: searchTimestamp //
|
|
33
|
+
timestamp: searchTimestamp // Search by 'timestamp' field
|
|
35
34
|
// Optional: Add status check if cancelled reservations should allow re-booking
|
|
36
35
|
// status: 'confirmed',
|
|
37
36
|
});
|
|
@@ -54,15 +53,12 @@ var isBikeReserved = /*#__PURE__*/function () {
|
|
|
54
53
|
*/
|
|
55
54
|
var createReservation = /*#__PURE__*/function () {
|
|
56
55
|
var _ref2 = _asyncToGenerator(function* (reservationData) {
|
|
57
|
-
// Destructure timestamp, remove date and timeSlot
|
|
58
56
|
var {
|
|
59
57
|
userId,
|
|
60
58
|
bikeId,
|
|
61
59
|
timestamp,
|
|
62
60
|
location
|
|
63
61
|
} = reservationData;
|
|
64
|
-
|
|
65
|
-
// Validate timestamp
|
|
66
62
|
var reservationTimestamp = new Date(timestamp);
|
|
67
63
|
if (isNaN(reservationTimestamp.getTime())) {
|
|
68
64
|
throw new Error('Timestamp inválido proporcionado para la reserva.');
|
|
@@ -91,7 +87,7 @@ var createReservation = /*#__PURE__*/function () {
|
|
|
91
87
|
userId,
|
|
92
88
|
bikeId,
|
|
93
89
|
timestamp: reservationTimestamp,
|
|
94
|
-
//
|
|
90
|
+
// Save to 'timestamp' field
|
|
95
91
|
location
|
|
96
92
|
});
|
|
97
93
|
yield newReservation.save();
|
|
@@ -103,23 +99,27 @@ var createReservation = /*#__PURE__*/function () {
|
|
|
103
99
|
}();
|
|
104
100
|
|
|
105
101
|
/**
|
|
106
|
-
* Gets the availability status of all bikes for a specific location and
|
|
107
|
-
* @param {string} location - The location ('Sambil' or 'Las Virtudes').
|
|
108
|
-
* @param {Date}
|
|
102
|
+
* Gets the availability status of all bikes for a specific location and timestamp.
|
|
103
|
+
* @param {string} location - The location ('Sambil Paraguaná' or 'C.C Las Virtudes').
|
|
104
|
+
* @param {Date|string} timestamp - The UTC timestamp to check (Date object or valid date string).
|
|
109
105
|
* @returns {Promise<Array<object>>} - An array of bike objects, each with an added 'reservationStatus' field.
|
|
110
106
|
*/
|
|
111
|
-
// Comentado el código existente para simplificar la función y probar la exportación
|
|
112
|
-
|
|
113
107
|
var getBikeAvailabilityForSlot = /*#__PURE__*/function () {
|
|
114
|
-
var _ref3 = _asyncToGenerator(function* (location,
|
|
108
|
+
var _ref3 = _asyncToGenerator(function* (location, timestamp) {
|
|
109
|
+
var checkTimestamp = new Date(timestamp);
|
|
110
|
+
if (isNaN(checkTimestamp.getTime())) {
|
|
111
|
+
throw new Error('Timestamp inválido proporcionado para obtener disponibilidad.');
|
|
112
|
+
}
|
|
113
|
+
|
|
115
114
|
// 1. Find all bikes for the given location
|
|
116
115
|
var bikesInLocation = yield _bikeModel.default.find({
|
|
117
116
|
location
|
|
118
117
|
}).lean(); // .lean() for plain JS objects
|
|
119
118
|
|
|
120
|
-
// 2. Find all reservations for the specific
|
|
119
|
+
// 2. Find all reservations for the specific timestamp and location
|
|
121
120
|
var reservations = yield _reservationModel.default.find({
|
|
122
|
-
|
|
121
|
+
timestamp: checkTimestamp,
|
|
122
|
+
// Search by 'timestamp' field
|
|
123
123
|
location // Filter by location as well for efficiency
|
|
124
124
|
// Optional: Add status filter if needed
|
|
125
125
|
// status: 'confirmed',
|