lms-sync 1.0.0
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/apiConnections/apiConnects.js +268 -0
- package/apiConnections/mapping.js +1337 -0
- package/apiConnections/sequelizeConnection.js +24 -0
- package/app.js +27 -0
- package/config/config.json +0 -0
- package/models/academic.departments.model.js +95 -0
- package/models/academicYears.model.js +83 -0
- package/models/campuses.model.js +125 -0
- package/models/colleges.model.js +117 -0
- package/models/courses.model.js +99 -0
- package/models/departments.model.js +90 -0
- package/models/enrolledStudents.model.js +292 -0
- package/models/index.js +48 -0
- package/models/instructors.model.js +168 -0
- package/models/rooms.model.js +89 -0
- package/models/schedules.model.js +75 -0
- package/models/sections.model.js +301 -0
- package/models/semesters.model.js +81 -0
- package/models/students.model.js +214 -0
- package/models/subjects.model.js +104 -0
- package/models/users.model.js +198 -0
- package/package.json +36 -0
- package/recordError.log +0 -0
- package/recordSuccess.log +0 -0
- package/utils/Mixins.js +189 -0
- package/utils/logger.js +33 -0
@@ -0,0 +1,1337 @@
|
|
1
|
+
const db = require('../models')
|
2
|
+
const logger = require('../utils/logger')
|
3
|
+
const api = require('../apiConnections/apiConnects')
|
4
|
+
const moment = require('moment')
|
5
|
+
const {
|
6
|
+
AcademicDepartments,
|
7
|
+
AcademicYears,
|
8
|
+
Campuses,
|
9
|
+
Colleges,
|
10
|
+
Courses,
|
11
|
+
EnrolledStudents,
|
12
|
+
Instructors,
|
13
|
+
Rooms,
|
14
|
+
Sections,
|
15
|
+
Students,
|
16
|
+
Subjects,
|
17
|
+
Schedules,
|
18
|
+
Users,
|
19
|
+
Semesters
|
20
|
+
|
21
|
+
} = db
|
22
|
+
|
23
|
+
const server = {
|
24
|
+
|
25
|
+
async Campus(){
|
26
|
+
try {
|
27
|
+
console.log("");
|
28
|
+
console.log("########################################################")
|
29
|
+
console.log(" Campuses Migration ")
|
30
|
+
console.log("########################################################")
|
31
|
+
console.log("");
|
32
|
+
|
33
|
+
const campusApi = await api.Campus()
|
34
|
+
const userMail = await Users.findOne({ where: { email: 'ccci_integrator@gmail.com' } });
|
35
|
+
|
36
|
+
let createdCounter = 0
|
37
|
+
let errorCounter = 0
|
38
|
+
let uniqueErrors = new Set()
|
39
|
+
|
40
|
+
for (let i = 0; i < campusApi.length; i++){
|
41
|
+
try {
|
42
|
+
|
43
|
+
let _campus = campusApi[i]
|
44
|
+
|
45
|
+
let modifiedById = userMail._id
|
46
|
+
let createdById = userMail._id
|
47
|
+
|
48
|
+
let [record, created] = await Campuses.findOrCreate({
|
49
|
+
where:{
|
50
|
+
name: _campus?.name,
|
51
|
+
code: _campus?.code
|
52
|
+
},
|
53
|
+
defaults:{
|
54
|
+
email: _campus?.email,
|
55
|
+
address: _campus?.address,
|
56
|
+
modifiedById,
|
57
|
+
createdById
|
58
|
+
}
|
59
|
+
})
|
60
|
+
if (created){
|
61
|
+
logger.info(`New campus record created ${createdCounter + 1}/${createdCounter}: [${record.code}] - ${record.name} `)
|
62
|
+
createdCounter++;
|
63
|
+
}
|
64
|
+
else {
|
65
|
+
const errorMsg = `Record campus already exists [${record.code}] - ${record.name} `;
|
66
|
+
if (!uniqueErrors.has(errorMsg)) {
|
67
|
+
logger.error(`${errorCounter + 1}/${errorCounter + 1}: ${errorMsg}`);
|
68
|
+
uniqueErrors.add(errorMsg);
|
69
|
+
errorCounter++;
|
70
|
+
}
|
71
|
+
|
72
|
+
}
|
73
|
+
|
74
|
+
} catch (error) {
|
75
|
+
console.error(error);
|
76
|
+
}
|
77
|
+
}
|
78
|
+
|
79
|
+
console.log("");
|
80
|
+
console.log("########################################################")
|
81
|
+
console.log("")
|
82
|
+
logger.info(' Campus Data Migration Completed');
|
83
|
+
logger.info(`Total successful Campus records created: ${createdCounter}/${createdCounter}`);
|
84
|
+
logger.info(`Total Campus Error Records: ${errorCounter}/${errorCounter}`);
|
85
|
+
console.log("")
|
86
|
+
console.log("########################################################")
|
87
|
+
console.log("")
|
88
|
+
|
89
|
+
let totalSummary = {
|
90
|
+
itemLength: campusApi.length,
|
91
|
+
error: errorCounter,
|
92
|
+
success: createdCounter
|
93
|
+
}
|
94
|
+
return totalSummary
|
95
|
+
|
96
|
+
} catch (error) {
|
97
|
+
console.error(error);
|
98
|
+
|
99
|
+
}
|
100
|
+
},
|
101
|
+
|
102
|
+
async College(){
|
103
|
+
try {
|
104
|
+
console.log("");
|
105
|
+
console.log("########################################################")
|
106
|
+
console.log(" Colleges Migration ")
|
107
|
+
console.log("########################################################")
|
108
|
+
console.log("");
|
109
|
+
|
110
|
+
const collegeApi = await api.College()
|
111
|
+
const campusApi = await api.Campus()
|
112
|
+
|
113
|
+
const campusSeq = await Campuses.findAll()
|
114
|
+
const userMail = await Users.findOne({ where: { email: 'ccci_integrator@gmail.com' } });
|
115
|
+
|
116
|
+
let createdCounter = 0
|
117
|
+
let errorCounter = 0
|
118
|
+
let uniqueErrors = new Set()
|
119
|
+
|
120
|
+
for (let i = 0; i < collegeApi.length; i++){
|
121
|
+
try {
|
122
|
+
let _college = collegeApi[i]
|
123
|
+
|
124
|
+
let campusMap = campusApi.find(a => a.id === _college?.campus_id)
|
125
|
+
|
126
|
+
let _campus = campusSeq.find(b => b.name === campusMap?.name)
|
127
|
+
|
128
|
+
let campusDefault = 999999
|
129
|
+
|
130
|
+
let modifiedById = userMail._id
|
131
|
+
let createdById = userMail._id
|
132
|
+
|
133
|
+
let [record, created] = await Colleges.findOrCreate({
|
134
|
+
|
135
|
+
where:{
|
136
|
+
name: _college?.name,
|
137
|
+
code: _college?.code
|
138
|
+
},
|
139
|
+
defaults:{
|
140
|
+
campusId: _campus?._id??campusDefault,
|
141
|
+
modifiedById,
|
142
|
+
createdById
|
143
|
+
}
|
144
|
+
})
|
145
|
+
if (created){
|
146
|
+
logger.info(`New college record created ${createdCounter + 1}/${createdCounter + 1}: [${record.code}] - ${record.name} `)
|
147
|
+
createdCounter++;
|
148
|
+
}
|
149
|
+
else {
|
150
|
+
const errorMsg = `Record college already exists: [${record.code}] - ${record.name} `
|
151
|
+
|
152
|
+
if (!uniqueErrors.has(errorMsg)) {
|
153
|
+
logger.error(`${errorCounter + 1}/${errorCounter + 1}: ${errorMsg}`);
|
154
|
+
uniqueErrors.add(errorMsg);
|
155
|
+
errorCounter++;
|
156
|
+
}
|
157
|
+
}
|
158
|
+
|
159
|
+
} catch (error) {
|
160
|
+
console.error(error);
|
161
|
+
}
|
162
|
+
}
|
163
|
+
|
164
|
+
console.log("");
|
165
|
+
console.log("########################################################")
|
166
|
+
console.log("")
|
167
|
+
logger.info(' College Data Migration Completed');
|
168
|
+
logger.info(`Total successful College records created: ${createdCounter}/${createdCounter}`);
|
169
|
+
logger.info(`Total College Error Records: ${errorCounter}/${errorCounter}`);
|
170
|
+
console.log("")
|
171
|
+
console.log("########################################################")
|
172
|
+
console.log("")
|
173
|
+
|
174
|
+
let totalSummary = {
|
175
|
+
itemLength: collegeApi.length,
|
176
|
+
error: errorCounter,
|
177
|
+
success: createdCounter
|
178
|
+
}
|
179
|
+
return totalSummary
|
180
|
+
|
181
|
+
} catch (error) {
|
182
|
+
console.error(error);
|
183
|
+
|
184
|
+
}
|
185
|
+
},
|
186
|
+
|
187
|
+
async AcademicDepartment(){
|
188
|
+
try {
|
189
|
+
console.log("");
|
190
|
+
console.log("########################################################")
|
191
|
+
console.log(" Academic Departments Migration ")
|
192
|
+
console.log("########################################################")
|
193
|
+
console.log("");
|
194
|
+
|
195
|
+
const departmentApi = await api.Department()
|
196
|
+
const campusApi = await api.Campus()
|
197
|
+
const collegeApi = await api.College()
|
198
|
+
|
199
|
+
|
200
|
+
const campusSeq = await Campuses.findAll()
|
201
|
+
const collegeSeq = await Colleges.findAll()
|
202
|
+
const userMail = await Users.findOne({ where: { email: 'ccci_integrator@gmail.com' } });
|
203
|
+
|
204
|
+
let createdCounter = 0
|
205
|
+
let errorCounter = 0
|
206
|
+
let uniqueErrors = new Set()
|
207
|
+
|
208
|
+
for (let i = 0; i < departmentApi.length; i++){
|
209
|
+
try {
|
210
|
+
let _acadDept = departmentApi[i]
|
211
|
+
|
212
|
+
|
213
|
+
let _college = collegeSeq.find( col => col.code === _acadDept?.code)
|
214
|
+
|
215
|
+
let college = collegeApi.find( cols => cols.code === _acadDept?.code)
|
216
|
+
|
217
|
+
let _campus = campusApi.find(cam => cam.id === college?.campus_id)
|
218
|
+
|
219
|
+
let campus = campusSeq.find(camp => camp.code === _campus?.code)
|
220
|
+
|
221
|
+
let campusDefault = 999999
|
222
|
+
let collegeDefault = 999999
|
223
|
+
let chairPersonDefault = 999999
|
224
|
+
|
225
|
+
let modifiedById = userMail._id
|
226
|
+
let createdById = userMail._id
|
227
|
+
|
228
|
+
|
229
|
+
let [record, created] = await AcademicDepartments.findOrCreate({
|
230
|
+
|
231
|
+
where:{
|
232
|
+
name: _acadDept?.name,
|
233
|
+
code: _acadDept?.code
|
234
|
+
},
|
235
|
+
defaults:{
|
236
|
+
collegeId: _college?._id??collegeDefault,
|
237
|
+
campusId: campus?._id??campusDefault,
|
238
|
+
chairPersonId: chairPersonDefault,
|
239
|
+
modifiedById,
|
240
|
+
createdById
|
241
|
+
}
|
242
|
+
})
|
243
|
+
if (created){
|
244
|
+
logger.info(`New academic department record created ${createdCounter + 1}/${createdCounter + 1}: [${record.code}] - ${record.name} `)
|
245
|
+
createdCounter++;
|
246
|
+
}
|
247
|
+
else {
|
248
|
+
const errorMsg = `Record academic department already exists [${record.code}] - ${record.name} `
|
249
|
+
|
250
|
+
if (!uniqueErrors.has(errorMsg)) {
|
251
|
+
logger.error(`${errorCounter + 1}/${errorCounter + 1}: ${errorMsg}`);
|
252
|
+
uniqueErrors.add(errorMsg);
|
253
|
+
errorCounter++;
|
254
|
+
}
|
255
|
+
|
256
|
+
}
|
257
|
+
|
258
|
+
} catch (error) {
|
259
|
+
console.error(error);
|
260
|
+
}
|
261
|
+
}
|
262
|
+
|
263
|
+
console.log("");
|
264
|
+
console.log("########################################################")
|
265
|
+
console.log("")
|
266
|
+
logger.info(' Academic Department Data Migration Completed');
|
267
|
+
logger.info(`Total successful Academic Department records created: ${createdCounter}/${createdCounter}`);
|
268
|
+
logger.info(`Total Academic Department Error Records: ${errorCounter}/${errorCounter}`);
|
269
|
+
console.log("")
|
270
|
+
console.log("########################################################")
|
271
|
+
console.log("")
|
272
|
+
|
273
|
+
let totalSummary = {
|
274
|
+
itemLength: departmentApi.length,
|
275
|
+
error: errorCounter,
|
276
|
+
success: createdCounter
|
277
|
+
}
|
278
|
+
return totalSummary
|
279
|
+
|
280
|
+
} catch (error) {
|
281
|
+
console.error(error);
|
282
|
+
|
283
|
+
}
|
284
|
+
},
|
285
|
+
|
286
|
+
async Course(){
|
287
|
+
try {
|
288
|
+
console.log("");
|
289
|
+
console.log("########################################################")
|
290
|
+
console.log(" Courses Migration ")
|
291
|
+
console.log("########################################################")
|
292
|
+
console.log("");
|
293
|
+
|
294
|
+
const studentApi = (await api.Student()).data
|
295
|
+
|
296
|
+
const courseApi = await api.Course()
|
297
|
+
const collegeApi = await api.College()
|
298
|
+
const departmentApi = await api.Department()
|
299
|
+
|
300
|
+
const acadDeptSeq = await AcademicDepartments.findAll()
|
301
|
+
|
302
|
+
const campusSeq = await Campuses.findAll()
|
303
|
+
const userMail = await Users.findOne({ where: { email: 'ccci_integrator@gmail.com' } });
|
304
|
+
|
305
|
+
let createdCounter = 0
|
306
|
+
let errorCounter = 0
|
307
|
+
let uniqueErrors = new Set()
|
308
|
+
|
309
|
+
for (let i = 0; i < studentApi.length; i++){
|
310
|
+
try {
|
311
|
+
|
312
|
+
let course = studentApi[i]
|
313
|
+
let courseCode = courseApi.find(crs => crs.name === course?.course)
|
314
|
+
let campus = campusSeq.find(camp => camp.name === course?.campus)
|
315
|
+
|
316
|
+
let college = collegeApi.find(col => col.name === course?.college)
|
317
|
+
let department = departmentApi.find(dep => dep.name === college?.name)
|
318
|
+
let _department = acadDeptSeq.find(ad => ad.name === department?.name)
|
319
|
+
|
320
|
+
|
321
|
+
|
322
|
+
|
323
|
+
|
324
|
+
let modifiedById = userMail._id
|
325
|
+
let createdById = userMail._id
|
326
|
+
|
327
|
+
|
328
|
+
let [record, created] = await Courses.findOrCreate({
|
329
|
+
where:{
|
330
|
+
name: course?.course,
|
331
|
+
code: courseCode?.code,
|
332
|
+
major: course?.major,
|
333
|
+
campusId: campus?._id??null,
|
334
|
+
departmentId: _department?._id??null,
|
335
|
+
modifiedById,
|
336
|
+
createdById
|
337
|
+
},
|
338
|
+
defaults:{
|
339
|
+
|
340
|
+
|
341
|
+
}
|
342
|
+
})
|
343
|
+
|
344
|
+
if (created) {
|
345
|
+
logger.info(`New course record created ${createdCounter +1}/${createdCounter +1}: [${record.code}] - ${record.name}, Major in ${record.major}`)
|
346
|
+
createdCounter++
|
347
|
+
} else {
|
348
|
+
|
349
|
+
const errorMsg = `Record course already exists [${record.code}] - ${record.name}, Major in ${record.major}`;
|
350
|
+
|
351
|
+
if (!uniqueErrors.has(errorMsg)) {
|
352
|
+
logger.error(`${errorCounter + 1}/${errorCounter + 1}: ${errorMsg}`);
|
353
|
+
uniqueErrors.add(errorMsg);
|
354
|
+
errorCounter++;
|
355
|
+
}
|
356
|
+
|
357
|
+
}
|
358
|
+
|
359
|
+
} catch (error) {
|
360
|
+
console.error(error);
|
361
|
+
}
|
362
|
+
}
|
363
|
+
|
364
|
+
|
365
|
+
console.log("");
|
366
|
+
console.log("########################################################")
|
367
|
+
console.log("")
|
368
|
+
logger.info(' Course Data Migration Completed');
|
369
|
+
logger.info(`Total successful Course records created: ${createdCounter}/${createdCounter}`);
|
370
|
+
logger.info(`Total Course Error Records: ${errorCounter}/${errorCounter}`);
|
371
|
+
console.log("")
|
372
|
+
console.log("########################################################")
|
373
|
+
console.log("")
|
374
|
+
|
375
|
+
let totalSummary = {
|
376
|
+
itemLength: courseApi.length,
|
377
|
+
error: errorCounter,
|
378
|
+
success: createdCounter
|
379
|
+
}
|
380
|
+
|
381
|
+
uniqueErrors.clear();
|
382
|
+
|
383
|
+
return totalSummary
|
384
|
+
|
385
|
+
} catch (error) {
|
386
|
+
console.error(error);
|
387
|
+
}
|
388
|
+
},
|
389
|
+
|
390
|
+
async Room(){
|
391
|
+
try {
|
392
|
+
console.log("");
|
393
|
+
console.log("########################################################")
|
394
|
+
console.log(" Rooms Migration ")
|
395
|
+
console.log("########################################################")
|
396
|
+
console.log("");
|
397
|
+
|
398
|
+
const subjectRoom = await api.Subject()
|
399
|
+
const roomApi = await api.Room()
|
400
|
+
|
401
|
+
const subjectSeq = await Subjects.findAll()
|
402
|
+
const campusSeq = await Campuses.findAll()
|
403
|
+
const departmentSeq = await AcademicDepartments.findAll()
|
404
|
+
|
405
|
+
const userMail = await Users.findOne({ where: { email: 'ccci_integrator@gmail.com' } });
|
406
|
+
|
407
|
+
let createdCounter = 0
|
408
|
+
let errorCounter = 0
|
409
|
+
let uniqueErrors = new Set()
|
410
|
+
|
411
|
+
for (let i = 0; i < roomApi.length; i++){
|
412
|
+
try {
|
413
|
+
let _room = roomApi[i]
|
414
|
+
|
415
|
+
let _subject = subjectRoom.find(r => r.room_id === _room?.id)
|
416
|
+
// console.log('_subject :>> ', _subject);
|
417
|
+
|
418
|
+
let _subjects = subjectSeq.find(s => s.name === _subject?.name)
|
419
|
+
// console.log('_subjects :>> ', _subjects);
|
420
|
+
|
421
|
+
|
422
|
+
let _department = departmentSeq.find(dep => dep._id === _subjects?.departmentId)
|
423
|
+
// console.log('_department :>> ', _department);
|
424
|
+
|
425
|
+
|
426
|
+
let _campus = campusSeq.find (cam => cam._id === _department?.campusId)
|
427
|
+
// console.log('_campus :>> ', _campus);
|
428
|
+
|
429
|
+
|
430
|
+
let capacity = 50
|
431
|
+
|
432
|
+
let campusDefault = "MSC - Boac Campus"
|
433
|
+
|
434
|
+
let _campusDefault = campusSeq.find(ccc => ccc.name === campusDefault)
|
435
|
+
|
436
|
+
// return console.log('campusDefault :>> ', campusDefault);
|
437
|
+
|
438
|
+
let modifiedById = userMail._id
|
439
|
+
let createdById = userMail._id
|
440
|
+
|
441
|
+
let [record, created] = await Rooms.findOrCreate({
|
442
|
+
where:{
|
443
|
+
name: _room?.name,
|
444
|
+
campusId: _campus?._id??_campusDefault?._id??null,
|
445
|
+
},
|
446
|
+
defaults:{
|
447
|
+
capacity,
|
448
|
+
modifiedById,
|
449
|
+
createdById
|
450
|
+
|
451
|
+
}
|
452
|
+
})
|
453
|
+
if (created){
|
454
|
+
logger.info(`New room record created ${createdCounter + 1}/${createdCounter + 1}: ${record.name} `)
|
455
|
+
createdCounter++;
|
456
|
+
}
|
457
|
+
else {
|
458
|
+
const errorMsg = `Record room already exists ${record.name}`;
|
459
|
+
|
460
|
+
if (!uniqueErrors.has(errorMsg)) {
|
461
|
+
logger.error(`${errorCounter + 1}/${errorCounter + 1}: ${errorMsg}`);
|
462
|
+
uniqueErrors.add(errorMsg);
|
463
|
+
errorCounter++;
|
464
|
+
}
|
465
|
+
|
466
|
+
}
|
467
|
+
|
468
|
+
} catch (error) {
|
469
|
+
console.error(error);
|
470
|
+
}
|
471
|
+
}
|
472
|
+
|
473
|
+
console.log("");
|
474
|
+
console.log("########################################################")
|
475
|
+
console.log("")
|
476
|
+
logger.info(' Room Data Migration Completed');
|
477
|
+
logger.info(`Total successful Room records created: ${createdCounter}/${createdCounter}`);
|
478
|
+
logger.info(`Total Room Error Records: ${errorCounter}/${errorCounter}`);
|
479
|
+
console.log("")
|
480
|
+
console.log("########################################################")
|
481
|
+
console.log("")
|
482
|
+
|
483
|
+
let totalSummary = {
|
484
|
+
itemLength: roomApi.length,
|
485
|
+
error: errorCounter,
|
486
|
+
success: createdCounter
|
487
|
+
}
|
488
|
+
return totalSummary
|
489
|
+
|
490
|
+
} catch (error) {
|
491
|
+
console.error(error);
|
492
|
+
|
493
|
+
}
|
494
|
+
},
|
495
|
+
|
496
|
+
async Instructor(){
|
497
|
+
try {
|
498
|
+
console.log("");
|
499
|
+
console.log("########################################################")
|
500
|
+
console.log(" Instructors Migration ")
|
501
|
+
console.log("########################################################")
|
502
|
+
console.log("");
|
503
|
+
|
504
|
+
const instructorApi = await api.Instructor()
|
505
|
+
const departmentApi = await api.Department()
|
506
|
+
|
507
|
+
const departmentSeq = await AcademicDepartments.findAll()
|
508
|
+
const campusSeq = await Campuses.findAll()
|
509
|
+
const userMail = await Users.findOne({ where: { email: 'ccci_integrator@gmail.com' } });
|
510
|
+
|
511
|
+
let createdCounter = 0
|
512
|
+
let errorCounter = 0
|
513
|
+
let uniqueErrors = new Set()
|
514
|
+
|
515
|
+
for (let i = 0; i < instructorApi.length; i++){
|
516
|
+
try {
|
517
|
+
let _instructor = instructorApi[i]
|
518
|
+
|
519
|
+
let acadDepartmentMap = departmentApi.find(a => a.name === _instructor?.department_name)
|
520
|
+
|
521
|
+
let _acadDepartment = departmentSeq.find(b => b.name === acadDepartmentMap?.name)
|
522
|
+
|
523
|
+
let campusMap = campusSeq.find(c => c._id === _acadDepartment?.campusId)
|
524
|
+
|
525
|
+
let academicDepartmentDefault = 999999
|
526
|
+
|
527
|
+
let modifiedById = userMail._id
|
528
|
+
let createdById = userMail._id
|
529
|
+
|
530
|
+
|
531
|
+
let campusDefault = "MSC - Boac Campus"
|
532
|
+
let _campusDefault = campusSeq.find(ccc => ccc.name === campusDefault)
|
533
|
+
|
534
|
+
let [record, created] = await Instructors.findOrCreate({
|
535
|
+
where:{
|
536
|
+
firstName: _instructor?.first_name,
|
537
|
+
lastName: _instructor?.last_name,
|
538
|
+
middleName: _instructor?.middle_name,
|
539
|
+
employeeNumber: _instructor?.faculty_id,
|
540
|
+
departmentId: _acadDepartment?._id??academicDepartmentDefault,
|
541
|
+
campusId: campusMap?._id??_campusDefault?._id,
|
542
|
+
modifiedById,
|
543
|
+
createdById,
|
544
|
+
// employeeId: record?._id??null,
|
545
|
+
|
546
|
+
|
547
|
+
},
|
548
|
+
defaults:{
|
549
|
+
|
550
|
+
}
|
551
|
+
})
|
552
|
+
if (created){
|
553
|
+
logger.info(`New instructor record created ${createdCounter + 1}/${createdCounter + 1}: [${record.employeeNumber}] - ${record.lastName}, ${record.firstName} `)
|
554
|
+
createdCounter++;
|
555
|
+
}
|
556
|
+
else {
|
557
|
+
const errorMsg = `Record instructor already exists [${record.employeeNumber}] - ${record.lastName}, ${record.firstName}`;
|
558
|
+
|
559
|
+
if (!uniqueErrors.has(errorMsg)) {
|
560
|
+
logger.error(`${errorCounter + 1}/${errorCounter + 1}: ${errorMsg}`);
|
561
|
+
uniqueErrors.add(errorMsg);
|
562
|
+
errorCounter++;
|
563
|
+
}
|
564
|
+
|
565
|
+
}
|
566
|
+
|
567
|
+
} catch (error) {
|
568
|
+
console.error(error);
|
569
|
+
}
|
570
|
+
}
|
571
|
+
|
572
|
+
console.log("");
|
573
|
+
console.log("########################################################")
|
574
|
+
console.log("")
|
575
|
+
logger.info(' Instructors Data Migration Completed');
|
576
|
+
logger.info(`Total successful Instructors records created: ${createdCounter}/${createdCounter}`);
|
577
|
+
logger.info(`Total Instructors Error Records: ${errorCounter}/${errorCounter}`);
|
578
|
+
console.log("")
|
579
|
+
console.log("########################################################")
|
580
|
+
console.log("")
|
581
|
+
|
582
|
+
let totalSummary = {
|
583
|
+
itemLength: instructorApi.length,
|
584
|
+
error: errorCounter,
|
585
|
+
success: createdCounter
|
586
|
+
}
|
587
|
+
return totalSummary
|
588
|
+
|
589
|
+
} catch (error) {
|
590
|
+
console.error(error);
|
591
|
+
|
592
|
+
}
|
593
|
+
},
|
594
|
+
|
595
|
+
async AcademicYear(){
|
596
|
+
try {
|
597
|
+
console.log("");
|
598
|
+
console.log("########################################################")
|
599
|
+
console.log(" Academic Years Migration ")
|
600
|
+
console.log("########################################################")
|
601
|
+
console.log("");
|
602
|
+
|
603
|
+
const acadYearApi = await api.AcademicYear()
|
604
|
+
const userMail = await Users.findOne({ where: { email: 'ccci_integrator@gmail.com' } });
|
605
|
+
|
606
|
+
let createdCounter = 0
|
607
|
+
let errorCounter = 0
|
608
|
+
let uniqueErrors = new Set()
|
609
|
+
|
610
|
+
const { acadYearResult, currentSchoolYear } = acadYearApi;
|
611
|
+
|
612
|
+
for (let i = 0; i < acadYearResult.length; i++){
|
613
|
+
try {
|
614
|
+
let _acadyear = acadYearResult[i]
|
615
|
+
// console.log('_acadyear :>> ', _acadyear);
|
616
|
+
|
617
|
+
let [from, to] = _acadyear.year.split('-')
|
618
|
+
|
619
|
+
to = /^\d+$/.test(to) ? parseInt(to, 10) : null;
|
620
|
+
from = /^\d+$/.test(from) ? parseInt(from, 10) : null;
|
621
|
+
|
622
|
+
let defaultDate = new Date()
|
623
|
+
let currentYear = defaultDate.getFullYear()
|
624
|
+
let previousYear = currentYear - 1
|
625
|
+
|
626
|
+
let isDefault = false
|
627
|
+
if(from == previousYear && to == currentYear) isDefault = true
|
628
|
+
|
629
|
+
let modifiedById = userMail._id
|
630
|
+
let createdById = userMail._id
|
631
|
+
|
632
|
+
let [record, created] = await AcademicYears.findOrCreate({
|
633
|
+
where:{
|
634
|
+
from,
|
635
|
+
to
|
636
|
+
},
|
637
|
+
defaults:{
|
638
|
+
modifiedById,
|
639
|
+
createdById,
|
640
|
+
default: isDefault
|
641
|
+
}
|
642
|
+
})
|
643
|
+
if (created){
|
644
|
+
logger.info(`New academic year record created ${createdCounter + 1}/${createdCounter + 1}: ${record.from} - ${record.to} `)
|
645
|
+
createdCounter++;
|
646
|
+
}
|
647
|
+
else {
|
648
|
+
const errorMsg = `Record academic year already exists ${record.from} - ${record.to}`;
|
649
|
+
if (!uniqueErrors.has(errorMsg)) {
|
650
|
+
logger.error(`${errorCounter + 1}/${errorCounter + 1}: ${errorMsg}`);
|
651
|
+
uniqueErrors.add(errorMsg);
|
652
|
+
errorCounter++;
|
653
|
+
}
|
654
|
+
}
|
655
|
+
|
656
|
+
} catch (error) {
|
657
|
+
console.error(error);
|
658
|
+
}
|
659
|
+
}
|
660
|
+
|
661
|
+
console.log("");
|
662
|
+
console.log("########################################################")
|
663
|
+
console.log("")
|
664
|
+
logger.info(' Academic Years Data Migration Completed');
|
665
|
+
logger.info(`Total successful Academic Years records created: ${createdCounter}/${createdCounter}`);
|
666
|
+
logger.info(`Total Academic Years Error Records: ${errorCounter}/${errorCounter}`);
|
667
|
+
console.log("")
|
668
|
+
console.log("########################################################")
|
669
|
+
console.log("")
|
670
|
+
|
671
|
+
let totalSummary = {
|
672
|
+
itemLength: acadYearResult.length,
|
673
|
+
error: errorCounter,
|
674
|
+
success: createdCounter
|
675
|
+
}
|
676
|
+
return totalSummary
|
677
|
+
|
678
|
+
} catch (error) {
|
679
|
+
console.error(error);
|
680
|
+
|
681
|
+
}
|
682
|
+
},
|
683
|
+
|
684
|
+
async Subject(){
|
685
|
+
try {
|
686
|
+
console.log("");
|
687
|
+
console.log("########################################################")
|
688
|
+
console.log(" Subjects Migration ")
|
689
|
+
console.log("########################################################")
|
690
|
+
console.log("");
|
691
|
+
|
692
|
+
const studentSubject = (await api.Student()).data
|
693
|
+
|
694
|
+
const subjectApi = await api.Subject()
|
695
|
+
|
696
|
+
const departmentSeq = await AcademicDepartments.findAll()
|
697
|
+
const userMail = await Users.findOne({ where: { email: 'ccci_integrator@gmail.com' } });
|
698
|
+
|
699
|
+
let createdCounter = 0
|
700
|
+
let errorCounter = 0
|
701
|
+
let uniqueErrors = new Set()
|
702
|
+
|
703
|
+
for (let i = 0; i < studentSubject.length; i++){
|
704
|
+
try {
|
705
|
+
let _subject = studentSubject[i]
|
706
|
+
|
707
|
+
let _department = departmentSeq.find(dep => dep.name === _subject?.college)
|
708
|
+
|
709
|
+
let _subs = studentSubject[i].subjects_enrolled;
|
710
|
+
|
711
|
+
|
712
|
+
for (let j = 0; j < _subs.length; j++){
|
713
|
+
|
714
|
+
let subject = _subs[j].subject_code
|
715
|
+
|
716
|
+
let _subjects = subjectApi.find(sub => sub.code === subject)
|
717
|
+
|
718
|
+
// return console.log('_subjects :>> ', _subjects);
|
719
|
+
|
720
|
+
|
721
|
+
if (!subject) {
|
722
|
+
// console.error(`Subject with code ${subjects} not found.`);
|
723
|
+
continue;
|
724
|
+
}
|
725
|
+
if (!_subjects) {
|
726
|
+
// console.error(`Subject with code ${subjects} not found.`);
|
727
|
+
continue;
|
728
|
+
}
|
729
|
+
let subjectType = "LECTURE"
|
730
|
+
let modifiedById = userMail._id
|
731
|
+
let createdById = userMail._id
|
732
|
+
|
733
|
+
|
734
|
+
|
735
|
+
let [record, created] = await Subjects.findOrCreate({
|
736
|
+
where:{
|
737
|
+
code:_subjects?.code,
|
738
|
+
name:_subjects?.name,
|
739
|
+
units:_subjects?.units,
|
740
|
+
departmentId: _department?._id,
|
741
|
+
subjectType,
|
742
|
+
modifiedById,
|
743
|
+
createdById
|
744
|
+
},
|
745
|
+
defaults:{
|
746
|
+
|
747
|
+
}
|
748
|
+
})
|
749
|
+
if (created){
|
750
|
+
logger.info(`New subject record created ${createdCounter + 1}/${createdCounter + 1}: [${record.code}], ${record.name} `)
|
751
|
+
createdCounter++;
|
752
|
+
}
|
753
|
+
else {
|
754
|
+
const errorMsg = `Record subject already exists [${record.code}], ${record.name}`;
|
755
|
+
|
756
|
+
if (!uniqueErrors.has(errorMsg)) {
|
757
|
+
logger.error(`${errorCounter + 1}/${errorCounter + 1}: ${errorMsg}`);
|
758
|
+
uniqueErrors.add(errorMsg);
|
759
|
+
errorCounter++;
|
760
|
+
}
|
761
|
+
}
|
762
|
+
}
|
763
|
+
|
764
|
+
|
765
|
+
} catch (error) {
|
766
|
+
console.error(error);
|
767
|
+
}
|
768
|
+
}
|
769
|
+
|
770
|
+
console.log("");
|
771
|
+
console.log("########################################################")
|
772
|
+
console.log("")
|
773
|
+
logger.info(' Subjects Data Migration Completed');
|
774
|
+
logger.info(`Total successful Subjects records created: ${createdCounter}/${createdCounter}`);
|
775
|
+
logger.info(`Total Subjects Error Records: ${errorCounter}/${errorCounter}`);
|
776
|
+
console.log("")
|
777
|
+
console.log("########################################################")
|
778
|
+
console.log("")
|
779
|
+
|
780
|
+
let totalSummary = {
|
781
|
+
itemLength: studentSubject.length,
|
782
|
+
error: errorCounter,
|
783
|
+
success: createdCounter
|
784
|
+
}
|
785
|
+
return totalSummary
|
786
|
+
|
787
|
+
} catch (error) {
|
788
|
+
console.error(error);
|
789
|
+
|
790
|
+
}
|
791
|
+
},
|
792
|
+
|
793
|
+
async Schedule(){
|
794
|
+
try {
|
795
|
+
console.log("");
|
796
|
+
console.log("########################################################")
|
797
|
+
console.log(" Schedules Migration ")
|
798
|
+
console.log("########################################################")
|
799
|
+
console.log("");
|
800
|
+
|
801
|
+
const scheduleApi = await api.Schedule()
|
802
|
+
const userMail = await Users.findOne({ where: { email: 'ccci_integrator@gmail.com' } });
|
803
|
+
|
804
|
+
let createdCounter = 0
|
805
|
+
let errorCounter = 0
|
806
|
+
let uniqueErrors = new Set()
|
807
|
+
|
808
|
+
for (let i = 0; i < scheduleApi.length; i++){
|
809
|
+
try {
|
810
|
+
let _schedule = scheduleApi[i]
|
811
|
+
|
812
|
+
const timeRegex = /(\d{1,2}:\d{2} [APMapm]{2}) - (\d{1,2}:\d{2} [APMapm]{2})/
|
813
|
+
const matchTime = _schedule.schedule.match(timeRegex)
|
814
|
+
|
815
|
+
if (!matchTime) {
|
816
|
+
// console.error(`Invalid schedule format, check the record:${_schedule.schedule}`);
|
817
|
+
continue;
|
818
|
+
}
|
819
|
+
|
820
|
+
const [_, startTime, endTime] = matchTime;
|
821
|
+
const stFormat = moment(startTime, 'h:mm A').format('HH:mm:ss')
|
822
|
+
const etFormat = moment(endTime, 'h:mm A').format('HH:mm:ss')
|
823
|
+
|
824
|
+
|
825
|
+
let dayHandler = _schedule.schedule.split(' ')
|
826
|
+
|
827
|
+
const dayMappings = {
|
828
|
+
'M': 'Monday',
|
829
|
+
'T': 'Tuesday',
|
830
|
+
'W': 'Wednesday',
|
831
|
+
'Th': 'Thursday',
|
832
|
+
'F': 'Friday',
|
833
|
+
'S': 'Saturday',
|
834
|
+
'Su': 'Sunday'
|
835
|
+
};
|
836
|
+
|
837
|
+
let modifiedById = userMail._id
|
838
|
+
let createdById = userMail._id
|
839
|
+
|
840
|
+
|
841
|
+
let from = null
|
842
|
+
let to = null
|
843
|
+
let days = null
|
844
|
+
|
845
|
+
if (dayHandler.length > 1) {
|
846
|
+
days = dayHandler[0].split('').map(day => dayMappings[day]).join(', ');
|
847
|
+
} else {
|
848
|
+
days = dayMappings[dayHandler[0]];
|
849
|
+
}
|
850
|
+
|
851
|
+
|
852
|
+
let [record, created] = await Schedules.findOrCreate({
|
853
|
+
where:{
|
854
|
+
name: _schedule?.schedule,
|
855
|
+
from : stFormat??from,
|
856
|
+
to : etFormat??to,
|
857
|
+
days
|
858
|
+
},
|
859
|
+
defaults:{
|
860
|
+
modifiedById,
|
861
|
+
createdById
|
862
|
+
}
|
863
|
+
})
|
864
|
+
if (created){
|
865
|
+
logger.info(`New schedule record created ${createdCounter + 1}/${createdCounter + 1}: [${record.from} - ${record.to}] ${record.name} `)
|
866
|
+
createdCounter++;
|
867
|
+
}
|
868
|
+
else {
|
869
|
+
const errorMsg = `Record schedule already exists [${record.from} - ${record.to}] ${record.name}`;
|
870
|
+
|
871
|
+
if (!uniqueErrors.has(errorMsg)) {
|
872
|
+
logger.error(`${errorCounter + 1}/${errorCounter + 1}: ${errorMsg}`);
|
873
|
+
uniqueErrors.add(errorMsg);
|
874
|
+
errorCounter++;
|
875
|
+
}
|
876
|
+
}
|
877
|
+
|
878
|
+
} catch (error) {
|
879
|
+
console.error(error);
|
880
|
+
}
|
881
|
+
}
|
882
|
+
|
883
|
+
console.log("");
|
884
|
+
console.log("########################################################")
|
885
|
+
console.log("")
|
886
|
+
logger.info(' Schedule Data Migration Completed');
|
887
|
+
logger.info(`Total successful Schedule records created: ${createdCounter}/${createdCounter}`);
|
888
|
+
logger.info(`Total Schedule Error Records: ${errorCounter}/${errorCounter}`);
|
889
|
+
console.log("")
|
890
|
+
console.log("########################################################")
|
891
|
+
console.log("")
|
892
|
+
|
893
|
+
let totalSummary = {
|
894
|
+
itemLength: scheduleApi.length,
|
895
|
+
error: errorCounter,
|
896
|
+
success: createdCounter
|
897
|
+
}
|
898
|
+
return totalSummary
|
899
|
+
|
900
|
+
} catch (error) {
|
901
|
+
console.error(error);
|
902
|
+
}
|
903
|
+
},
|
904
|
+
|
905
|
+
async Student(){
|
906
|
+
try {
|
907
|
+
console.log("");
|
908
|
+
console.log("########################################################")
|
909
|
+
console.log(" Students Migration ")
|
910
|
+
console.log("########################################################")
|
911
|
+
console.log("");
|
912
|
+
|
913
|
+
const studentApi = await api.Student()
|
914
|
+
|
915
|
+
const campusSeq = await Campuses.findAll()
|
916
|
+
const courseSeq = await Courses.findAll()
|
917
|
+
const collegeSeq = await Colleges.findAll()
|
918
|
+
const semesterSeq = await Semesters.findAll()
|
919
|
+
const acadYearSeq = await AcademicYears.findAll()
|
920
|
+
|
921
|
+
const userMail = await Users.findOne({ where: { email: 'ccci_integrator@gmail.com' } });
|
922
|
+
|
923
|
+
let createdCounter = 0
|
924
|
+
let errorCounter = 0
|
925
|
+
let uniqueErrors = new Set()
|
926
|
+
|
927
|
+
const emailDomain = 'default.msc.edu.ph';
|
928
|
+
|
929
|
+
|
930
|
+
const {data} = studentApi
|
931
|
+
for (let i = 0; i < data.length; i++){
|
932
|
+
try {
|
933
|
+
|
934
|
+
let _student = data[i]
|
935
|
+
|
936
|
+
|
937
|
+
let _campus = campusSeq.find(a => a.name === _student?.campus)
|
938
|
+
let _course = courseSeq.find(b => b.name === _student?.course)
|
939
|
+
let _college = collegeSeq.find(c => c.name === _student?.college)
|
940
|
+
|
941
|
+
const getLastName = _student?.last_name.toLowerCase().replace(/\s/g, '') ?? "";
|
942
|
+
|
943
|
+
let email = `${_student?.student_number}_${getLastName}@${emailDomain}`;
|
944
|
+
|
945
|
+
let modifiedById = userMail._id
|
946
|
+
let createdById = userMail._id
|
947
|
+
|
948
|
+
let campusDefault = 999999
|
949
|
+
let courseDefault = 999999
|
950
|
+
let collegeDefault = 999999
|
951
|
+
|
952
|
+
let semester = "2nd Semester"
|
953
|
+
let _semester = semesterSeq.find(sem => sem.code === semester)
|
954
|
+
|
955
|
+
let acadFrom = 2023
|
956
|
+
let acadTo = 2024
|
957
|
+
|
958
|
+
|
959
|
+
|
960
|
+
|
961
|
+
|
962
|
+
let _acadYear = acadYearSeq.find(yr => yr.from === acadFrom && yr.to === acadTo)
|
963
|
+
|
964
|
+
let [record, created] = await Students.findOrCreate({
|
965
|
+
where:{
|
966
|
+
studentNumber: _student?.student_number,
|
967
|
+
firstName: _student?.first_name,
|
968
|
+
lastName: _student?.last_name,
|
969
|
+
middleName: _student?.middle_name,
|
970
|
+
},
|
971
|
+
defaults:{
|
972
|
+
email: email,
|
973
|
+
courseId: _course?._id??courseDefault,
|
974
|
+
campusId: _campus?._id??campusDefault,
|
975
|
+
collegeId: _college?._id??collegeDefault,
|
976
|
+
admittedYearId: _acadYear?._id ?? null,
|
977
|
+
admittedSemId: _semester?._id ?? null,
|
978
|
+
modifiedById,
|
979
|
+
createdById
|
980
|
+
}
|
981
|
+
})
|
982
|
+
if (created){
|
983
|
+
logger.info(`New student record created ${createdCounter + 1}/${createdCounter + 1}: [${record.studentNumber}] ${record.lastName}, ${record.firstName} ${record.middleName} `)
|
984
|
+
createdCounter++;
|
985
|
+
}
|
986
|
+
else {
|
987
|
+
|
988
|
+
const errorMsg = `Record student already exists [${record.studentNumber}] ${record.lastName}, ${record.firstName} ${record.middleName}`;
|
989
|
+
|
990
|
+
if (!uniqueErrors.has(errorMsg)) {
|
991
|
+
logger.error(`${errorCounter + 1}/${errorCounter + 1}: ${errorMsg}`);
|
992
|
+
uniqueErrors.add(errorMsg);
|
993
|
+
errorCounter++;
|
994
|
+
}
|
995
|
+
|
996
|
+
}
|
997
|
+
|
998
|
+
} catch (error) {
|
999
|
+
console.error(error);
|
1000
|
+
}
|
1001
|
+
}
|
1002
|
+
|
1003
|
+
console.log("");
|
1004
|
+
console.log("########################################################")
|
1005
|
+
console.log("")
|
1006
|
+
logger.info(' Student Data Migration Completed');
|
1007
|
+
logger.info(`Total successful Student records created: ${createdCounter}/${createdCounter}`);
|
1008
|
+
logger.info(`Total Student Error Records: ${errorCounter}/${errorCounter}`);
|
1009
|
+
console.log("")
|
1010
|
+
console.log("########################################################")
|
1011
|
+
console.log("")
|
1012
|
+
|
1013
|
+
let totalSummary = {
|
1014
|
+
itemLength: data.length,
|
1015
|
+
error: errorCounter,
|
1016
|
+
success: createdCounter
|
1017
|
+
}
|
1018
|
+
return totalSummary
|
1019
|
+
|
1020
|
+
} catch (error) {
|
1021
|
+
console.error(error);
|
1022
|
+
|
1023
|
+
}
|
1024
|
+
},
|
1025
|
+
|
1026
|
+
async Section() {
|
1027
|
+
try {
|
1028
|
+
console.log("");
|
1029
|
+
console.log("########################################################");
|
1030
|
+
console.log(" Sections Migration ");
|
1031
|
+
console.log("########################################################");
|
1032
|
+
console.log("");
|
1033
|
+
|
1034
|
+
const student = (await api.Student()).data;
|
1035
|
+
|
1036
|
+
const subjectApi = await api.Subject();
|
1037
|
+
const instructorApi = await api.Instructor()
|
1038
|
+
|
1039
|
+
const subjectSeq = await Subjects.findAll();
|
1040
|
+
const instructorSeq = await Instructors.findAll()
|
1041
|
+
const courseSeq = await Courses.findAll()
|
1042
|
+
const campusSeq = await Campuses.findAll()
|
1043
|
+
const semesterSeq = await Semesters.findAll()
|
1044
|
+
const acadYearSeq = await AcademicYears.findAll()
|
1045
|
+
const acadDeptSeq = await AcademicDepartments.findAll()
|
1046
|
+
|
1047
|
+
|
1048
|
+
const userMail = await Users.findOne({ where: { email: 'ccci_integrator@gmail.com' } });
|
1049
|
+
|
1050
|
+
let createdCounter = 0
|
1051
|
+
let errorCounter = 0
|
1052
|
+
let uniqueErrors = new Set()
|
1053
|
+
|
1054
|
+
for (let i = 0; i < student.length; i++) {
|
1055
|
+
try {
|
1056
|
+
|
1057
|
+
let _sec = student[i]
|
1058
|
+
|
1059
|
+
let _course = courseSeq.find(crs => crs.name === _sec?.course)
|
1060
|
+
let _campus = campusSeq.find(cam => cam.name === _sec?.campus)
|
1061
|
+
let _section = student[i].subjects_enrolled;
|
1062
|
+
|
1063
|
+
|
1064
|
+
for (let j = 0; j < _section.length; j++) {
|
1065
|
+
let sections = _section[j].section_name
|
1066
|
+
let subjects = _section[j].subject_code;
|
1067
|
+
let instructors = _section[j].faculty_id
|
1068
|
+
|
1069
|
+
let _subject = subjectApi.find(sub => sub.code === subjects);
|
1070
|
+
|
1071
|
+
let _instructor = instructorApi.find( ins => ins.faculty_id === instructors)
|
1072
|
+
|
1073
|
+
let _subjects = subjectSeq.find( subs => subs.code === _subject?.code)
|
1074
|
+
|
1075
|
+
let _instructors = instructorSeq.find(inst => inst.employeeNumber === _instructor?.faculty_id)
|
1076
|
+
|
1077
|
+
let _insdepartment = acadDeptSeq.find(idep => idep.name === _instructor?.department_name)
|
1078
|
+
|
1079
|
+
|
1080
|
+
if (!_subject) {
|
1081
|
+
// console.error(`Subject with code ${subjects} not found.`);
|
1082
|
+
continue;
|
1083
|
+
}
|
1084
|
+
|
1085
|
+
if (!_instructor) {
|
1086
|
+
// console.error(`Instructor with faculty_id ${instructors} not found.`);
|
1087
|
+
continue;
|
1088
|
+
}
|
1089
|
+
|
1090
|
+
|
1091
|
+
|
1092
|
+
|
1093
|
+
let code = sections ?? 'CODE'
|
1094
|
+
code = code.split(/\s+/).map((word) => word.charAt(0).toUpperCase()).join('')
|
1095
|
+
|
1096
|
+
let semester = "2nd Semester"
|
1097
|
+
let _semester = semesterSeq.find(sem => sem.code === semester)
|
1098
|
+
|
1099
|
+
let acadFrom = 2023
|
1100
|
+
let acadTo = 2024
|
1101
|
+
|
1102
|
+
let _acadYear = acadYearSeq.find(yr => yr.from === acadFrom && yr.to === acadTo)
|
1103
|
+
|
1104
|
+
|
1105
|
+
let modifiedById = userMail._id;
|
1106
|
+
let createdById = userMail._id;
|
1107
|
+
|
1108
|
+
let defaultSub = 99999
|
1109
|
+
let defaultInst = 99999
|
1110
|
+
|
1111
|
+
let classType = 'SYNCHRONOUS'
|
1112
|
+
|
1113
|
+
let [record, created] = await Sections.findOrCreate({
|
1114
|
+
where: {
|
1115
|
+
name: sections,
|
1116
|
+
code,
|
1117
|
+
subjectId: _subjects?._id??defaultSub??null,
|
1118
|
+
instructorId: _instructors?._id??defaultInst??null,
|
1119
|
+
classType,
|
1120
|
+
semesterId: _semester?._id??null,
|
1121
|
+
academicYearId: _acadYear?._id??null,
|
1122
|
+
courseId: _course?._id??null,
|
1123
|
+
campusId: _campus?._id??null,
|
1124
|
+
departmentId: _insdepartment?._id??null,
|
1125
|
+
modifiedById,
|
1126
|
+
createdById,
|
1127
|
+
|
1128
|
+
},
|
1129
|
+
defaults: {
|
1130
|
+
// classType,
|
1131
|
+
// semesterId: _semester?._id??null,
|
1132
|
+
// academicYearId: _acadYear?._id??null,
|
1133
|
+
// courseId: _course?._id??null,
|
1134
|
+
// campusId: _campus?._id??null,
|
1135
|
+
// modifiedById,
|
1136
|
+
// createdById,
|
1137
|
+
}
|
1138
|
+
});
|
1139
|
+
|
1140
|
+
if (created) {
|
1141
|
+
logger.info(`New section record created ${createdCounter + 1}/${createdCounter + 1}: ${record.name} `);
|
1142
|
+
createdCounter++;
|
1143
|
+
} else {
|
1144
|
+
|
1145
|
+
const errorMsg = `Record section already exists ${record.name} `;
|
1146
|
+
|
1147
|
+
if (!uniqueErrors.has(errorMsg)) {
|
1148
|
+
logger.error(`${errorCounter + 1}/${errorCounter + 1}: ${errorMsg}`);
|
1149
|
+
uniqueErrors.add(errorMsg);
|
1150
|
+
errorCounter++;
|
1151
|
+
}
|
1152
|
+
}
|
1153
|
+
}
|
1154
|
+
} catch (error) {
|
1155
|
+
console.error(error);
|
1156
|
+
}
|
1157
|
+
}
|
1158
|
+
|
1159
|
+
console.log("");
|
1160
|
+
console.log("########################################################");
|
1161
|
+
console.log("");
|
1162
|
+
logger.info(' Section Data Migration Completed');
|
1163
|
+
logger.info(`Total successful Section records created: ${createdCounter}/${createdCounter}`);
|
1164
|
+
logger.info(`Total Section Error Records: ${errorCounter}/${errorCounter}`);
|
1165
|
+
console.log("");
|
1166
|
+
console.log("########################################################");
|
1167
|
+
console.log("");
|
1168
|
+
|
1169
|
+
let totalSummary = {
|
1170
|
+
itemLength: student.length,
|
1171
|
+
error: errorCounter,
|
1172
|
+
success: createdCounter
|
1173
|
+
};
|
1174
|
+
return totalSummary;
|
1175
|
+
|
1176
|
+
} catch (error) {
|
1177
|
+
console.error(error);
|
1178
|
+
}
|
1179
|
+
},
|
1180
|
+
|
1181
|
+
|
1182
|
+
async EnrolledStudent(){
|
1183
|
+
try {
|
1184
|
+
console.log("");
|
1185
|
+
console.log("########################################################")
|
1186
|
+
console.log(" Enrolled Students Migration ")
|
1187
|
+
console.log("########################################################")
|
1188
|
+
console.log("");
|
1189
|
+
|
1190
|
+
const studentApi = (await api.Student()).data
|
1191
|
+
|
1192
|
+
const sectionsApi = await api.Section()
|
1193
|
+
const instructorApi = await api.Instructor()
|
1194
|
+
|
1195
|
+
|
1196
|
+
const studentSeq = await Students.findAll()
|
1197
|
+
const courseSeq = await Courses.findAll()
|
1198
|
+
const campusSeq = await Campuses.findAll()
|
1199
|
+
const acadYearSeq = await AcademicYears.findAll()
|
1200
|
+
const semesterSeq = await Semesters.findAll()
|
1201
|
+
const sectionSeq = await Sections.findAll()
|
1202
|
+
const instructorSeq = await Instructors.findAll()
|
1203
|
+
|
1204
|
+
const userMail = await Users.findOne({ where: { email: 'ccci_integrator@gmail.com' } });
|
1205
|
+
|
1206
|
+
let createdCounter = 0
|
1207
|
+
let errorCounter = 0
|
1208
|
+
let uniqueErrors = new Set()
|
1209
|
+
|
1210
|
+
for (let i = 0; i < studentApi.length; i++){
|
1211
|
+
try {
|
1212
|
+
|
1213
|
+
let _student = studentApi[i]
|
1214
|
+
|
1215
|
+
let student = studentSeq.find(st => st.studentNumber === _student?.student_number)
|
1216
|
+
|
1217
|
+
let campus = campusSeq.find(ca => ca.name === _student?.campus)
|
1218
|
+
let course = courseSeq.find(cr => cr.name === _student?.course)
|
1219
|
+
|
1220
|
+
let _students = studentApi[i].subjects_enrolled
|
1221
|
+
|
1222
|
+
let semester = "2nd Semester"
|
1223
|
+
let _semester = semesterSeq.find(sem => sem.code === semester)
|
1224
|
+
|
1225
|
+
let acadFrom = 2023
|
1226
|
+
let acadTo = 2024
|
1227
|
+
let _acadYear = acadYearSeq.find(yr => yr.from === acadFrom && yr.to === acadTo)
|
1228
|
+
|
1229
|
+
let modifiedById = userMail._id;
|
1230
|
+
let createdById = userMail._id;
|
1231
|
+
|
1232
|
+
for (let j = 0; j < _students.length; j++){
|
1233
|
+
|
1234
|
+
let instrcutor = _students[j].faculty_id
|
1235
|
+
let sections = _students[j].section_name
|
1236
|
+
|
1237
|
+
let _inst = instructorApi.find(i => i.faculty_id === instrcutor)
|
1238
|
+
|
1239
|
+
|
1240
|
+
let _instructor = instructorSeq.find(ins => ins.employeeNumber === _inst?.faculty_id)
|
1241
|
+
|
1242
|
+
let _section = sectionSeq.find(sec => sec.name === sections)
|
1243
|
+
|
1244
|
+
|
1245
|
+
|
1246
|
+
if (!_inst) {
|
1247
|
+
continue;
|
1248
|
+
}
|
1249
|
+
|
1250
|
+
if (!_student) {
|
1251
|
+
continue;
|
1252
|
+
}
|
1253
|
+
|
1254
|
+
if (!student) {
|
1255
|
+
continue;
|
1256
|
+
}
|
1257
|
+
|
1258
|
+
|
1259
|
+
// return
|
1260
|
+
let [record, created] = await EnrolledStudents.findOrCreate({
|
1261
|
+
where:{
|
1262
|
+
studentId: student?._id,
|
1263
|
+
courseId: course?._id,
|
1264
|
+
instructorId: _instructor?._id??null,
|
1265
|
+
sectionId: _section?._id??null,
|
1266
|
+
campusId: campus?._id,
|
1267
|
+
academicYearId: _acadYear?._id,
|
1268
|
+
semesterId: _semester?._id,
|
1269
|
+
createdById,
|
1270
|
+
modifiedById,
|
1271
|
+
},
|
1272
|
+
default:{
|
1273
|
+
|
1274
|
+
}
|
1275
|
+
})
|
1276
|
+
|
1277
|
+
if (created) {
|
1278
|
+
logger.info(`New enrolled student record created ${createdCounter + 1}/${createdCounter + 1}: studentId = [${record.studentId}], sectionId = [${record.sectionId}], instructorId = [${record.instructorId}]`);
|
1279
|
+
createdCounter++;
|
1280
|
+
} else {
|
1281
|
+
|
1282
|
+
const errorMsg = `Record enrolled student already exists studentId = [${record.studentId}], sectionId = [${record.sectionId}], instructorId = [${record.instructorId}]`;
|
1283
|
+
|
1284
|
+
if (!uniqueErrors.has(errorMsg)) {
|
1285
|
+
logger.error(`${errorCounter + 1}/${errorCounter + 1}: ${errorMsg}`);
|
1286
|
+
uniqueErrors.add(errorMsg);
|
1287
|
+
errorCounter++;
|
1288
|
+
}
|
1289
|
+
}
|
1290
|
+
}
|
1291
|
+
} catch (error) {
|
1292
|
+
console.error(error);
|
1293
|
+
}
|
1294
|
+
}
|
1295
|
+
|
1296
|
+
console.log("");
|
1297
|
+
console.log("########################################################")
|
1298
|
+
console.log("")
|
1299
|
+
logger.info(' Enrolled Student Data Migration Completed');
|
1300
|
+
logger.info(`Total successful Enrolled Student records created: ${createdCounter}/${createdCounter}`);
|
1301
|
+
logger.info(`Total Enrolled Student Error Records: ${errorCounter}/${errorCounter}`);
|
1302
|
+
console.log("")
|
1303
|
+
console.log("########################################################")
|
1304
|
+
console.log("")
|
1305
|
+
|
1306
|
+
let totalSummary = {
|
1307
|
+
itemLength: studentApi.length,
|
1308
|
+
error: errorCounter,
|
1309
|
+
success: createdCounter
|
1310
|
+
}
|
1311
|
+
return totalSummary
|
1312
|
+
|
1313
|
+
} catch (error) {
|
1314
|
+
console.error(error);
|
1315
|
+
|
1316
|
+
}
|
1317
|
+
},
|
1318
|
+
|
1319
|
+
async executeAll(){
|
1320
|
+
await this.Campus()
|
1321
|
+
await this.College()
|
1322
|
+
await this.AcademicDepartment()
|
1323
|
+
await this.Course()
|
1324
|
+
await this.Room()
|
1325
|
+
await this.Instructor()
|
1326
|
+
await this.AcademicYear()
|
1327
|
+
await this.Subject()
|
1328
|
+
await this.Schedule()
|
1329
|
+
await this.Student()
|
1330
|
+
await this.Section()
|
1331
|
+
await this.EnrolledStudent()
|
1332
|
+
|
1333
|
+
}
|
1334
|
+
}
|
1335
|
+
|
1336
|
+
|
1337
|
+
module.exports = server
|