goldstars-services 1.0.70 → 1.0.71
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.
- package/dist/index.js +21 -0
- package/dist/models/scheduleException.model.js +87 -0
- package/dist/models/user.model.js +32 -0
- package/dist/models/weeklyScheduleTemplate.model.js +73 -0
- package/dist/scripts/migrateInitialSchedules.js +331 -0
- package/dist/services/reservation.service.js +117 -27
- package/dist/services/scheduleException.service.js +288 -0
- package/dist/services/userSuspension.service.js +253 -0
- package/dist/services/weeklyScheduleTemplate.service.js +226 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -21,6 +21,12 @@ Object.defineProperty(exports, "ReservationService", {
|
|
|
21
21
|
return _reservation.default;
|
|
22
22
|
}
|
|
23
23
|
});
|
|
24
|
+
Object.defineProperty(exports, "ScheduleExceptionService", {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function get() {
|
|
27
|
+
return _scheduleException.default;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
24
30
|
Object.defineProperty(exports, "TransactionService", {
|
|
25
31
|
enumerable: true,
|
|
26
32
|
get: function get() {
|
|
@@ -33,6 +39,18 @@ Object.defineProperty(exports, "UserService", {
|
|
|
33
39
|
return _user.default;
|
|
34
40
|
}
|
|
35
41
|
});
|
|
42
|
+
Object.defineProperty(exports, "UserSuspensionService", {
|
|
43
|
+
enumerable: true,
|
|
44
|
+
get: function get() {
|
|
45
|
+
return _userSuspension.default;
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
Object.defineProperty(exports, "WeeklyScheduleTemplateService", {
|
|
49
|
+
enumerable: true,
|
|
50
|
+
get: function get() {
|
|
51
|
+
return _weeklyScheduleTemplate.default;
|
|
52
|
+
}
|
|
53
|
+
});
|
|
36
54
|
Object.defineProperty(exports, "bankService", {
|
|
37
55
|
enumerable: true,
|
|
38
56
|
get: function get() {
|
|
@@ -80,4 +98,7 @@ var _report = _interopRequireDefault(require("./services/report.service"));
|
|
|
80
98
|
var _reservation = _interopRequireDefault(require("./services/reservation.service"));
|
|
81
99
|
var _eventRegistration = _interopRequireDefault(require("./services/eventRegistration.service"));
|
|
82
100
|
var _gymPass = _interopRequireDefault(require("./services/gymPass.service"));
|
|
101
|
+
var _weeklyScheduleTemplate = _interopRequireDefault(require("./services/weeklyScheduleTemplate.service"));
|
|
102
|
+
var _scheduleException = _interopRequireDefault(require("./services/scheduleException.service"));
|
|
103
|
+
var _userSuspension = _interopRequireDefault(require("./services/userSuspension.service"));
|
|
83
104
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
@@ -0,0 +1,87 @@
|
|
|
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
|
+
var scheduleExceptionSchema = new _mongoose.default.Schema({
|
|
10
|
+
location: {
|
|
11
|
+
type: String,
|
|
12
|
+
required: true,
|
|
13
|
+
enum: ['C.C Las Virtudes', 'Sambil Paraguaná'],
|
|
14
|
+
index: true
|
|
15
|
+
},
|
|
16
|
+
exceptionDate: {
|
|
17
|
+
type: Date,
|
|
18
|
+
// Fecha específica (solo día, ignorar hora)
|
|
19
|
+
required: true,
|
|
20
|
+
index: true
|
|
21
|
+
},
|
|
22
|
+
exceptionType: {
|
|
23
|
+
type: String,
|
|
24
|
+
required: true,
|
|
25
|
+
enum: ['CLOSED',
|
|
26
|
+
// Sede cerrada todo el día
|
|
27
|
+
'CUSTOM_HOURS',
|
|
28
|
+
// Horarios custom para ese día
|
|
29
|
+
'SLOT_BLOCKED' // Bloqueo de slot específico
|
|
30
|
+
]
|
|
31
|
+
},
|
|
32
|
+
// Para CUSTOM_HOURS
|
|
33
|
+
customTimeSlots: [{
|
|
34
|
+
time: {
|
|
35
|
+
type: String,
|
|
36
|
+
validate: {
|
|
37
|
+
validator: function validator(v) {
|
|
38
|
+
return /^(1[0-2]|[1-9])(:([0-5][0-9]))?(am|pm)$/i.test(v);
|
|
39
|
+
},
|
|
40
|
+
message: 'Formato de hora inválido'
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
isActive: {
|
|
44
|
+
type: Boolean,
|
|
45
|
+
default: true
|
|
46
|
+
}
|
|
47
|
+
}],
|
|
48
|
+
// Para SLOT_BLOCKED
|
|
49
|
+
blockedTimeSlot: {
|
|
50
|
+
type: String
|
|
51
|
+
// Solo requerido si exceptionType === 'SLOT_BLOCKED'
|
|
52
|
+
},
|
|
53
|
+
reason: {
|
|
54
|
+
type: String,
|
|
55
|
+
default: ''
|
|
56
|
+
},
|
|
57
|
+
isActive: {
|
|
58
|
+
type: Boolean,
|
|
59
|
+
default: true
|
|
60
|
+
},
|
|
61
|
+
createdBy: {
|
|
62
|
+
type: _mongoose.default.Schema.Types.ObjectId,
|
|
63
|
+
ref: 'User',
|
|
64
|
+
required: true
|
|
65
|
+
},
|
|
66
|
+
createdAt: {
|
|
67
|
+
type: Date,
|
|
68
|
+
default: Date.now
|
|
69
|
+
},
|
|
70
|
+
updatedAt: {
|
|
71
|
+
type: Date,
|
|
72
|
+
default: Date.now
|
|
73
|
+
}
|
|
74
|
+
}, {
|
|
75
|
+
timestamps: true
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
// Índice compuesto para búsquedas rápidas
|
|
79
|
+
scheduleExceptionSchema.index({
|
|
80
|
+
location: 1,
|
|
81
|
+
exceptionDate: 1
|
|
82
|
+
});
|
|
83
|
+
scheduleExceptionSchema.index({
|
|
84
|
+
exceptionDate: 1
|
|
85
|
+
});
|
|
86
|
+
var ScheduleException = _mongoose.default.model('ScheduleException', scheduleExceptionSchema);
|
|
87
|
+
var _default = exports.default = ScheduleException;
|
|
@@ -87,6 +87,38 @@ var UserSchema = Schema({
|
|
|
87
87
|
signUpDate: {
|
|
88
88
|
type: Date,
|
|
89
89
|
default: Date.now
|
|
90
|
+
},
|
|
91
|
+
suspensionStatus: {
|
|
92
|
+
type: {
|
|
93
|
+
isSuspended: {
|
|
94
|
+
type: Boolean,
|
|
95
|
+
default: false
|
|
96
|
+
},
|
|
97
|
+
suspendedAt: {
|
|
98
|
+
type: Date,
|
|
99
|
+
default: null
|
|
100
|
+
},
|
|
101
|
+
suspendedBy: {
|
|
102
|
+
type: Schema.Types.ObjectId,
|
|
103
|
+
ref: "User",
|
|
104
|
+
default: null
|
|
105
|
+
},
|
|
106
|
+
reason: {
|
|
107
|
+
type: String,
|
|
108
|
+
default: ""
|
|
109
|
+
},
|
|
110
|
+
suspendedUntil: {
|
|
111
|
+
type: Date,
|
|
112
|
+
default: null
|
|
113
|
+
},
|
|
114
|
+
// null = indefinido
|
|
115
|
+
allowedServices: {
|
|
116
|
+
type: [String],
|
|
117
|
+
enum: ["bikes", "gym", "events"],
|
|
118
|
+
default: ["bikes", "gym", "events"]
|
|
119
|
+
}
|
|
120
|
+
},
|
|
121
|
+
default: null
|
|
90
122
|
}
|
|
91
123
|
});
|
|
92
124
|
UserSchema.pre("save", /*#__PURE__*/function () {
|
|
@@ -0,0 +1,73 @@
|
|
|
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
|
+
var weeklyScheduleTemplateSchema = new _mongoose.default.Schema({
|
|
10
|
+
location: {
|
|
11
|
+
type: String,
|
|
12
|
+
required: true,
|
|
13
|
+
enum: ['C.C Las Virtudes', 'Sambil Paraguaná'],
|
|
14
|
+
index: true
|
|
15
|
+
},
|
|
16
|
+
dayOfWeek: {
|
|
17
|
+
type: Number,
|
|
18
|
+
required: true,
|
|
19
|
+
min: 1,
|
|
20
|
+
// Monday
|
|
21
|
+
max: 5,
|
|
22
|
+
// Friday
|
|
23
|
+
validate: {
|
|
24
|
+
validator: Number.isInteger,
|
|
25
|
+
message: 'dayOfWeek debe ser un número entero entre 1 (Lunes) y 5 (Viernes)'
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
timeSlots: [{
|
|
29
|
+
time: {
|
|
30
|
+
type: String,
|
|
31
|
+
required: true,
|
|
32
|
+
// Formato: '7am', '8:30am', '5pm', '7pm'
|
|
33
|
+
validate: {
|
|
34
|
+
validator: function validator(v) {
|
|
35
|
+
return /^(1[0-2]|[1-9])(:([0-5][0-9]))?(am|pm)$/i.test(v);
|
|
36
|
+
},
|
|
37
|
+
message: 'Formato de hora inválido. Use formato como: 7am, 8:30am, 5pm'
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
isActive: {
|
|
41
|
+
type: Boolean,
|
|
42
|
+
default: true
|
|
43
|
+
},
|
|
44
|
+
maxCapacity: {
|
|
45
|
+
type: Number,
|
|
46
|
+
default: null // null = usar todas las bikes disponibles en esa ubicación
|
|
47
|
+
}
|
|
48
|
+
}],
|
|
49
|
+
isActive: {
|
|
50
|
+
type: Boolean,
|
|
51
|
+
default: true
|
|
52
|
+
},
|
|
53
|
+
createdAt: {
|
|
54
|
+
type: Date,
|
|
55
|
+
default: Date.now
|
|
56
|
+
},
|
|
57
|
+
updatedAt: {
|
|
58
|
+
type: Date,
|
|
59
|
+
default: Date.now
|
|
60
|
+
}
|
|
61
|
+
}, {
|
|
62
|
+
timestamps: true
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
// Índice compuesto único: una sola config por location+dayOfWeek
|
|
66
|
+
weeklyScheduleTemplateSchema.index({
|
|
67
|
+
location: 1,
|
|
68
|
+
dayOfWeek: 1
|
|
69
|
+
}, {
|
|
70
|
+
unique: true
|
|
71
|
+
});
|
|
72
|
+
var WeeklyScheduleTemplate = _mongoose.default.model('WeeklyScheduleTemplate', weeklyScheduleTemplateSchema);
|
|
73
|
+
var _default = exports.default = WeeklyScheduleTemplate;
|
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _mongoose = _interopRequireDefault(require("mongoose"));
|
|
4
|
+
var _weeklyScheduleTemplateModel = _interopRequireDefault(require("../models/weeklyScheduleTemplate.model.js"));
|
|
5
|
+
var _dotenv = _interopRequireDefault(require("dotenv"));
|
|
6
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
7
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
8
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
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); }); }; }
|
|
11
|
+
_dotenv.default.config();
|
|
12
|
+
|
|
13
|
+
// Datos iniciales de horarios basados en los valores hardcoded
|
|
14
|
+
var INITIAL_SCHEDULES = [
|
|
15
|
+
// C.C Las Virtudes - Lunes (1)
|
|
16
|
+
{
|
|
17
|
+
location: 'C.C Las Virtudes',
|
|
18
|
+
dayOfWeek: 1,
|
|
19
|
+
timeSlots: [{
|
|
20
|
+
time: '7am',
|
|
21
|
+
isActive: true,
|
|
22
|
+
maxCapacity: null
|
|
23
|
+
}, {
|
|
24
|
+
time: '5pm',
|
|
25
|
+
isActive: true,
|
|
26
|
+
maxCapacity: null
|
|
27
|
+
}, {
|
|
28
|
+
time: '7pm',
|
|
29
|
+
isActive: true,
|
|
30
|
+
maxCapacity: null
|
|
31
|
+
}],
|
|
32
|
+
isActive: true
|
|
33
|
+
},
|
|
34
|
+
// C.C Las Virtudes - Martes (2)
|
|
35
|
+
{
|
|
36
|
+
location: 'C.C Las Virtudes',
|
|
37
|
+
dayOfWeek: 2,
|
|
38
|
+
timeSlots: [{
|
|
39
|
+
time: '7am',
|
|
40
|
+
isActive: true,
|
|
41
|
+
maxCapacity: null
|
|
42
|
+
}, {
|
|
43
|
+
time: '8:30am',
|
|
44
|
+
isActive: true,
|
|
45
|
+
maxCapacity: null
|
|
46
|
+
}, {
|
|
47
|
+
time: '5pm',
|
|
48
|
+
isActive: true,
|
|
49
|
+
maxCapacity: null
|
|
50
|
+
}, {
|
|
51
|
+
time: '7pm',
|
|
52
|
+
isActive: true,
|
|
53
|
+
maxCapacity: null
|
|
54
|
+
}],
|
|
55
|
+
isActive: true
|
|
56
|
+
},
|
|
57
|
+
// C.C Las Virtudes - Miércoles (3)
|
|
58
|
+
{
|
|
59
|
+
location: 'C.C Las Virtudes',
|
|
60
|
+
dayOfWeek: 3,
|
|
61
|
+
timeSlots: [{
|
|
62
|
+
time: '7am',
|
|
63
|
+
isActive: true,
|
|
64
|
+
maxCapacity: null
|
|
65
|
+
}, {
|
|
66
|
+
time: '8:30am',
|
|
67
|
+
isActive: true,
|
|
68
|
+
maxCapacity: null
|
|
69
|
+
}, {
|
|
70
|
+
time: '5pm',
|
|
71
|
+
isActive: true,
|
|
72
|
+
maxCapacity: null
|
|
73
|
+
}, {
|
|
74
|
+
time: '7pm',
|
|
75
|
+
isActive: true,
|
|
76
|
+
maxCapacity: null
|
|
77
|
+
}],
|
|
78
|
+
isActive: true
|
|
79
|
+
},
|
|
80
|
+
// C.C Las Virtudes - Jueves (4)
|
|
81
|
+
{
|
|
82
|
+
location: 'C.C Las Virtudes',
|
|
83
|
+
dayOfWeek: 4,
|
|
84
|
+
timeSlots: [{
|
|
85
|
+
time: '7am',
|
|
86
|
+
isActive: true,
|
|
87
|
+
maxCapacity: null
|
|
88
|
+
}, {
|
|
89
|
+
time: '8:30am',
|
|
90
|
+
isActive: true,
|
|
91
|
+
maxCapacity: null
|
|
92
|
+
}, {
|
|
93
|
+
time: '5pm',
|
|
94
|
+
isActive: true,
|
|
95
|
+
maxCapacity: null
|
|
96
|
+
}, {
|
|
97
|
+
time: '7pm',
|
|
98
|
+
isActive: true,
|
|
99
|
+
maxCapacity: null
|
|
100
|
+
}],
|
|
101
|
+
isActive: true
|
|
102
|
+
},
|
|
103
|
+
// C.C Las Virtudes - Viernes (5)
|
|
104
|
+
{
|
|
105
|
+
location: 'C.C Las Virtudes',
|
|
106
|
+
dayOfWeek: 5,
|
|
107
|
+
timeSlots: [{
|
|
108
|
+
time: '7am',
|
|
109
|
+
isActive: true,
|
|
110
|
+
maxCapacity: null
|
|
111
|
+
}, {
|
|
112
|
+
time: '5pm',
|
|
113
|
+
isActive: true,
|
|
114
|
+
maxCapacity: null
|
|
115
|
+
}, {
|
|
116
|
+
time: '7pm',
|
|
117
|
+
isActive: true,
|
|
118
|
+
maxCapacity: null
|
|
119
|
+
}],
|
|
120
|
+
isActive: true
|
|
121
|
+
},
|
|
122
|
+
// Sambil Paraguaná - Lunes (1)
|
|
123
|
+
{
|
|
124
|
+
location: 'Sambil Paraguaná',
|
|
125
|
+
dayOfWeek: 1,
|
|
126
|
+
timeSlots: [{
|
|
127
|
+
time: '8am',
|
|
128
|
+
isActive: true,
|
|
129
|
+
maxCapacity: null
|
|
130
|
+
}, {
|
|
131
|
+
time: '9:15am',
|
|
132
|
+
isActive: true,
|
|
133
|
+
maxCapacity: null
|
|
134
|
+
}, {
|
|
135
|
+
time: '5pm',
|
|
136
|
+
isActive: true,
|
|
137
|
+
maxCapacity: null
|
|
138
|
+
}, {
|
|
139
|
+
time: '7pm',
|
|
140
|
+
isActive: true,
|
|
141
|
+
maxCapacity: null
|
|
142
|
+
}],
|
|
143
|
+
isActive: true
|
|
144
|
+
},
|
|
145
|
+
// Sambil Paraguaná - Martes (2)
|
|
146
|
+
{
|
|
147
|
+
location: 'Sambil Paraguaná',
|
|
148
|
+
dayOfWeek: 2,
|
|
149
|
+
timeSlots: [{
|
|
150
|
+
time: '8am',
|
|
151
|
+
isActive: true,
|
|
152
|
+
maxCapacity: null
|
|
153
|
+
}, {
|
|
154
|
+
time: '9:15am',
|
|
155
|
+
isActive: true,
|
|
156
|
+
maxCapacity: null
|
|
157
|
+
}, {
|
|
158
|
+
time: '5pm',
|
|
159
|
+
isActive: true,
|
|
160
|
+
maxCapacity: null
|
|
161
|
+
}, {
|
|
162
|
+
time: '7pm',
|
|
163
|
+
isActive: true,
|
|
164
|
+
maxCapacity: null
|
|
165
|
+
}],
|
|
166
|
+
isActive: true
|
|
167
|
+
},
|
|
168
|
+
// Sambil Paraguaná - Miércoles (3)
|
|
169
|
+
{
|
|
170
|
+
location: 'Sambil Paraguaná',
|
|
171
|
+
dayOfWeek: 3,
|
|
172
|
+
timeSlots: [{
|
|
173
|
+
time: '8am',
|
|
174
|
+
isActive: true,
|
|
175
|
+
maxCapacity: null
|
|
176
|
+
}, {
|
|
177
|
+
time: '9:15am',
|
|
178
|
+
isActive: true,
|
|
179
|
+
maxCapacity: null
|
|
180
|
+
}, {
|
|
181
|
+
time: '5pm',
|
|
182
|
+
isActive: true,
|
|
183
|
+
maxCapacity: null
|
|
184
|
+
}, {
|
|
185
|
+
time: '7pm',
|
|
186
|
+
isActive: true,
|
|
187
|
+
maxCapacity: null
|
|
188
|
+
}],
|
|
189
|
+
isActive: true
|
|
190
|
+
},
|
|
191
|
+
// Sambil Paraguaná - Jueves (4)
|
|
192
|
+
{
|
|
193
|
+
location: 'Sambil Paraguaná',
|
|
194
|
+
dayOfWeek: 4,
|
|
195
|
+
timeSlots: [{
|
|
196
|
+
time: '8am',
|
|
197
|
+
isActive: true,
|
|
198
|
+
maxCapacity: null
|
|
199
|
+
}, {
|
|
200
|
+
time: '9:15am',
|
|
201
|
+
isActive: true,
|
|
202
|
+
maxCapacity: null
|
|
203
|
+
}, {
|
|
204
|
+
time: '5pm',
|
|
205
|
+
isActive: true,
|
|
206
|
+
maxCapacity: null
|
|
207
|
+
}, {
|
|
208
|
+
time: '7pm',
|
|
209
|
+
isActive: true,
|
|
210
|
+
maxCapacity: null
|
|
211
|
+
}],
|
|
212
|
+
isActive: true
|
|
213
|
+
},
|
|
214
|
+
// Sambil Paraguaná - Viernes (5)
|
|
215
|
+
{
|
|
216
|
+
location: 'Sambil Paraguaná',
|
|
217
|
+
dayOfWeek: 5,
|
|
218
|
+
timeSlots: [{
|
|
219
|
+
time: '8am',
|
|
220
|
+
isActive: true,
|
|
221
|
+
maxCapacity: null
|
|
222
|
+
}, {
|
|
223
|
+
time: '9:15am',
|
|
224
|
+
isActive: true,
|
|
225
|
+
maxCapacity: null
|
|
226
|
+
}, {
|
|
227
|
+
time: '5pm',
|
|
228
|
+
isActive: true,
|
|
229
|
+
maxCapacity: null
|
|
230
|
+
}, {
|
|
231
|
+
time: '7pm',
|
|
232
|
+
isActive: true,
|
|
233
|
+
maxCapacity: null
|
|
234
|
+
}],
|
|
235
|
+
isActive: true
|
|
236
|
+
}];
|
|
237
|
+
var migrateSchedules = /*#__PURE__*/function () {
|
|
238
|
+
var _ref = _asyncToGenerator(function* () {
|
|
239
|
+
try {
|
|
240
|
+
console.log('🚀 Iniciando migración de horarios iniciales...');
|
|
241
|
+
|
|
242
|
+
// Conectar a la base de datos
|
|
243
|
+
var mongoUri = process.env.MONGODB_URI || 'mongodb://localhost:27017/goldstars';
|
|
244
|
+
yield _mongoose.default.connect(mongoUri);
|
|
245
|
+
console.log('✅ Conectado a MongoDB');
|
|
246
|
+
|
|
247
|
+
// Verificar si ya existen horarios
|
|
248
|
+
var existingSchedules = yield _weeklyScheduleTemplateModel.default.countDocuments();
|
|
249
|
+
if (existingSchedules > 0) {
|
|
250
|
+
console.log("\u26A0\uFE0F Ya existen ".concat(existingSchedules, " horarios en la base de datos."));
|
|
251
|
+
var readline = yield Promise.resolve().then(() => _interopRequireWildcard(require('readline')));
|
|
252
|
+
var rl = readline.createInterface({
|
|
253
|
+
input: process.stdin,
|
|
254
|
+
output: process.stdout
|
|
255
|
+
});
|
|
256
|
+
var answer = yield new Promise(resolve => {
|
|
257
|
+
rl.question('¿Desea eliminar los horarios existentes y crear nuevos? (s/n): ', resolve);
|
|
258
|
+
});
|
|
259
|
+
rl.close();
|
|
260
|
+
if (answer.toLowerCase() !== 's') {
|
|
261
|
+
console.log('❌ Migración cancelada por el usuario.');
|
|
262
|
+
yield _mongoose.default.disconnect();
|
|
263
|
+
process.exit(0);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
// Eliminar horarios existentes
|
|
267
|
+
yield _weeklyScheduleTemplateModel.default.deleteMany({});
|
|
268
|
+
console.log('🗑️ Horarios existentes eliminados.');
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
// Insertar horarios iniciales
|
|
272
|
+
console.log('📝 Insertando horarios iniciales...');
|
|
273
|
+
var insertedCount = 0;
|
|
274
|
+
for (var schedule of INITIAL_SCHEDULES) {
|
|
275
|
+
try {
|
|
276
|
+
yield _weeklyScheduleTemplateModel.default.create(schedule);
|
|
277
|
+
insertedCount++;
|
|
278
|
+
console.log(" \u2713 ".concat(schedule.location, " - ").concat(getDayName(schedule.dayOfWeek), ": ").concat(schedule.timeSlots.length, " slots"));
|
|
279
|
+
} catch (error) {
|
|
280
|
+
console.error(" \u2717 Error insertando ".concat(schedule.location, " - ").concat(getDayName(schedule.dayOfWeek), ":"), error.message);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
console.log("\n\u2705 Migraci\xF3n completada: ".concat(insertedCount, "/").concat(INITIAL_SCHEDULES.length, " horarios insertados."));
|
|
284
|
+
|
|
285
|
+
// Mostrar resumen
|
|
286
|
+
console.log('\n📊 Resumen de horarios por ubicación:');
|
|
287
|
+
var virtudes = yield _weeklyScheduleTemplateModel.default.find({
|
|
288
|
+
location: 'C.C Las Virtudes'
|
|
289
|
+
}).sort({
|
|
290
|
+
dayOfWeek: 1
|
|
291
|
+
});
|
|
292
|
+
var sambil = yield _weeklyScheduleTemplateModel.default.find({
|
|
293
|
+
location: 'Sambil Paraguaná'
|
|
294
|
+
}).sort({
|
|
295
|
+
dayOfWeek: 1
|
|
296
|
+
});
|
|
297
|
+
console.log('\n🏢 C.C Las Virtudes:');
|
|
298
|
+
virtudes.forEach(s => {
|
|
299
|
+
var slots = s.timeSlots.map(t => t.time).join(', ');
|
|
300
|
+
console.log(" ".concat(getDayName(s.dayOfWeek), ": ").concat(slots));
|
|
301
|
+
});
|
|
302
|
+
console.log('\n🏢 Sambil Paraguaná:');
|
|
303
|
+
sambil.forEach(s => {
|
|
304
|
+
var slots = s.timeSlots.map(t => t.time).join(', ');
|
|
305
|
+
console.log(" ".concat(getDayName(s.dayOfWeek), ": ").concat(slots));
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
// Desconectar
|
|
309
|
+
yield _mongoose.default.disconnect();
|
|
310
|
+
console.log('\n✅ Desconectado de MongoDB');
|
|
311
|
+
console.log('🎉 Migración finalizada exitosamente!');
|
|
312
|
+
process.exit(0);
|
|
313
|
+
} catch (error) {
|
|
314
|
+
console.error('❌ Error durante la migración:', error);
|
|
315
|
+
yield _mongoose.default.disconnect();
|
|
316
|
+
process.exit(1);
|
|
317
|
+
}
|
|
318
|
+
});
|
|
319
|
+
return function migrateSchedules() {
|
|
320
|
+
return _ref.apply(this, arguments);
|
|
321
|
+
};
|
|
322
|
+
}();
|
|
323
|
+
|
|
324
|
+
// Helper function
|
|
325
|
+
var getDayName = dayOfWeek => {
|
|
326
|
+
var days = ['', 'Lunes', 'Martes', 'Miércoles', 'Jueves', 'Viernes'];
|
|
327
|
+
return days[dayOfWeek] || 'Desconocido';
|
|
328
|
+
};
|
|
329
|
+
|
|
330
|
+
// Ejecutar migración
|
|
331
|
+
migrateSchedules();
|