lms-sync 1.0.15 → 1.0.17

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.
@@ -32,8 +32,6 @@ const server = {
32
32
  console.log("########################################################")
33
33
  console.log("");
34
34
 
35
- const campusApi = await api.Campus()
36
-
37
35
  let userDefPayload = {
38
36
  email: 'ccci_integrator@gmail.com',
39
37
  password: '$2a$12$Q.h3Q9IN6vsIxGBa/EgfOOABeXTcwxt4t9cu4nqAK.nczGRRtZJUS',
@@ -48,6 +46,51 @@ const server = {
48
46
  });
49
47
 
50
48
  const userMail = await Users.findOne({ where: { email: 'ccci_integrator@gmail.com' } });
49
+
50
+ let semesterData = [
51
+ {
52
+ code: '1st Semester',
53
+ description: '1st Semester',
54
+ modifiedById: userMail._id,
55
+ createdById: userMail._id
56
+ },
57
+ {
58
+ code: '2nd Semester',
59
+ description: '2nd Semester',
60
+ modifiedById: userMail._id,
61
+ createdById: userMail._id
62
+ },
63
+ {
64
+ code: 'Summer',
65
+ description: 'Summer',
66
+ modifiedById: userMail._id,
67
+ createdById: userMail._id
68
+ },
69
+ {
70
+ code: 'School Year',
71
+ description: 'School Year',
72
+ modifiedById: userMail._id,
73
+ createdById: userMail._id
74
+ }
75
+ ]
76
+
77
+ for (let sem = 0; sem < semesterData.length; sem++) {
78
+ const semesters = semesterData[sem];
79
+
80
+ let semestersPayload = {
81
+ code: semesters.code,
82
+ description: semesters.description,
83
+ modifiedById: userMail._id,
84
+ createdById: userMail._id
85
+ }
86
+
87
+ let [semdefaults, semcreateddef] = await Semesters.findOrCreate({
88
+ where: { code: semestersPayload.code},
89
+ defaults: semestersPayload
90
+ });
91
+ }
92
+
93
+ const campusApi = await api.Campus()
51
94
 
52
95
  let campusDefPayload = {
53
96
  name: 'Campus Default',
@@ -68,14 +111,9 @@ const server = {
68
111
  let uniqueErrors = new Set()
69
112
 
70
113
  const db_schema = schema
71
- // let maxIds = await Campuses.max('_id'); = await Campuses.max('_id'); // Fetch maximum _id directly from the campuses model
72
- // let maxId = maxIds|| 0;
73
- // await db.sequelize.query(`ALTER SEQUENCE ${db_schema}."Campuses__id_seq" RESTART WITH ${maxId + 1}`);
74
-
75
- // let migratedAt = new Date() //present date of the migration
76
- // let migratedTable = 'campuses' // sql counterpart main table
77
- // let referenceId = campusApi.id // id of the data
78
- // let isMigrated = true
114
+ let maxIds = await Campuses.max('_id'); //Fetch maximum _id directly from the campuses model
115
+ let maxId = maxIds|| 0;
116
+ await db.sequelize.query(`ALTER SEQUENCE ${db_schema}."Campuses__id_seq" RESTART WITH ${maxId + 1}`);
79
117
 
80
118
  let uCode = new Set()
81
119
  let uName = new Set()
@@ -204,9 +242,9 @@ const server = {
204
242
  let uniqueErrors = new Set()
205
243
 
206
244
  const db_schema = schema
207
- // let maxIds = await Campuses.max('_id'); = await Colleges.max('_id'); // Fetch maximum _id directly from the Colleges model
208
- // let maxId = maxIds|| 0;
209
- // await db.sequelize.query(`ALTER SEQUENCE ${db_schema}."Colleges__id_seq" RESTART WITH ${maxId + 1}`);
245
+ let maxIds = await Colleges.max('_id'); // Fetch maximum _id directly from the Colleges model
246
+ let maxId = maxIds|| 0;
247
+ await db.sequelize.query(`ALTER SEQUENCE ${db_schema}."Colleges__id_seq" RESTART WITH ${maxId + 1}`);
210
248
 
211
249
  // let migratedAt = new Date() //present date of the migration
212
250
  // let migratedTable = 'colleges' // sql counterpart main table
@@ -347,9 +385,9 @@ const server = {
347
385
  let uniqueErrors = new Set()
348
386
 
349
387
  const db_schema = schema
350
- // let maxIds = await Campuses.max('_id'); = await AcademicDepartments.max('_id'); // Fetch maximum _id directly from the AcademicDepartments model
351
- // let maxId = maxIds|| 0;
352
- // await db.sequelize.query(`ALTER SEQUENCE ${db_schema}."AcademicDepartments__id_seq" RESTART WITH ${maxId + 1}`);
388
+ let maxIds = await AcademicDepartments.max('_id'); // Fetch maximum _id directly from the AcademicDepartments model
389
+ let maxId = maxIds|| 0;
390
+ await db.sequelize.query(`ALTER SEQUENCE ${db_schema}."AcademicDepartments__id_seq" RESTART WITH ${maxId + 1}`);
353
391
 
354
392
  let uCode = new Set()
355
393
  let uName = new Set()
@@ -549,9 +587,9 @@ const server = {
549
587
 
550
588
 
551
589
  const db_schema = schema
552
- // let maxIds = await Campuses.max('_id'); = await Instructors.max('_id'); // Fetch maximum _id directly from the Instructors model
553
- // let maxId = maxIds|| 0;
554
- // await db.sequelize.query(`ALTER SEQUENCE ${db_schema}."Instructors__id_seq" RESTART WITH ${maxId + 1}`);
590
+ let maxIds = await Instructors.max('_id'); //Fetch maximum _id directly from the Instructors model
591
+ let maxId = maxIds|| 0;
592
+ await db.sequelize.query(`ALTER SEQUENCE ${db_schema}."Instructors__id_seq" RESTART WITH ${maxId + 1}`);
555
593
 
556
594
  let uDept = new Set()
557
595
  let uCamp = new Set()
@@ -724,9 +762,9 @@ const server = {
724
762
  let uniqueErrors = new Set()
725
763
 
726
764
  const db_schema = schema
727
- // let maxIds = await Campuses.max('_id'); = await Courses.max('_id'); // Fetch maximum _id directly from the Courses model
728
- // let maxId = maxIds|| 0;
729
- // await db.sequelize.query(`ALTER SEQUENCE ${db_schema}."Courses__id_seq" RESTART WITH ${maxId + 1}`);
765
+ let maxIds = await Courses.max('_id'); //Fetch maximum _id directly from the Courses model
766
+ let maxId = maxIds|| 0;
767
+ await db.sequelize.query(`ALTER SEQUENCE ${db_schema}."Courses__id_seq" RESTART WITH ${maxId + 1}`);
730
768
 
731
769
 
732
770
  let uCode = new Set()
@@ -876,9 +914,9 @@ const server = {
876
914
 
877
915
 
878
916
  const db_schema = schema
879
- // let maxIds = await Campuses.max('_id'); = await Rooms.max('_id'); // Fetch maximum _id directly from the Rooms model
880
- // let maxId = maxIds|| 0;
881
- // await db.sequelize.query(`ALTER SEQUENCE ${db_schema}."Rooms__id_seq" RESTART WITH ${maxId + 1}`);
917
+ let maxIds = await Rooms.max('_id'); // Fetch maximum _id directly from the Rooms model
918
+ let maxId = maxIds|| 0;
919
+ await db.sequelize.query(`ALTER SEQUENCE ${db_schema}."Rooms__id_seq" RESTART WITH ${maxId + 1}`);
882
920
 
883
921
  let uName = new Set()
884
922
  let uCampus = new Set()
@@ -996,9 +1034,9 @@ const server = {
996
1034
  const { acadYearResult, currentSchoolYear } = acadYearApi;
997
1035
 
998
1036
  const db_schema = schema
999
- // let maxIds = await Campuses.max('_id'); = await AcademicYears.max('_id'); // Fetch maximum _id directly from the AcademicYears model
1000
- // let maxId = maxIds|| 0;
1001
- // await db.sequelize.query(`ALTER SEQUENCE ${db_schema}."AcademicYears__id_seq" RESTART WITH ${maxId + 1}`);
1037
+ let maxIds = await AcademicYears.max('_id'); // Fetch maximum _id directly from the AcademicYears model
1038
+ let maxId = maxIds|| 0;
1039
+ await db.sequelize.query(`ALTER SEQUENCE ${db_schema}."AcademicYears__id_seq" RESTART WITH ${maxId + 1}`);
1002
1040
 
1003
1041
  let uFrom = new Set()
1004
1042
  let uTo = new Set()
@@ -1136,19 +1174,20 @@ const server = {
1136
1174
  let uniqueErrors = new Set()
1137
1175
 
1138
1176
  const db_schema = schema
1139
- // let maxIds = await Campuses.max('_id'); = await Subjects.max('_id'); // Fetch maximum _id directly from the Subjects model
1140
- // let maxId = maxIds|| 0;
1141
- // await db.sequelize.query(`ALTER SEQUENCE ${db_schema}."Subjects__id_seq" RESTART WITH ${maxId + 1}`);
1177
+ let maxIds = await Subjects.max('_id'); // Fetch maximum _id directly from the Subjects model
1178
+ let maxId = maxIds|| 0;
1179
+ await db.sequelize.query(`ALTER SEQUENCE ${db_schema}."Subjects__id_seq" RESTART WITH ${maxId + 1}`);
1142
1180
 
1143
1181
  let uCode = new Set()
1144
1182
  let uName = new Set()
1145
1183
  let uUnits = new Set()
1146
1184
  let uDept = new Set()
1185
+ let uDescription = new Set()
1147
1186
 
1148
1187
  let newSubject = []
1149
1188
 
1150
1189
  const exSubj = await Subjects.findAll()
1151
- const exSubjMap = new Map(exSubj.map(subj => [`[${subj.code}] - ${subj.name} [${subj.units}, ${subj.departmentId}]`, subj]))
1190
+ const exSubjMap = new Map(exSubj.map(subj => [`[${subj.code}] - ${subj.name} ${subj.description} [${subj.units}, ${subj.departmentId}]`, subj]))
1152
1191
 
1153
1192
  for (let i = 0; i < studentSubject.length; i++){
1154
1193
  try {
@@ -1161,6 +1200,7 @@ const server = {
1161
1200
  for (let j = 0; j < _subs.length; j++){
1162
1201
 
1163
1202
  let subject = _subs[j].subject_code
1203
+ let _description = _subs[j]. subject_description
1164
1204
 
1165
1205
  let _subjects = subjectApi.find(sub => sub.code === subject)
1166
1206
 
@@ -1178,8 +1218,9 @@ const server = {
1178
1218
  let name =_subjects?.name
1179
1219
  let units =_subjects?.units
1180
1220
  let departmentId = _department?._id??departmentDefault?._id
1221
+ let description = _description
1181
1222
 
1182
- if(uCode.has(code) && uName.has(name) && uUnits.has(units) && uDept.has(departmentId)){
1223
+ if(uCode.has(code) && uName.has(name) && uDescription.has(description) && uUnits.has(units) && uDept.has(departmentId)){
1183
1224
  const errorMsg = `Duplicate Payload Found: [${code}] - ${name} [units: ${units}, departmentId: ${departmentId}]`
1184
1225
  if(!uniqueErrors.has(errorMsg)){
1185
1226
  logger.error(`${errorCounter + 1}/${errorCounter + 1}: ${errorMsg}`)
@@ -1187,8 +1228,8 @@ const server = {
1187
1228
  errorCounter++
1188
1229
  }
1189
1230
  }
1190
- else if ( exSubjMap.has(`[${code}] - ${name} [${units}, ${departmentId}]`)){
1191
- const exSubj = exSubjMap.get(`[${code}] - ${name} [${units}, ${departmentId}]`)
1231
+ else if ( exSubjMap.has(`[${code}] - ${name} ${description} [${units}, ${departmentId}]`)){
1232
+ const exSubj = exSubjMap.get(`[${code}] - ${name} ${description} [${units}, ${departmentId}]`)
1192
1233
  const errorMsg = `Existing Data Found: [${exSubj.code}] - ${exSubj.name} [units: ${exSubj.units}, departmentId: ${exSubj.departmentId}]`
1193
1234
  if(!uniqueErrors.has(errorMsg)){
1194
1235
  logger.error(`${errorCounter + 1}/${errorCounter + 1}: ${errorMsg}`)
@@ -1201,12 +1242,14 @@ const server = {
1201
1242
  uName.add(name)
1202
1243
  uUnits.add(units)
1203
1244
  uDept.add(departmentId)
1245
+ uDescription.add(description)
1204
1246
  newSubject.push({
1205
1247
  code:_subjects?.code,
1206
1248
  name:_subjects?.name,
1207
1249
  units:_subjects?.units,
1208
1250
  departmentId: _department?._id??departmentDefault?._id,
1209
1251
  subjectType,
1252
+ description,
1210
1253
  modifiedById,
1211
1254
  createdById,
1212
1255
  // migratedAt,
@@ -1275,9 +1318,9 @@ const server = {
1275
1318
 
1276
1319
 
1277
1320
  const db_schema = schema
1278
- // let maxIds = await Campuses.max('_id'); = await Schedules.max('_id'); // Fetch maximum _id directly from the Schedules model
1279
- // let maxId = maxIds|| 0;
1280
- // await db.sequelize.query(`ALTER SEQUENCE ${db_schema}."Schedules__id_seq" RESTART WITH ${maxId + 1}`);
1321
+ let maxIds = await Schedules.max('_id'); // Fetch maximum _id directly from the Schedules model
1322
+ let maxId = maxIds|| 0;
1323
+ await db.sequelize.query(`ALTER SEQUENCE ${db_schema}."Schedules__id_seq" RESTART WITH ${maxId + 1}`);
1281
1324
 
1282
1325
 
1283
1326
  let uName = new Set()
@@ -1428,9 +1471,9 @@ const server = {
1428
1471
  const acadYearSeq = await AcademicYears.findAll()
1429
1472
 
1430
1473
  const userMail = await Users.findOne({ where: { email: 'ccci_integrator@gmail.com' } });
1431
- const campusDefault = await Users.findOne({ where: { name: 'Campus Default' } });
1432
- const courseDefault = await Users.findOne({ where: { name: 'Course Default' } });
1433
- const collegeDefault = await Users.findOne({ where: { name: 'Colleges Default' } });
1474
+ const campusDefault = await Campuses.findOne({ where: { name: 'Campus Default' } });
1475
+ const courseDefault = await Courses.findOne({ where: { name: 'Course Default' } });
1476
+ const collegeDefault = await Colleges.findOne({ where: { name: 'Colleges Default' } });
1434
1477
 
1435
1478
  let createdCounter = 0
1436
1479
  let errorCounter = 0
@@ -1439,9 +1482,9 @@ const server = {
1439
1482
  const emailDomain = 'default.msc.edu.ph';
1440
1483
 
1441
1484
  const db_schema = schema
1442
- // let maxIds = await Campuses.max('_id'); = await Students.max('_id'); // Fetch maximum _id directly from the Students model
1443
- // let maxId = maxIds|| 0;
1444
- // await db.sequelize.query(`ALTER SEQUENCE ${db_schema}."Students__id_seq" RESTART WITH ${maxId + 1}`);
1485
+ let maxIds = await Students.max('_id'); // Fetch maximum _id directly from the Students model
1486
+ let maxId = maxIds|| 0;
1487
+ await db.sequelize.query(`ALTER SEQUENCE ${db_schema}."Students__id_seq" RESTART WITH ${maxId + 1}`);
1445
1488
 
1446
1489
 
1447
1490
  let uNum = new Set()
@@ -1491,7 +1534,7 @@ const server = {
1491
1534
  let campusId = _campus?._id??campusDefault?._id
1492
1535
 
1493
1536
  if(uNum.has(studentNumber) && uLname.has(lastName) && uFname.has(firstName) && uMname.has(middleName) && uCourse.has(courseId) && uCampus.has(campusId)){
1494
- const errorMsg = `Duplicate Payload Found: [${studentNumber}] - ${lastName}, ${firstName} ${middleName} [${courseId}, ${campusId}]`
1537
+ const errorMsg = `Duplicate Payload Found: [${studentNumber}] - ${lastName}, ${firstName} ${middleName} [courseId: ${courseId}, campusId:${campusId}]`
1495
1538
  if(!uniqueErrors.has(errorMsg)){
1496
1539
  logger.error(`${errorCounter + 1}/${errorCounter + 1}: ${errorMsg}`)
1497
1540
  uniqueErrors.add(errorMsg)
@@ -1500,7 +1543,7 @@ const server = {
1500
1543
  }
1501
1544
  else if ( exStudentMap.has(`[${studentNumber}] - ${lastName}, ${firstName} ${middleName} [${courseId}, ${campusId}]`)){
1502
1545
  const exStudent = exStudentMap.get(`[${studentNumber}] - ${lastName}, ${firstName} ${middleName} [${courseId}, ${campusId}]`)
1503
- const errorMsg = `Existing Data Found:[${exStudent.studentNumber}] - ${exStudent.lastName}, ${exStudent.firstName} ${exStudent.middleName} [${exStudent.courseId}, ${exStudent.campusId}]`
1546
+ const errorMsg = `Existing Data Found:[${exStudent.studentNumber}] - ${exStudent.lastName}, ${exStudent.firstName} ${exStudent.middleName} [courseId: ${exStudent.courseId}, campusId: ${exStudent.campusId}]`
1504
1547
  if(!uniqueErrors.has(errorMsg)){
1505
1548
  logger.error(`${errorCounter + 1}/${errorCounter + 1}: ${errorMsg}`)
1506
1549
  uniqueErrors.add(errorMsg)
@@ -1540,7 +1583,7 @@ const server = {
1540
1583
  createdCounter += newStudent.length
1541
1584
 
1542
1585
  newStudent.forEach((exStudent, index) => {
1543
- logger.info(`${index + 1}/${index + 1}: New Student Record Created: [${exStudent.studentNumber}] - ${exStudent.lastName}, ${exStudent.firstName} ${exStudent.middleName} [${exStudent.courseId}, ${exStudent.campusId}]`)
1586
+ logger.info(`${index + 1}/${index + 1}: New Student Record Created: [${exStudent.studentNumber}] - ${exStudent.lastName}, ${exStudent.firstName} ${exStudent.middleName} [courseId: ${exStudent.courseId}, campusId: ${exStudent.campusId}]`)
1544
1587
  });
1545
1588
  }
1546
1589
 
@@ -1563,7 +1606,6 @@ const server = {
1563
1606
  return totalSummary
1564
1607
 
1565
1608
  } catch (error) {
1566
- ;
1567
1609
  logger.error(`Error occurred: ${error.stack} ${error}`);
1568
1610
 
1569
1611
  }
@@ -1598,9 +1640,9 @@ const server = {
1598
1640
 
1599
1641
 
1600
1642
  const db_schema = schema
1601
- // let maxIds = await Campuses.max('_id'); = await Sections.max('_id'); // Fetch maximum _id directly from the Sections model
1602
- // let maxId = maxIds|| 0;
1603
- // await db.sequelize.query(`ALTER SEQUENCE ${db_schema}."Sections__id_seq" RESTART WITH ${maxId + 1}`);
1643
+ let maxIds = await Sections.max('_id'); // Fetch maximum _id directly from the Sections model
1644
+ let maxId = maxIds|| 0;
1645
+ await db.sequelize.query(`ALTER SEQUENCE ${db_schema}."Sections__id_seq" RESTART WITH ${maxId + 1}`);
1604
1646
 
1605
1647
  let uName = new Set()
1606
1648
  let uCode = new Set()
@@ -1679,7 +1721,7 @@ const server = {
1679
1721
 
1680
1722
 
1681
1723
  if(uCode.has(code) && uName.has(name) && uSub.has(subjectId) && uIns.has(instructorId) && uSem.has(semesterId) && uYear.has(academicYearId)&& uCrs.has(courseId)&& uDept.has(departmentId) && uCam.has(campusId)){
1682
- const errorMsg = `Duplicate Payload Found: [${code}] - ${name}`
1724
+ const errorMsg = `Duplicate Payload Found: [${code}] - ${name} [subjectId: ${subjectId}, instructorId: ${instructorId}]`
1683
1725
  if(!uniqueErrors.has(errorMsg)){
1684
1726
  logger.error(`${errorCounter + 1}/${errorCounter + 1}: ${errorMsg}`)
1685
1727
  uniqueErrors.add(errorMsg)
@@ -1688,7 +1730,7 @@ const server = {
1688
1730
  }
1689
1731
  else if ( exSectMap.has(`[${code}] - ${name} [${subjectId}, ${instructorId}, ${semesterId}, ${academicYearId}, ${courseId}, ${departmentId}, ${campusId}]`)){
1690
1732
  const exSect = exSectMap.get(`[${code}] - ${name} [${subjectId}, ${instructorId}, ${semesterId}, ${academicYearId}, ${courseId}, ${departmentId}, ${campusId}]`)
1691
- const errorMsg = `Existing Data Found:[${exSect.code}] - ${exSect.name}`
1733
+ const errorMsg = `Existing Data Found:[${exSect.code}] - ${exSect.name} [subjectId: ${exSect.subjectId}, instructorId: ${exSect.instructorId}]`
1692
1734
  if(!uniqueErrors.has(errorMsg)){
1693
1735
  logger.error(`${errorCounter + 1}/${errorCounter + 1}: ${errorMsg}`)
1694
1736
  uniqueErrors.add(errorMsg)
@@ -1733,9 +1775,21 @@ const server = {
1733
1775
  createdCounter += newSection.length
1734
1776
 
1735
1777
  newSection.forEach((sect, index) => {
1736
- logger.info(`${index + 1}/${index + 1}: New Section Record Created: [${sect.code}] - ${sect.name}`)
1778
+ logger.info(`${index + 1}/${index + 1}: New Section Record Created: [${sect.code}] - ${sect.name} [subjectId: ${sect.subjectId}, instructorId: ${sect.instructorId}]`)
1737
1779
  });
1738
1780
  }
1781
+
1782
+
1783
+ // let batchSize = 500
1784
+ // for (let i = 0; i < newSection.length; i += batchSize){
1785
+ // const batch = newSection.slice(i, i + batchSize)
1786
+ // await Sections.bulkCreate(batch)
1787
+ // createdCounter += batch.length
1788
+ // batch.forEach((sect, index) => {
1789
+ // logger.info(`${index + 1}/${index + 1}: New Section Record Created: [${sect.code}] - ${sect.name}`)
1790
+ // })
1791
+ // }
1792
+
1739
1793
 
1740
1794
  console.log("");
1741
1795
  console.log("########################################################");
@@ -1761,8 +1815,7 @@ const server = {
1761
1815
  }
1762
1816
  },
1763
1817
 
1764
-
1765
- async EnrolledStudent(){
1818
+ async EnrolledStudentss(){
1766
1819
  try {
1767
1820
  console.log("");
1768
1821
  console.log("########################################################")
@@ -1780,6 +1833,7 @@ const server = {
1780
1833
  const semesterSeq = await Semesters.findAll()
1781
1834
  const sectionSeq = await Sections.findAll()
1782
1835
  const instructorSeq = await Instructors.findAll()
1836
+ const subjectSeq = await Subjects.findAll()
1783
1837
 
1784
1838
  const userMail = await Users.findOne({ where: { email: 'ccci_integrator@gmail.com' } });
1785
1839
 
@@ -1787,13 +1841,11 @@ const server = {
1787
1841
  let errorCounter = 0
1788
1842
  let uniqueErrors = new Set()
1789
1843
 
1790
-
1791
1844
  const db_schema = schema
1792
- // let maxIds = await Campuses.max('_id'); = await EnrolledStudents.max('_id'); // Fetch maximum _id directly from the EnrolledStudents model
1793
- // let maxId = maxIds|| 0;
1794
- // await db.sequelize.query(`ALTER SEQUENCE ${db_schema}."EnrolledStudents__id_seq" RESTART WITH ${maxId + 1}`);
1845
+ let maxIds = await EnrolledStudents.max('_id'); // Fetch maximum _id directly from the EnrolledStudents model
1846
+ let maxId = maxIds|| 0;
1847
+ await db.sequelize.query(`ALTER SEQUENCE ${db_schema}."EnrolledStudents__id_seq" RESTART WITH ${maxId + 1}`);
1795
1848
 
1796
-
1797
1849
  let uStud = new Set()
1798
1850
  let uCrs = new Set()
1799
1851
  let uIns = new Set()
@@ -1802,23 +1854,20 @@ const server = {
1802
1854
  let uYear = new Set()
1803
1855
  let uSem = new Set()
1804
1856
  let uGrade = new Set()
1857
+ let uRemarks = new Set()
1858
+ let uAllStat = new Set()
1805
1859
 
1806
1860
  let newEnroll = []
1807
1861
 
1808
- const exEnroll = await EnrolledStudents.findAll()
1809
- const exEnrollMap = new Map(exEnroll.map(student => [`[${student.studentId}] - [${student.courseId}, ${student.instructorId}, ${student.sectionId}, ${student.campusId}, ${student.academicYearId}, ${student.academicYearId}, ${student.semesterId}, ${student.finalGrade}]`, student]))
1862
+ const existings = await EnrolledStudents.findAll()
1863
+ const existingEnrolledMap = new Map(existings.map(enroll => [`[${enroll.studentId} ${enroll.instructorId} ${enroll.sectionId}] ${enroll.finalGrade} ${enroll.remarks} ${enroll.overAllStatus}`, enroll]))
1810
1864
 
1811
-
1812
1865
  for (let i = 0; i < studentApi.length; i++){
1813
1866
  try {
1814
-
1815
1867
  let _student = studentApi[i]
1816
-
1817
1868
  let student = studentSeq.find(st => st.studentNumber === _student?.student_number)
1818
-
1819
1869
  let campus = campusSeq.find(ca => ca.name === _student?.campus)
1820
1870
  let course = courseSeq.find(cr => cr.name === _student?.course)
1821
-
1822
1871
  let _students = studentApi[i].subjects_enrolled
1823
1872
 
1824
1873
  let fromPrompts = await Picked()
@@ -1829,23 +1878,17 @@ const server = {
1829
1878
  let _semester = semesterSeq.find(sem => sem.code === semester)
1830
1879
  let _acadYear = acadYearSeq.find(yr => yr.from === parseInt(yearsFrom) && yr.to === parseInt(yearsTo))
1831
1880
 
1832
-
1833
1881
  let modifiedById = userMail._id;
1834
1882
  let createdById = userMail._id;
1835
1883
 
1836
1884
  for (let j = 0; j < _students.length; j++){
1837
-
1838
1885
  let instrcutor = _students[j].faculty_id
1839
1886
  let sections = _students[j].section_name
1840
1887
  let fGrade = _students[j].final_grade
1841
1888
  let rmarks = _students[j].remarks
1842
-
1843
-
1889
+
1844
1890
  let _inst = instructorApi.find(i => i.faculty_id === instrcutor)
1845
-
1846
-
1847
1891
  let _instructor = instructorSeq.find(ins => ins.employeeNumber === _inst?.faculty_id)
1848
-
1849
1892
  let _section = sectionSeq.find(sec => sec.name === sections)
1850
1893
 
1851
1894
 
@@ -1861,17 +1904,52 @@ const server = {
1861
1904
  continue;
1862
1905
  }
1863
1906
 
1864
- let totalPoints = 100
1907
+ let overAllStatus = null
1865
1908
  let finalG = fGrade
1866
- let gradePoints = ((-4.0 / totalPoints) * parseFloat (finalG) + 5.0).toFixed(2)
1909
+
1867
1910
  let graded = false
1868
- if (gradePoints){
1911
+ if (finalG){
1869
1912
  graded = true
1870
1913
  }
1871
- else if (!gradePoints){
1872
- gradePoints = 0
1873
- }
1914
+ else if (!finalG){
1915
+ finalG = 0
1916
+ }
1917
+
1874
1918
  let remarks = rmarks?.toUpperCase()??null
1919
+ if (remarks === 'INCOMPLETE'){
1920
+ finalG = 0
1921
+ overAllStatus = "INC"
1922
+ }
1923
+ else if (remarks === 'UNOFFICIALLY DROPPED'){
1924
+ finalG = 0
1925
+ overAllStatus = "UD"
1926
+ }
1927
+ else if (remarks === 'UNAUTHORIZED WITHDRAWAL'){
1928
+ finalG = 0
1929
+ overAllStatus = "UW"
1930
+ }
1931
+ else if (remarks === 'DROPPED'){
1932
+ finalG = 0
1933
+ overAllStatus = "DRP"
1934
+ }
1935
+ else if (remarks === 'NO CREDIT'){
1936
+ finalG = 0
1937
+ overAllStatus = "IN-PROG"
1938
+ }
1939
+ else if (remarks === 'CREDITED'){
1940
+ finalG = 0
1941
+ overAllStatus = "UD"
1942
+ }
1943
+ else if (remarks === 'PASSED'){
1944
+ overAllStatus = "PASSED"
1945
+ }
1946
+ else if (!remarks){
1947
+ finalG = 0
1948
+ }
1949
+ if(finalG === 5.00){
1950
+ remarks = "FAILED"
1951
+ overAllStatus = "FAILED"
1952
+ }
1875
1953
 
1876
1954
  let studentId = student?._id
1877
1955
  let courseId = course?._id
@@ -1880,19 +1958,19 @@ const server = {
1880
1958
  let campusId = campus?._id
1881
1959
  let academicYearId = _acadYear?._id
1882
1960
  let semesterId = _semester?._id
1883
- let finalGrade = gradePoints
1961
+ let finalGrade = finalG
1884
1962
 
1885
- if(uStud.has(studentId) && uCrs.has(courseId) && uIns.has(instructorId) && uSec.has(sectionId) && uCam.has(campusId) && uYear.has(academicYearId) && uSem.has(semesterId) && uGrade.has(finalGrade)){
1886
- const errorMsg = `Duplicate Payload Found: [${studentId}] - [${courseId}, ${instructorId}, ${sectionId}, ${campusId}, ${academicYearId}, ${academicYearId}, ${semesterId}, ${finalGrade}]`
1963
+ if(uStud.has(studentId) && uIns.has(instructorId) && uSec.has(sectionId) && uGrade.has(finalGrade) && uRemarks.has(remarks) && uAllStat.has(overAllStatus)){
1964
+ const errorMsg = `Duplicate Payload Found: [${studentId}] - [${courseId}, ${instructorId}, ${sectionId}] = ${finalGrade}, ${remarks}, ${overAllStatus}`
1887
1965
  if(!uniqueErrors.has(errorMsg)){
1888
1966
  logger.error(`${errorCounter + 1}/${errorCounter + 1}: ${errorMsg}`)
1889
1967
  uniqueErrors.add(errorMsg)
1890
1968
  errorCounter++
1891
1969
  }
1892
1970
  }
1893
- else if ( exEnrollMap.has(`[${studentId}] - [${courseId}, ${instructorId}, ${sectionId}, ${campusId}, ${academicYearId}, ${academicYearId}, ${semesterId}, ${finalGrade}]`)){
1894
- const exEnroll = exEnrollMap.get(`[${studentId}] - [${courseId}, ${instructorId}, ${sectionId}, ${campusId}, ${academicYearId}, ${academicYearId}, ${semesterId}, ${finalGrade}]`)
1895
- const errorMsg = `Existing Data Found: [${exEnroll.exEnrollId}] - [${exEnroll.courseId}, ${exEnroll.instructorId}, ${exEnroll.sectionId}, ${exEnroll.campusId}, ${exEnroll.academicYearId}, ${exEnroll.academicYearId}, ${exEnroll.semesterId}, ${exEnroll.finalGrade}]`
1971
+ else if (existingEnrolledMap.has(`[${studentId} ${instructorId} ${sectionId} ${finalGrade}] ${remarks} ${overAllStatus}`)){
1972
+ const existings = existingEnrolledMap.get(`[${studentId} ${instructorId} ${sectionId} ${finalGrade}] ${remarks} ${overAllStatus}`)
1973
+ const errorMsg = `Existing Data Found: [${existings.studentId}] - [${existings.courseId}, ${existings.instructorId}, ${existings.sectionId}] = ${existings.finalGrade}, ${existings.remarks}, ${existings.overAllStatus}`
1896
1974
  if(!uniqueErrors.has(errorMsg)){
1897
1975
  logger.error(`${errorCounter + 1}/${errorCounter + 1}: ${errorMsg}`)
1898
1976
  uniqueErrors.add(errorMsg)
@@ -1908,6 +1986,8 @@ const server = {
1908
1986
  uYear.add(academicYearId)
1909
1987
  uSem.add(semesterId)
1910
1988
  uGrade.add(finalGrade)
1989
+ uAllStat.add(overAllStatus)
1990
+ uRemarks.add(remarks)
1911
1991
  newEnroll.push({
1912
1992
  studentId: student?._id,
1913
1993
  courseId: course?._id,
@@ -1916,8 +1996,9 @@ const server = {
1916
1996
  campusId: campus?._id,
1917
1997
  academicYearId: _acadYear?._id,
1918
1998
  semesterId: _semester?._id,
1919
- finalGrade: gradePoints,
1999
+ finalGrade: finalG,
1920
2000
  graded,
2001
+ overAllStatus,
1921
2002
  remarks,
1922
2003
  createdById,
1923
2004
  modifiedById,
@@ -1925,17 +2006,16 @@ const server = {
1925
2006
  }
1926
2007
  }
1927
2008
  } catch (error) {
1928
- ;
1929
2009
  logger.error(`Error occurred: ${error.stack} ${error}`);
1930
2010
  }
1931
2011
  }
1932
2012
 
1933
2013
  if (newEnroll.length > 0) {
1934
- await Sections.bulkCreate(newEnroll)
2014
+ await EnrolledStudents.bulkCreate(newEnroll)
1935
2015
  createdCounter += newEnroll.length
1936
2016
 
1937
2017
  newEnroll.forEach((es, index) => {
1938
- logger.info(`${index + 1}/${index + 1}: New Section Record Created: [${es.studentId}] - [${es.courseId}, ${es.instructorId}, ${es.sectionId}, ${es.campusId}, ${es.academicYearId}, ${es.academicYearId}, ${es.semesterId}, ${es.finalGrade}]`)
2018
+ logger.info(`${index + 1}/${index + 1}: New Enrolled Students Record Created: [${es.studentId}] - [${es.courseId}, ${es.instructorId}, ${es.sectionId}] = ${es.finalGrade}, ${es.remarks}, ${es.overAllStatus}`)
1939
2019
  });
1940
2020
  }
1941
2021
 
@@ -1958,11 +2038,208 @@ const server = {
1958
2038
  return totalSummary
1959
2039
 
1960
2040
  } catch (error) {
1961
- ;
1962
2041
  logger.error(`Error occurred: ${error.stack} ${error}`);
1963
2042
 
1964
2043
  }
1965
2044
  },
2045
+
2046
+ async EnrolledStudent(){
2047
+ try {
2048
+ console.log("");
2049
+ console.log("########################################################")
2050
+ console.log(" Enrolled Students Migration ")
2051
+ console.log("########################################################")
2052
+ console.log("");
2053
+
2054
+ const studentApi = (await api.Student()).data
2055
+ const instructorApi = await api.Instructor()
2056
+
2057
+ const studentSeq = await Students.findAll()
2058
+ const courseSeq = await Courses.findAll()
2059
+ const campusSeq = await Campuses.findAll()
2060
+ const acadYearSeq = await AcademicYears.findAll()
2061
+ const semesterSeq = await Semesters.findAll()
2062
+ const sectionSeq = await Sections.findAll()
2063
+ const instructorSeq = await Instructors.findAll()
2064
+
2065
+ const userMail = await Users.findOne({ where: { email: 'ccci_integrator@gmail.com' } });
2066
+
2067
+ let createdCounter = 0
2068
+ let errorCounter = 0
2069
+ let uniqueErrors = new Set()
2070
+
2071
+
2072
+ let maxIds = await EnrolledStudents.max('_id'); // Fetch maximum _id directly from the EnrolledStudents model
2073
+ let maxId = maxIds|| 0;
2074
+ await db.sequelize.query(`ALTER SEQUENCE public_migrations."EnrolledStudents__id_seq" RESTART WITH ${maxId + 1}`);
2075
+
2076
+
2077
+ for (let i = 0; i < studentApi.length; i++){
2078
+ try {
2079
+
2080
+ let _student = studentApi[i]
2081
+
2082
+ let student = studentSeq.find(st => st.studentNumber === _student?.student_number)
2083
+
2084
+ let campus = campusSeq.find(ca => ca.name === _student?.campus)
2085
+ let course = courseSeq.find(cr => cr.name === _student?.course)
2086
+
2087
+ let _students = studentApi[i].subjects_enrolled
2088
+
2089
+ let fromPrompts = await Picked()
2090
+
2091
+ let semester = fromPrompts.semester
2092
+ let yearsFrom = fromPrompts.yearFrom
2093
+ let yearsTo = fromPrompts.yearTo
2094
+ let _semester = semesterSeq.find(sem => sem.code === semester)
2095
+ let _acadYear = acadYearSeq.find(yr => yr.from === parseInt(yearsFrom) && yr.to === parseInt(yearsTo))
2096
+
2097
+
2098
+ let modifiedById = userMail._id;
2099
+ let createdById = userMail._id;
2100
+
2101
+ for (let j = 0; j < _students.length; j++){
2102
+
2103
+ let instrcutor = _students[j].faculty_id
2104
+ let sections = _students[j].section_name
2105
+ let fGrade = _students[j].final_grade
2106
+ let rmarks = _students[j].remarks
2107
+
2108
+
2109
+ let _inst = instructorApi.find(i => i.faculty_id === instrcutor)
2110
+
2111
+
2112
+ let _instructor = instructorSeq.find(ins => ins.employeeNumber === _inst?.faculty_id)
2113
+
2114
+ let _section = sectionSeq.find(sec => sec.name === sections)
2115
+
2116
+
2117
+ if (!_inst) {
2118
+ continue;
2119
+ }
2120
+
2121
+ if (!_student) {
2122
+ continue;
2123
+ }
2124
+
2125
+ if (!student) {
2126
+ continue;
2127
+ }
2128
+
2129
+ let overAllStatus = null
2130
+ let finalG = fGrade
2131
+
2132
+ // let totalPoints = 100
2133
+ // let finalG = fGrade
2134
+ // let gradePoints = ((-4.0 / totalPoints) * parseFloat (finalG) + 5.0).toFixed(2)
2135
+
2136
+ let graded = false
2137
+ if (finalG){
2138
+ graded = true
2139
+ }
2140
+ else if (!finalG){
2141
+ finalG = 0
2142
+ }
2143
+
2144
+ let remarks = rmarks?.toUpperCase()??null
2145
+ if (remarks === 'INCOMPLETE'){
2146
+ finalG = 0
2147
+ overAllStatus = "INC"
2148
+ }
2149
+ else if (remarks === 'UNOFFICIALLY DROPPED'){
2150
+ finalG = 0
2151
+ overAllStatus = "UD"
2152
+ }
2153
+ else if (remarks === 'UNAUTHORIZED WITHDRAWAL'){
2154
+ finalG = 0
2155
+ overAllStatus = "UW"
2156
+ }
2157
+ else if (remarks === 'DROPPED'){
2158
+ finalG = 0
2159
+ overAllStatus = "DRP"
2160
+ }
2161
+ else if (remarks === 'NO CREDIT'){
2162
+ finalG = 0
2163
+ overAllStatus = "IN-PROG"
2164
+ }
2165
+ else if (remarks === 'CREDITED'){
2166
+ finalG = 0
2167
+ overAllStatus = "UD"
2168
+ }
2169
+ else if (remarks === 'PASSED'){
2170
+ overAllStatus = "PASSED"
2171
+ }
2172
+ else if (!remarks){
2173
+ finalG = 0
2174
+ }
2175
+ if(finalG === 5.00){
2176
+ remarks = "FAILED"
2177
+ overAllStatus = "FAILED"
2178
+ }
2179
+ // return
2180
+ let [record, created] = await EnrolledStudents.findOrCreate({
2181
+ where:{
2182
+ studentId: student?._id,
2183
+ courseId: course?._id,
2184
+ instructorId: _instructor?._id??null,
2185
+ sectionId: _section?._id??null,
2186
+ campusId: campus?._id,
2187
+ academicYearId: _acadYear?._id,
2188
+ semesterId: _semester?._id,
2189
+ finalGrade: finalG,
2190
+ graded,
2191
+ remarks,
2192
+ overAllStatus,
2193
+ createdById,
2194
+ modifiedById,
2195
+ },
2196
+ default:{
2197
+
2198
+ }
2199
+ })
2200
+
2201
+ if (created) {
2202
+ logger.info(`${createdCounter + 1}/${createdCounter + 1}: New Enrolled Students Record Created: [${record.studentId}] - [${record.courseId}, ${record.instructorId}, ${record.sectionId}] = ${record.finalGrade}, ${record.remarks}, ${record.overAllStatus}`)
2203
+ createdCounter++;
2204
+ } else {
2205
+
2206
+ const errorMsg = `Record enrolled student already exists: studentId = [${record.studentId}] - [${record.courseId}, ${record.instructorId}, ${record.sectionId}] = ${record.finalGrade}, ${record.remarks}, ${record.overAllStatus}`;
2207
+
2208
+ if (!uniqueErrors.has(errorMsg)) {
2209
+ logger.error(`${errorCounter + 1}/${errorCounter + 1} ${errorMsg}`);
2210
+ uniqueErrors.add(errorMsg);
2211
+ errorCounter++;
2212
+ }
2213
+ }
2214
+ }
2215
+ } catch (error) {
2216
+ console.error(error);
2217
+ }
2218
+ }
2219
+
2220
+ console.log("");
2221
+ console.log("########################################################")
2222
+ console.log("")
2223
+ logger.info(' Enrolled Student Data Migration Completed');
2224
+ logger.info(`Total successful Enrolled Student records created: ${createdCounter}/${createdCounter}`);
2225
+ logger.info(`Total Enrolled Student Error Records: ${errorCounter}/${errorCounter}`);
2226
+ console.log("")
2227
+ console.log("########################################################")
2228
+ console.log("")
2229
+
2230
+ let totalSummary = {
2231
+ itemLength: studentApi.length,
2232
+ error: errorCounter,
2233
+ success: createdCounter
2234
+ }
2235
+ return totalSummary
2236
+
2237
+ } catch (error) {
2238
+ console.error(error);
2239
+
2240
+ }
2241
+ },
2242
+
1966
2243
  }
1967
2244
 
1968
2245
  async function runServerFunctions() {