goldstars-services 1.0.44 → 1.0.48
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.
|
@@ -3,10 +3,15 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.default = void 0;
|
|
7
7
|
var _reservationModel = _interopRequireDefault(require("../models/reservation.model.js"));
|
|
8
8
|
var _bikeModel = _interopRequireDefault(require("../models/bike.model.js"));
|
|
9
9
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
10
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
11
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
12
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
13
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
14
|
+
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
10
15
|
function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
|
|
11
16
|
function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; } // MicroService/src/services/reservation.service.js
|
|
12
17
|
// Needed to check bike status/location
|
|
@@ -45,7 +50,7 @@ var isBikeReserved = /*#__PURE__*/function () {
|
|
|
45
50
|
* @returns {Promise<object>} - The created reservation document.
|
|
46
51
|
* @throws {Error} - If bike not found, is instructor bike, or already reserved.
|
|
47
52
|
*/
|
|
48
|
-
var createReservation =
|
|
53
|
+
var createReservation = /*#__PURE__*/function () {
|
|
49
54
|
var _ref2 = _asyncToGenerator(function* (reservationData) {
|
|
50
55
|
var {
|
|
51
56
|
userId,
|
|
@@ -97,70 +102,76 @@ var createReservation = exports.createReservation = /*#__PURE__*/function () {
|
|
|
97
102
|
* @returns {Promise<Array<object>>} - An array of bike objects, each with an added 'reservationStatus' field.
|
|
98
103
|
*/
|
|
99
104
|
// Comentado el código existente para simplificar la función y probar la exportación
|
|
100
|
-
/*
|
|
101
|
-
export const getBikeAvailabilityForSlot = async (location, date) => {
|
|
102
|
-
// 1. Find all bikes for the given location
|
|
103
|
-
const bikesInLocation = await Bike.find({ location }).lean(); // .lean() for plain JS objects
|
|
104
|
-
|
|
105
|
-
// 2. Find all reservations for the specific date
|
|
106
|
-
const reservations = await Reservation.find({
|
|
107
|
-
date,
|
|
108
|
-
location, // Filter by location as well for efficiency
|
|
109
|
-
// Optional: Add status filter if needed
|
|
110
|
-
// status: 'confirmed',
|
|
111
|
-
})
|
|
112
|
-
.populate('userId', 'name email') // Populate user name/email for admin view
|
|
113
|
-
.lean();
|
|
114
|
-
|
|
115
|
-
// 3. Create a map of reserved bike IDs for quick lookup
|
|
116
|
-
const reservedBikeMap = new Map();
|
|
117
|
-
reservations.forEach(res => {
|
|
118
|
-
// Store the user info (or just true if user info isn't needed/allowed)
|
|
119
|
-
reservedBikeMap.set(res.bikeId.toString(), res.userId); // Store populated user object
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
// 4. Combine bike data with reservation status
|
|
123
|
-
const bikesWithStatus = bikesInLocation.map(bike => {
|
|
124
|
-
const bikeIdStr = bike._id.toString();
|
|
125
|
-
const reservedByUser = reservedBikeMap.get(bikeIdStr);
|
|
126
|
-
let reservationStatus;
|
|
127
|
-
|
|
128
|
-
if (bike.isInstructorBike) {
|
|
129
|
-
reservationStatus = { status: 'instructor', reservedBy: null };
|
|
130
|
-
} else if (reservedByUser) {
|
|
131
|
-
// For admin: include user details. For regular user, this might be simplified later.
|
|
132
|
-
reservationStatus = { status: 'agendada', reservedBy: reservedByUser };
|
|
133
|
-
} else if (bike.status === 'Disponible') { // Check the bike's general status
|
|
134
|
-
reservationStatus = { status: 'disponible', reservedBy: null };
|
|
135
|
-
} else {
|
|
136
|
-
// If bike's general status is 'No Disponible' or something else
|
|
137
|
-
reservationStatus = { status: 'no_disponible_general', reservedBy: null };
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
return {
|
|
141
|
-
...bike, // Spread original bike data
|
|
142
|
-
reservationStatus, // Add the specific status for this slot
|
|
143
|
-
};
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
return bikesWithStatus;
|
|
147
|
-
};
|
|
148
|
-
*/
|
|
149
105
|
|
|
150
|
-
|
|
151
|
-
var getBikeAvailabilityForSlot = exports.getBikeAvailabilityForSlot = /*#__PURE__*/function () {
|
|
106
|
+
var getBikeAvailabilityForSlot = /*#__PURE__*/function () {
|
|
152
107
|
var _ref3 = _asyncToGenerator(function* (location, date) {
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
location
|
|
156
|
-
|
|
157
|
-
|
|
108
|
+
// 1. Find all bikes for the given location
|
|
109
|
+
var bikesInLocation = yield _bikeModel.default.find({
|
|
110
|
+
location
|
|
111
|
+
}).lean(); // .lean() for plain JS objects
|
|
112
|
+
|
|
113
|
+
// 2. Find all reservations for the specific date
|
|
114
|
+
var reservations = yield _reservationModel.default.find({
|
|
115
|
+
date,
|
|
116
|
+
location // Filter by location as well for efficiency
|
|
117
|
+
// Optional: Add status filter if needed
|
|
118
|
+
// status: 'confirmed',
|
|
119
|
+
}).populate('userId', 'name email') // Populate user name/email for admin view
|
|
120
|
+
.lean();
|
|
121
|
+
|
|
122
|
+
// 3. Create a map of reserved bike IDs for quick lookup
|
|
123
|
+
var reservedBikeMap = new Map();
|
|
124
|
+
reservations.forEach(res => {
|
|
125
|
+
// Store the user info (or just true if user info isn't needed/allowed)
|
|
126
|
+
reservedBikeMap.set(res.bikeId.toString(), res.userId); // Store populated user object
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
// 4. Combine bike data with reservation status
|
|
130
|
+
var bikesWithStatus = bikesInLocation.map(bike => {
|
|
131
|
+
var bikeIdStr = bike._id.toString();
|
|
132
|
+
var reservedByUser = reservedBikeMap.get(bikeIdStr);
|
|
133
|
+
var reservationStatus;
|
|
134
|
+
if (bike.isInstructorBike) {
|
|
135
|
+
reservationStatus = {
|
|
136
|
+
status: 'instructor',
|
|
137
|
+
reservedBy: null
|
|
138
|
+
};
|
|
139
|
+
} else if (reservedByUser) {
|
|
140
|
+
// For admin: include user details. For regular user, this might be simplified later.
|
|
141
|
+
reservationStatus = {
|
|
142
|
+
status: 'agendada',
|
|
143
|
+
reservedBy: reservedByUser
|
|
144
|
+
};
|
|
145
|
+
} else if (bike.status === 'Disponible') {
|
|
146
|
+
// Check the bike's general status
|
|
147
|
+
reservationStatus = {
|
|
148
|
+
status: 'disponible',
|
|
149
|
+
reservedBy: null
|
|
150
|
+
};
|
|
151
|
+
} else {
|
|
152
|
+
// If bike's general status is 'No Disponible' or something else
|
|
153
|
+
reservationStatus = {
|
|
154
|
+
status: 'no_disponible_general',
|
|
155
|
+
reservedBy: null
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
return _objectSpread(_objectSpread({}, bike), {}, {
|
|
159
|
+
// Spread original bike data
|
|
160
|
+
reservationStatus // Add the specific status for this slot
|
|
161
|
+
});
|
|
162
|
+
});
|
|
163
|
+
return bikesWithStatus;
|
|
158
164
|
});
|
|
159
165
|
return function getBikeAvailabilityForSlot(_x5, _x6) {
|
|
160
166
|
return _ref3.apply(this, arguments);
|
|
161
167
|
};
|
|
162
168
|
}();
|
|
163
169
|
|
|
170
|
+
// Nueva implementación simplificada para probar la exportación
|
|
171
|
+
/* const getBikeAvailabilityForSlot = async (location, date) => {
|
|
172
|
+
return { message: "Function is being called successfully", location, date };
|
|
173
|
+
};
|
|
174
|
+
*/
|
|
164
175
|
// Optional: Add functions for cancelling or fetching user-specific reservations later
|
|
165
176
|
/**
|
|
166
177
|
* Cancels a reservation.
|
|
@@ -170,7 +181,7 @@ var getBikeAvailabilityForSlot = exports.getBikeAvailabilityForSlot = /*#__PURE_
|
|
|
170
181
|
* @returns {Promise<object>} - The result of the deletion operation.
|
|
171
182
|
* @throws {Error} - If reservation not found or user is not authorized.
|
|
172
183
|
*/
|
|
173
|
-
var cancelReservation =
|
|
184
|
+
var cancelReservation = /*#__PURE__*/function () {
|
|
174
185
|
var _ref4 = _asyncToGenerator(function* (reservationId, userId, userRole) {
|
|
175
186
|
var reservation = yield _reservationModel.default.findById(reservationId);
|
|
176
187
|
if (!reservation) {
|
|
@@ -194,4 +205,10 @@ var cancelReservation = exports.cancelReservation = /*#__PURE__*/function () {
|
|
|
194
205
|
return function cancelReservation(_x7, _x8, _x9) {
|
|
195
206
|
return _ref4.apply(this, arguments);
|
|
196
207
|
};
|
|
197
|
-
}();
|
|
208
|
+
}();
|
|
209
|
+
var _default = exports.default = {
|
|
210
|
+
getBikeAvailabilityForSlot,
|
|
211
|
+
createReservation,
|
|
212
|
+
cancelReservation,
|
|
213
|
+
isBikeReserved
|
|
214
|
+
};
|