goldstars-services 1.0.59 → 1.0.60

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.
@@ -0,0 +1,202 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.updateInstructorSchedule = exports.getInstructorSchedules = exports.getInstructorForSlot = exports.deleteInstructorSchedule = exports.createInstructorSchedule = void 0;
7
+ var _instructorScheduleService = _interopRequireDefault(require("../services/instructorSchedule.service.js"));
8
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
9
+ 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); }
10
+ 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/controllers/instructorSchedule.controller.js
11
+ /**
12
+ * Creates a new weekly instructor schedule
13
+ */
14
+ var createInstructorSchedule = exports.createInstructorSchedule = /*#__PURE__*/function () {
15
+ var _ref = _asyncToGenerator(function* (req, res) {
16
+ try {
17
+ var {
18
+ instructorId,
19
+ instructorName,
20
+ location,
21
+ dayOfWeek,
22
+ timeSlot,
23
+ specialization
24
+ } = req.body;
25
+
26
+ // Validate required fields
27
+ if (!instructorId || !instructorName || !location || !dayOfWeek || !timeSlot) {
28
+ return res.status(400).json({
29
+ status: 400,
30
+ message: 'Todos los campos requeridos deben ser proporcionados: instructorId, instructorName, location, dayOfWeek, timeSlot'
31
+ });
32
+ }
33
+ var scheduleData = {
34
+ instructorId,
35
+ instructorName,
36
+ location,
37
+ dayOfWeek: parseInt(dayOfWeek),
38
+ timeSlot,
39
+ specialization: specialization || 'Spinning'
40
+ };
41
+ var newSchedule = yield _instructorScheduleService.default.createInstructorSchedule(scheduleData);
42
+ res.status(201).json({
43
+ status: 201,
44
+ message: 'Asignación de instructor creada exitosamente',
45
+ data: newSchedule
46
+ });
47
+ } catch (error) {
48
+ console.error('Error creating instructor schedule:', error);
49
+ res.status(400).json({
50
+ status: 400,
51
+ message: error.message || 'Error al crear la asignación del instructor'
52
+ });
53
+ }
54
+ });
55
+ return function createInstructorSchedule(_x, _x2) {
56
+ return _ref.apply(this, arguments);
57
+ };
58
+ }();
59
+
60
+ /**
61
+ * Gets instructor schedules filtered by location
62
+ */
63
+ var getInstructorSchedules = exports.getInstructorSchedules = /*#__PURE__*/function () {
64
+ var _ref2 = _asyncToGenerator(function* (req, res) {
65
+ try {
66
+ var {
67
+ location
68
+ } = req.query;
69
+ var schedules;
70
+ if (location) {
71
+ schedules = yield _instructorScheduleService.default.getInstructorSchedulesByLocation(location);
72
+ } else {
73
+ schedules = yield _instructorScheduleService.default.getAllInstructorSchedules();
74
+ }
75
+ res.status(200).json({
76
+ status: 200,
77
+ message: 'Asignaciones de instructor obtenidas exitosamente',
78
+ data: schedules
79
+ });
80
+ } catch (error) {
81
+ console.error('Error fetching instructor schedules:', error);
82
+ res.status(500).json({
83
+ status: 500,
84
+ message: error.message || 'Error al obtener las asignaciones de instructor'
85
+ });
86
+ }
87
+ });
88
+ return function getInstructorSchedules(_x3, _x4) {
89
+ return _ref2.apply(this, arguments);
90
+ };
91
+ }();
92
+
93
+ /**
94
+ * Gets instructor for a specific slot
95
+ */
96
+ var getInstructorForSlot = exports.getInstructorForSlot = /*#__PURE__*/function () {
97
+ var _ref3 = _asyncToGenerator(function* (req, res) {
98
+ try {
99
+ var {
100
+ location,
101
+ dayOfWeek,
102
+ timeSlot
103
+ } = req.query;
104
+ if (!location || !dayOfWeek || !timeSlot) {
105
+ return res.status(400).json({
106
+ status: 400,
107
+ message: 'location, dayOfWeek y timeSlot son requeridos'
108
+ });
109
+ }
110
+ var instructor = yield _instructorScheduleService.default.getInstructorForSlot(location, parseInt(dayOfWeek), timeSlot);
111
+ if (!instructor) {
112
+ return res.status(404).json({
113
+ status: 404,
114
+ message: 'No hay instructor asignado para este horario'
115
+ });
116
+ }
117
+ res.status(200).json({
118
+ status: 200,
119
+ message: 'Instructor encontrado',
120
+ data: instructor
121
+ });
122
+ } catch (error) {
123
+ console.error('Error fetching instructor for slot:', error);
124
+ res.status(500).json({
125
+ status: 500,
126
+ message: error.message || 'Error al obtener el instructor para el horario'
127
+ });
128
+ }
129
+ });
130
+ return function getInstructorForSlot(_x5, _x6) {
131
+ return _ref3.apply(this, arguments);
132
+ };
133
+ }();
134
+
135
+ /**
136
+ * Deletes an instructor schedule
137
+ */
138
+ var deleteInstructorSchedule = exports.deleteInstructorSchedule = /*#__PURE__*/function () {
139
+ var _ref4 = _asyncToGenerator(function* (req, res) {
140
+ try {
141
+ var {
142
+ id
143
+ } = req.params;
144
+ if (!id) {
145
+ return res.status(400).json({
146
+ status: 400,
147
+ message: 'ID de la asignación es requerido'
148
+ });
149
+ }
150
+ var result = yield _instructorScheduleService.default.deleteInstructorSchedule(id);
151
+ res.status(200).json({
152
+ status: 200,
153
+ message: result.message,
154
+ data: result.deletedSchedule
155
+ });
156
+ } catch (error) {
157
+ console.error('Error deleting instructor schedule:', error);
158
+ res.status(404).json({
159
+ status: 404,
160
+ message: error.message || 'Error al eliminar la asignación del instructor'
161
+ });
162
+ }
163
+ });
164
+ return function deleteInstructorSchedule(_x7, _x8) {
165
+ return _ref4.apply(this, arguments);
166
+ };
167
+ }();
168
+
169
+ /**
170
+ * Updates an instructor schedule
171
+ */
172
+ var updateInstructorSchedule = exports.updateInstructorSchedule = /*#__PURE__*/function () {
173
+ var _ref5 = _asyncToGenerator(function* (req, res) {
174
+ try {
175
+ var {
176
+ id
177
+ } = req.params;
178
+ var updateData = req.body;
179
+ if (!id) {
180
+ return res.status(400).json({
181
+ status: 400,
182
+ message: 'ID de la asignación es requerido'
183
+ });
184
+ }
185
+ var updatedSchedule = yield _instructorScheduleService.default.updateInstructorSchedule(id, updateData);
186
+ res.status(200).json({
187
+ status: 200,
188
+ message: 'Asignación de instructor actualizada exitosamente',
189
+ data: updatedSchedule
190
+ });
191
+ } catch (error) {
192
+ console.error('Error updating instructor schedule:', error);
193
+ res.status(404).json({
194
+ status: 404,
195
+ message: error.message || 'Error al actualizar la asignación del instructor'
196
+ });
197
+ }
198
+ });
199
+ return function updateInstructorSchedule(_x9, _x10) {
200
+ return _ref5.apply(this, arguments);
201
+ };
202
+ }();
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _mongoose = _interopRequireDefault(require("mongoose"));
8
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
9
+ // MicroService/src/models/instructorSchedule.model.js
10
+
11
+ var instructorScheduleSchema = new _mongoose.default.Schema({
12
+ instructorId: {
13
+ type: _mongoose.default.Schema.Types.ObjectId,
14
+ ref: 'User',
15
+ // Assuming instructors are stored in User model
16
+ required: true
17
+ },
18
+ instructorName: {
19
+ type: String,
20
+ required: true
21
+ },
22
+ location: {
23
+ type: String,
24
+ required: true,
25
+ enum: ['Sambil Paraguaná', 'C.C Las Virtudes']
26
+ },
27
+ dayOfWeek: {
28
+ type: Number,
29
+ required: true,
30
+ min: 1,
31
+ // Monday = 1
32
+ max: 5 // Friday = 5
33
+ },
34
+ timeSlot: {
35
+ type: String,
36
+ required: true
37
+ // Examples: '7am', '8am', '9:15am', '5pm', '7pm'
38
+ },
39
+ specialization: {
40
+ type: String,
41
+ default: 'Spinning'
42
+ },
43
+ isActive: {
44
+ type: Boolean,
45
+ default: true
46
+ },
47
+ createdAt: {
48
+ type: Date,
49
+ default: Date.now
50
+ },
51
+ updatedAt: {
52
+ type: Date,
53
+ default: Date.now
54
+ }
55
+ });
56
+
57
+ // Create a compound index to ensure unique instructor assignments per location/day/time
58
+ instructorScheduleSchema.index({
59
+ location: 1,
60
+ dayOfWeek: 1,
61
+ timeSlot: 1
62
+ }, {
63
+ unique: true
64
+ });
65
+
66
+ // Update the updatedAt field before saving
67
+ instructorScheduleSchema.pre('save', function (next) {
68
+ this.updatedAt = new Date();
69
+ next();
70
+ });
71
+ var InstructorSchedule = _mongoose.default.model('InstructorSchedule', instructorScheduleSchema);
72
+ var _default = exports.default = InstructorSchedule;
@@ -0,0 +1,246 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _instructorScheduleModel = _interopRequireDefault(require("../models/instructorSchedule.model.js"));
8
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
9
+ 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); }
10
+ 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/instructorSchedule.service.js
11
+ /**
12
+ * Helper function to extract time slot from timestamp
13
+ * @param {Date} timestamp - The timestamp
14
+ * @returns {string} - Time slot string (e.g., '7am', '5pm')
15
+ */
16
+ var extractTimeSlotFromTimestamp = timestamp => {
17
+ var hour = timestamp.getHours();
18
+ var minute = timestamp.getMinutes();
19
+
20
+ // Convert to 12-hour format with am/pm
21
+ if (hour === 0) return '12am';
22
+ if (hour < 12) {
23
+ if (minute === 0) return "".concat(hour, "am");
24
+ return "".concat(hour, ":").concat(minute.toString().padStart(2, '0'), "am");
25
+ }
26
+ if (hour === 12) {
27
+ if (minute === 0) return '12pm';
28
+ return "12:".concat(minute.toString().padStart(2, '0'), "pm");
29
+ }
30
+ var hour12 = hour - 12;
31
+ if (minute === 0) return "".concat(hour12, "pm");
32
+ return "".concat(hour12, ":").concat(minute.toString().padStart(2, '0'), "pm");
33
+ };
34
+
35
+ /**
36
+ * Creates a weekly instructor assignment
37
+ * @param {object} scheduleData - The schedule data
38
+ * @param {string} scheduleData.instructorId - Instructor's user ID
39
+ * @param {string} scheduleData.instructorName - Instructor's name
40
+ * @param {string} scheduleData.location - Location (Sambil Paraguaná or C.C Las Virtudes)
41
+ * @param {number} scheduleData.dayOfWeek - Day of week (1=Monday, 5=Friday)
42
+ * @param {string} scheduleData.timeSlot - Time slot (e.g., '7am', '5pm')
43
+ * @param {string} [scheduleData.specialization] - Instructor's specialization
44
+ * @returns {Promise<object>} - The created schedule document
45
+ */
46
+ var createInstructorSchedule = /*#__PURE__*/function () {
47
+ var _ref = _asyncToGenerator(function* (scheduleData) {
48
+ var {
49
+ instructorId,
50
+ instructorName,
51
+ location,
52
+ dayOfWeek,
53
+ timeSlot,
54
+ specialization = 'Spinning'
55
+ } = scheduleData;
56
+
57
+ // Validate required fields
58
+ if (!instructorId || !instructorName || !location || !dayOfWeek || !timeSlot) {
59
+ throw new Error('Todos los campos requeridos deben ser proporcionados.');
60
+ }
61
+
62
+ // Validate day of week
63
+ if (dayOfWeek < 1 || dayOfWeek > 5) {
64
+ throw new Error('El día de la semana debe estar entre 1 (Lunes) y 5 (Viernes).');
65
+ }
66
+
67
+ // Validate location
68
+ if (!['Sambil Paraguaná', 'C.C Las Virtudes'].includes(location)) {
69
+ throw new Error('Ubicación no válida.');
70
+ }
71
+ try {
72
+ var newSchedule = new _instructorScheduleModel.default({
73
+ instructorId,
74
+ instructorName,
75
+ location,
76
+ dayOfWeek,
77
+ timeSlot,
78
+ specialization
79
+ });
80
+ yield newSchedule.save();
81
+ return newSchedule;
82
+ } catch (error) {
83
+ if (error.code === 11000) {
84
+ throw new Error('Ya existe un instructor asignado para este horario y ubicación.');
85
+ }
86
+ throw error;
87
+ }
88
+ });
89
+ return function createInstructorSchedule(_x) {
90
+ return _ref.apply(this, arguments);
91
+ };
92
+ }();
93
+
94
+ /**
95
+ * Gets instructor assignments for a specific location
96
+ * @param {string} location - The location to filter by
97
+ * @returns {Promise<Array<object>>} - Array of instructor schedules
98
+ */
99
+ var getInstructorSchedulesByLocation = /*#__PURE__*/function () {
100
+ var _ref2 = _asyncToGenerator(function* (location) {
101
+ if (!location) {
102
+ throw new Error('La ubicación es requerida.');
103
+ }
104
+ var schedules = yield _instructorScheduleModel.default.find({
105
+ location,
106
+ isActive: true
107
+ }).sort({
108
+ dayOfWeek: 1,
109
+ timeSlot: 1
110
+ });
111
+ return schedules;
112
+ });
113
+ return function getInstructorSchedulesByLocation(_x2) {
114
+ return _ref2.apply(this, arguments);
115
+ };
116
+ }();
117
+
118
+ /**
119
+ * Gets all instructor assignments
120
+ * @returns {Promise<Array<object>>} - Array of all instructor schedules
121
+ */
122
+ var getAllInstructorSchedules = /*#__PURE__*/function () {
123
+ var _ref3 = _asyncToGenerator(function* () {
124
+ var schedules = yield _instructorScheduleModel.default.find({
125
+ isActive: true
126
+ }).sort({
127
+ location: 1,
128
+ dayOfWeek: 1,
129
+ timeSlot: 1
130
+ });
131
+ return schedules;
132
+ });
133
+ return function getAllInstructorSchedules() {
134
+ return _ref3.apply(this, arguments);
135
+ };
136
+ }();
137
+
138
+ /**
139
+ * Gets instructor for a specific location, day and time
140
+ * @param {string} location - Location
141
+ * @param {number} dayOfWeek - Day of week (1=Monday, 5=Friday)
142
+ * @param {string} timeSlot - Time slot
143
+ * @returns {Promise<object|null>} - Instructor schedule or null if not found
144
+ */
145
+ var getInstructorForSlot = /*#__PURE__*/function () {
146
+ var _ref4 = _asyncToGenerator(function* (location, dayOfWeek, timeSlot) {
147
+ var schedule = yield _instructorScheduleModel.default.findOne({
148
+ location,
149
+ dayOfWeek,
150
+ timeSlot,
151
+ isActive: true
152
+ });
153
+ return schedule;
154
+ });
155
+ return function getInstructorForSlot(_x3, _x4, _x5) {
156
+ return _ref4.apply(this, arguments);
157
+ };
158
+ }();
159
+
160
+ /**
161
+ * Gets instructor for a specific timestamp (automatically calculates day and time)
162
+ * @param {string} location - Location
163
+ * @param {Date} timestamp - The timestamp to check
164
+ * @returns {Promise<object|null>} - Instructor schedule or null if not found
165
+ */
166
+ var getInstructorForTimestamp = /*#__PURE__*/function () {
167
+ var _ref5 = _asyncToGenerator(function* (location, timestamp) {
168
+ var date = new Date(timestamp);
169
+ var dayOfWeek = date.getDay(); // 0=Sunday, 1=Monday, ..., 6=Saturday
170
+
171
+ // Convert Sunday=0 to Monday=1 format and skip weekends
172
+ if (dayOfWeek === 0 || dayOfWeek === 6) {
173
+ return null; // No classes on weekends
174
+ }
175
+ var normalizedDayOfWeek = dayOfWeek; // Keep as is since 1=Monday, 5=Friday
176
+ var timeSlot = extractTimeSlotFromTimestamp(date);
177
+ return yield getInstructorForSlot(location, normalizedDayOfWeek, timeSlot);
178
+ });
179
+ return function getInstructorForTimestamp(_x6, _x7) {
180
+ return _ref5.apply(this, arguments);
181
+ };
182
+ }();
183
+
184
+ /**
185
+ * Deletes an instructor schedule
186
+ * @param {string} scheduleId - ID of the schedule to delete
187
+ * @returns {Promise<object>} - Result of the deletion
188
+ */
189
+ var deleteInstructorSchedule = /*#__PURE__*/function () {
190
+ var _ref6 = _asyncToGenerator(function* (scheduleId) {
191
+ var schedule = yield _instructorScheduleModel.default.findById(scheduleId);
192
+ if (!schedule) {
193
+ throw new Error('Asignación de instructor no encontrada.');
194
+ }
195
+ var result = yield _instructorScheduleModel.default.deleteOne({
196
+ _id: scheduleId
197
+ });
198
+ if (result.deletedCount === 0) {
199
+ throw new Error('No se pudo eliminar la asignación del instructor.');
200
+ }
201
+ return {
202
+ message: 'Asignación de instructor eliminada exitosamente.',
203
+ deletedSchedule: schedule
204
+ };
205
+ });
206
+ return function deleteInstructorSchedule(_x8) {
207
+ return _ref6.apply(this, arguments);
208
+ };
209
+ }();
210
+
211
+ /**
212
+ * Updates an instructor schedule
213
+ * @param {string} scheduleId - ID of the schedule to update
214
+ * @param {object} updateData - Data to update
215
+ * @returns {Promise<object>} - Updated schedule
216
+ */
217
+ var updateInstructorSchedule = /*#__PURE__*/function () {
218
+ var _ref7 = _asyncToGenerator(function* (scheduleId, updateData) {
219
+ var schedule = yield _instructorScheduleModel.default.findById(scheduleId);
220
+ if (!schedule) {
221
+ throw new Error('Asignación de instructor no encontrada.');
222
+ }
223
+
224
+ // Update fields
225
+ Object.keys(updateData).forEach(key => {
226
+ if (updateData[key] !== undefined) {
227
+ schedule[key] = updateData[key];
228
+ }
229
+ });
230
+ yield schedule.save();
231
+ return schedule;
232
+ });
233
+ return function updateInstructorSchedule(_x9, _x10) {
234
+ return _ref7.apply(this, arguments);
235
+ };
236
+ }();
237
+ var _default = exports.default = {
238
+ createInstructorSchedule,
239
+ getInstructorSchedulesByLocation,
240
+ getAllInstructorSchedules,
241
+ getInstructorForSlot,
242
+ getInstructorForTimestamp,
243
+ deleteInstructorSchedule,
244
+ updateInstructorSchedule,
245
+ extractTimeSlotFromTimestamp
246
+ };
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
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
+ var _instructorScheduleService = _interopRequireDefault(require("./instructorSchedule.service.js"));
9
10
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
10
11
  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
12
  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; }
@@ -15,7 +16,6 @@ function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e =
15
16
  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); }
16
17
  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
17
18
  // Needed to check bike status/location
18
-
19
19
  /**
20
20
  * Checks if a bike is already reserved for a specific timestamp.
21
21
  * @param {string} bikeId - The ID of the bike.
@@ -130,10 +130,12 @@ var createReservation = /*#__PURE__*/function () {
130
130
  * Gets the availability status of all bikes for a specific location and timestamp.
131
131
  * @param {string} location - The location ('Sambil Paraguaná' or 'C.C Las Virtudes').
132
132
  * @param {Date|string} timestamp - The UTC timestamp to check (Date object or valid date string).
133
+ * @param {boolean} includeInstructor - Whether to include instructor information.
133
134
  * @returns {Promise<Array<object>>} - An array of bike objects, each with an added 'reservationStatus' field.
134
135
  */
135
136
  var getBikeAvailabilityForSlot = /*#__PURE__*/function () {
136
137
  var _ref3 = _asyncToGenerator(function* (location, timestamp) {
138
+ var includeInstructor = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
137
139
  var checkTimestamp = new Date(timestamp);
138
140
  if (isNaN(checkTimestamp.getTime())) {
139
141
  throw new Error('Timestamp inválido proporcionado para obtener disponibilidad.');
@@ -157,43 +159,65 @@ var getBikeAvailabilityForSlot = /*#__PURE__*/function () {
157
159
  // 3. Create a map of reserved bike IDs for quick lookup
158
160
  var reservedBikeMap = new Map();
159
161
  reservations.forEach(res => {
160
- // Store the user info (or just true if user info isn't needed/allowed)
161
- reservedBikeMap.set(res.bikeId.toString(), res.userId); // Store populated user object
162
+ // Store the user info and reservation ID
163
+ reservedBikeMap.set(res.bikeId.toString(), {
164
+ user: res.userId,
165
+ reservationId: res._id.toString()
166
+ });
162
167
  });
163
168
 
164
- // 4. Combine bike data with reservation status
169
+ // 4. Get instructor information if requested
170
+ var instructorInfo = null;
171
+ if (includeInstructor) {
172
+ instructorInfo = yield _instructorScheduleService.default.getInstructorForTimestamp(location, checkTimestamp);
173
+ }
174
+
175
+ // 5. Combine bike data with reservation status
165
176
  var bikesWithStatus = bikesInLocation.map(bike => {
166
177
  var bikeIdStr = bike._id.toString();
167
- var reservedByUser = reservedBikeMap.get(bikeIdStr);
178
+ var reservationData = reservedBikeMap.get(bikeIdStr);
168
179
  var reservationStatus;
169
180
  if (bike.isInstructorBike) {
181
+ // For instructor bike, include instructor name if available
182
+ var instructorName = instructorInfo ? instructorInfo.instructorName : null;
170
183
  reservationStatus = {
171
184
  status: 'instructor',
172
- reservedBy: null
185
+ reservedBy: null,
186
+ reservationId: null,
187
+ instructorName: instructorName
173
188
  };
174
- } else if (reservedByUser) {
175
- // For admin: include user details. For regular user, this might be simplified later.
189
+ } else if (reservationData) {
190
+ // For admin: include user details and reservation ID
176
191
  reservationStatus = {
177
192
  status: 'agendada',
178
- reservedBy: reservedByUser
193
+ reservedBy: reservationData.user,
194
+ reservationId: reservationData.reservationId
179
195
  };
180
196
  } else if (bike.status === 'Disponible') {
181
197
  // Check the bike's general status
182
198
  reservationStatus = {
183
199
  status: 'disponible',
184
- reservedBy: null
200
+ reservedBy: null,
201
+ reservationId: null
185
202
  };
186
203
  } else {
187
204
  // If bike's general status is 'No Disponible' or something else
188
205
  reservationStatus = {
189
206
  status: 'no_disponible_general',
190
- reservedBy: null
207
+ reservedBy: null,
208
+ reservationId: null
191
209
  };
192
210
  }
193
- return _objectSpread(_objectSpread({}, bike), {}, {
211
+ var result = _objectSpread(_objectSpread({}, bike), {}, {
194
212
  // Spread original bike data
195
213
  reservationStatus // Add the specific status for this slot
196
214
  });
215
+
216
+ // Add instructor name directly to instructor bikes for easier access
217
+ if (bike.isInstructorBike && instructorInfo) {
218
+ result.instructorName = instructorInfo.instructorName;
219
+ }
220
+ return result;
197
221
  });
198
222
  return bikesWithStatus;
199
223
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "goldstars-services",
3
- "version": "1.0.59",
3
+ "version": "1.0.60",
4
4
  "description": "This is the services layer for GoldStars",
5
5
  "main": "./dist/index.js",
6
6
  "scripts": {