@eeplatform/basic-edu 1.10.1 → 1.10.3
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/CHANGELOG.md +12 -0
- package/dist/index.d.ts +30 -3
- package/dist/index.js +334 -74
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +334 -74
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -39352,6 +39352,7 @@ var schemaSection = Joi31.object({
|
|
|
39352
39352
|
_id: Joi31.string().hex().optional().allow(null, ""),
|
|
39353
39353
|
school: Joi31.string().hex().required(),
|
|
39354
39354
|
name: Joi31.string().min(1).max(100).required(),
|
|
39355
|
+
label: Joi31.string().max(100).optional().allow(null, ""),
|
|
39355
39356
|
schoolYear: Joi31.string().required(),
|
|
39356
39357
|
gradeLevel: Joi31.string().required(),
|
|
39357
39358
|
students: Joi31.number().integer().min(0).optional(),
|
|
@@ -39368,8 +39369,7 @@ var schemaGenerateSections = Joi31.object({
|
|
|
39368
39369
|
gradeLevel: Joi31.string().required(),
|
|
39369
39370
|
minStudents: Joi31.number().integer().min(1).required(),
|
|
39370
39371
|
maxStudents: Joi31.number().integer().min(Joi31.ref("minStudents")).required(),
|
|
39371
|
-
specialProgram: Joi31.string().hex().optional().allow(null, "")
|
|
39372
|
-
set: Joi31.array().items(Joi31.string().min(1).max(100)).required()
|
|
39372
|
+
specialProgram: Joi31.string().hex().optional().allow(null, "")
|
|
39373
39373
|
});
|
|
39374
39374
|
function modelSection(value) {
|
|
39375
39375
|
const { error } = schemaSection.validate(value);
|
|
@@ -39401,6 +39401,7 @@ function modelSection(value) {
|
|
|
39401
39401
|
_id: value._id,
|
|
39402
39402
|
school: value.school,
|
|
39403
39403
|
name: value.name,
|
|
39404
|
+
label: value.label ?? "",
|
|
39404
39405
|
schoolYear: value.schoolYear,
|
|
39405
39406
|
gradeLevel: value.gradeLevel,
|
|
39406
39407
|
adviser: value.adviser,
|
|
@@ -39444,7 +39445,7 @@ function useSectionRepo() {
|
|
|
39444
39445
|
{ key: { createdAt: 1 } },
|
|
39445
39446
|
{ key: { name: "text", schoolYear: "text", gradeLevel: "text" } },
|
|
39446
39447
|
{
|
|
39447
|
-
key: { school: 1,
|
|
39448
|
+
key: { school: 1, teacher: 1, schoolYear: 1, status: 1 },
|
|
39448
39449
|
unique: true,
|
|
39449
39450
|
name: "unique_section"
|
|
39450
39451
|
}
|
|
@@ -39471,7 +39472,7 @@ function useSectionRepo() {
|
|
|
39471
39472
|
value = modelSection(value);
|
|
39472
39473
|
const res = await collection.insertOne(value, { session });
|
|
39473
39474
|
delCachedData();
|
|
39474
|
-
return res.insertedId;
|
|
39475
|
+
return res.insertedId.toString();
|
|
39475
39476
|
} catch (error) {
|
|
39476
39477
|
logger27.log({
|
|
39477
39478
|
level: "error",
|
|
@@ -39612,6 +39613,54 @@ function useSectionRepo() {
|
|
|
39612
39613
|
}
|
|
39613
39614
|
}
|
|
39614
39615
|
}
|
|
39616
|
+
async function getSection(options) {
|
|
39617
|
+
const query = {};
|
|
39618
|
+
const cacheKeyOptions = { tag: "getSection" };
|
|
39619
|
+
try {
|
|
39620
|
+
query.school = new ObjectId30(options.school);
|
|
39621
|
+
cacheKeyOptions.school = String(options.school);
|
|
39622
|
+
} catch (error) {
|
|
39623
|
+
throw new BadRequestError49("Invalid school ID.");
|
|
39624
|
+
}
|
|
39625
|
+
query.gradeLevel = options.gradeLevel;
|
|
39626
|
+
cacheKeyOptions.gradeLevel = options.gradeLevel;
|
|
39627
|
+
query.name = options.name;
|
|
39628
|
+
cacheKeyOptions.name = options.name;
|
|
39629
|
+
if (options.schoolYear) {
|
|
39630
|
+
query.schoolYear = options.schoolYear;
|
|
39631
|
+
cacheKeyOptions.schoolYear = options.schoolYear;
|
|
39632
|
+
}
|
|
39633
|
+
const cacheKey = makeCacheKey16(namespace_collection, cacheKeyOptions);
|
|
39634
|
+
try {
|
|
39635
|
+
const cached = await getCache(cacheKey);
|
|
39636
|
+
if (cached) {
|
|
39637
|
+
logger27.log({
|
|
39638
|
+
level: "info",
|
|
39639
|
+
message: `Cache hit for getSection: ${cacheKey}`
|
|
39640
|
+
});
|
|
39641
|
+
return cached;
|
|
39642
|
+
}
|
|
39643
|
+
const result = await collection.findOne(query);
|
|
39644
|
+
setCache(cacheKey, result, 300).then(() => {
|
|
39645
|
+
logger27.log({
|
|
39646
|
+
level: "info",
|
|
39647
|
+
message: `Cache set for section: ${cacheKey}`
|
|
39648
|
+
});
|
|
39649
|
+
}).catch((err) => {
|
|
39650
|
+
logger27.log({
|
|
39651
|
+
level: "error",
|
|
39652
|
+
message: `Failed to set cache for section: ${err.message}`
|
|
39653
|
+
});
|
|
39654
|
+
});
|
|
39655
|
+
return result;
|
|
39656
|
+
} catch (error) {
|
|
39657
|
+
if (error instanceof AppError17) {
|
|
39658
|
+
throw error;
|
|
39659
|
+
} else {
|
|
39660
|
+
throw new InternalServerError14("Failed to get section.");
|
|
39661
|
+
}
|
|
39662
|
+
}
|
|
39663
|
+
}
|
|
39615
39664
|
async function getByName(name) {
|
|
39616
39665
|
const cacheKey = makeCacheKey16(namespace_collection, { name });
|
|
39617
39666
|
try {
|
|
@@ -39795,6 +39844,7 @@ function useSectionRepo() {
|
|
|
39795
39844
|
add,
|
|
39796
39845
|
getAll,
|
|
39797
39846
|
getById,
|
|
39847
|
+
getSection,
|
|
39798
39848
|
getByName,
|
|
39799
39849
|
getBySchool,
|
|
39800
39850
|
updateFieldById,
|
|
@@ -40053,11 +40103,73 @@ function useSectionStudentRepo() {
|
|
|
40053
40103
|
});
|
|
40054
40104
|
return data;
|
|
40055
40105
|
}
|
|
40106
|
+
async function getStudent(options) {
|
|
40107
|
+
const query = {};
|
|
40108
|
+
const cacheKeyOptions = { tag: "getStudent" };
|
|
40109
|
+
if (options.learner) {
|
|
40110
|
+
try {
|
|
40111
|
+
query.learner = new ObjectId32(options.learner);
|
|
40112
|
+
cacheKeyOptions.learner = String(options.learner);
|
|
40113
|
+
} catch (error) {
|
|
40114
|
+
throw new BadRequestError51("Invalid learner ID.");
|
|
40115
|
+
}
|
|
40116
|
+
}
|
|
40117
|
+
if (options.schoolYear) {
|
|
40118
|
+
query.schoolYear = options.schoolYear;
|
|
40119
|
+
cacheKeyOptions.schoolYear = options.schoolYear;
|
|
40120
|
+
}
|
|
40121
|
+
if (options.section) {
|
|
40122
|
+
try {
|
|
40123
|
+
query.section = new ObjectId32(options.section);
|
|
40124
|
+
cacheKeyOptions.section = String(options.section);
|
|
40125
|
+
} catch (error) {
|
|
40126
|
+
throw new BadRequestError51("Invalid section ID.");
|
|
40127
|
+
}
|
|
40128
|
+
}
|
|
40129
|
+
if (options.gradeLevel) {
|
|
40130
|
+
query.gradeLevel = options.gradeLevel;
|
|
40131
|
+
cacheKeyOptions.gradeLevel = options.gradeLevel;
|
|
40132
|
+
}
|
|
40133
|
+
try {
|
|
40134
|
+
query.student = new ObjectId32(options.student);
|
|
40135
|
+
cacheKeyOptions.student = String(options.student);
|
|
40136
|
+
} catch (error) {
|
|
40137
|
+
throw new BadRequestError51("Invalid student ID.");
|
|
40138
|
+
}
|
|
40139
|
+
const cacheKey = makeCacheKey17(namespace_collection, cacheKeyOptions);
|
|
40140
|
+
try {
|
|
40141
|
+
const cached = await getCache(cacheKey);
|
|
40142
|
+
if (cached) {
|
|
40143
|
+
logger28.log({
|
|
40144
|
+
level: "info",
|
|
40145
|
+
message: `Cache hit for getStudent section student: ${cacheKey}`
|
|
40146
|
+
});
|
|
40147
|
+
return cached;
|
|
40148
|
+
}
|
|
40149
|
+
const item = await collection.findOne(query);
|
|
40150
|
+
setCache(cacheKey, item, 600).then(() => {
|
|
40151
|
+
logger28.log({
|
|
40152
|
+
level: "info",
|
|
40153
|
+
message: `Cache set for getStudent section student: ${cacheKey}`
|
|
40154
|
+
});
|
|
40155
|
+
}).catch((err) => {
|
|
40156
|
+
logger28.log({
|
|
40157
|
+
level: "error",
|
|
40158
|
+
message: `Failed to set cache for getStudent section student: ${err.message}`
|
|
40159
|
+
});
|
|
40160
|
+
});
|
|
40161
|
+
return item;
|
|
40162
|
+
} catch (error) {
|
|
40163
|
+
logger28.log({ level: "error", message: `${error}` });
|
|
40164
|
+
throw error;
|
|
40165
|
+
}
|
|
40166
|
+
}
|
|
40056
40167
|
return {
|
|
40057
40168
|
createIndexes,
|
|
40058
40169
|
delCachedData,
|
|
40059
40170
|
add,
|
|
40060
|
-
getAll
|
|
40171
|
+
getAll,
|
|
40172
|
+
getStudent
|
|
40061
40173
|
};
|
|
40062
40174
|
}
|
|
40063
40175
|
|
|
@@ -40403,6 +40515,63 @@ function useSectionSubjectRepo() {
|
|
|
40403
40515
|
}
|
|
40404
40516
|
}
|
|
40405
40517
|
}
|
|
40518
|
+
async function getSectionSubject(options) {
|
|
40519
|
+
const query = {};
|
|
40520
|
+
const cacheKeyOptions = { tag: "getSectionSubject" };
|
|
40521
|
+
if (options.gradeLevel) {
|
|
40522
|
+
query.gradeLevel = options.gradeLevel;
|
|
40523
|
+
cacheKeyOptions.gradeLevel = options.gradeLevel;
|
|
40524
|
+
}
|
|
40525
|
+
if (options.schoolYear) {
|
|
40526
|
+
query.schoolYear = options.schoolYear;
|
|
40527
|
+
cacheKeyOptions.schoolYear = options.schoolYear;
|
|
40528
|
+
}
|
|
40529
|
+
if (options.subjectCode) {
|
|
40530
|
+
query.subjectCode = options.subjectCode;
|
|
40531
|
+
cacheKeyOptions.subjectCode = options.subjectCode;
|
|
40532
|
+
}
|
|
40533
|
+
try {
|
|
40534
|
+
query.section = new ObjectId34(options.section);
|
|
40535
|
+
cacheKeyOptions.section = String(options.section);
|
|
40536
|
+
} catch (error) {
|
|
40537
|
+
throw new BadRequestError53("Invalid section ID.");
|
|
40538
|
+
}
|
|
40539
|
+
const cacheKey = makeCacheKey18(namespace_collection, cacheKeyOptions);
|
|
40540
|
+
try {
|
|
40541
|
+
const cached = await getCache(cacheKey);
|
|
40542
|
+
if (cached) {
|
|
40543
|
+
logger29.log({
|
|
40544
|
+
level: "info",
|
|
40545
|
+
message: `Cache hit for getSectionSubject section subjects: ${cacheKey}`
|
|
40546
|
+
});
|
|
40547
|
+
return cached;
|
|
40548
|
+
}
|
|
40549
|
+
const result = await collection.find({
|
|
40550
|
+
...query,
|
|
40551
|
+
deletedAt: { $in: ["", null] }
|
|
40552
|
+
}).toArray();
|
|
40553
|
+
setCache(cacheKey, result, 300).then(() => {
|
|
40554
|
+
logger29.log({
|
|
40555
|
+
level: "info",
|
|
40556
|
+
message: `Cache set for section subjects by getSectionSubject: ${cacheKey}`
|
|
40557
|
+
});
|
|
40558
|
+
}).catch((err) => {
|
|
40559
|
+
logger29.log({
|
|
40560
|
+
level: "error",
|
|
40561
|
+
message: `Failed to set cache for section subjects by getSectionSubject: ${err.message}`
|
|
40562
|
+
});
|
|
40563
|
+
});
|
|
40564
|
+
return result;
|
|
40565
|
+
} catch (error) {
|
|
40566
|
+
if (error instanceof AppError19) {
|
|
40567
|
+
throw error;
|
|
40568
|
+
} else {
|
|
40569
|
+
throw new InternalServerError16(
|
|
40570
|
+
"Failed to get section subjects by getSectionSubject."
|
|
40571
|
+
);
|
|
40572
|
+
}
|
|
40573
|
+
}
|
|
40574
|
+
}
|
|
40406
40575
|
async function getBySection(section) {
|
|
40407
40576
|
try {
|
|
40408
40577
|
section = new ObjectId34(section);
|
|
@@ -40635,6 +40804,7 @@ function useSectionSubjectRepo() {
|
|
|
40635
40804
|
add,
|
|
40636
40805
|
getAll,
|
|
40637
40806
|
getById,
|
|
40807
|
+
getSectionSubject,
|
|
40638
40808
|
getBySection,
|
|
40639
40809
|
getByTeacher,
|
|
40640
40810
|
getBySchool,
|
|
@@ -41024,7 +41194,13 @@ function useTeachingLoadRepo() {
|
|
|
41024
41194
|
{ key: { status: 1 } },
|
|
41025
41195
|
{ key: { school: 1 } },
|
|
41026
41196
|
{ key: { teacher: 1 } },
|
|
41027
|
-
{ key: {
|
|
41197
|
+
{ key: { gradeLevel: 1 } },
|
|
41198
|
+
{ key: { schoolYear: 1 } },
|
|
41199
|
+
{
|
|
41200
|
+
key: { school: 1, teacher: 1, schoolYear: 1, gradeLevel: 1 },
|
|
41201
|
+
unique: true,
|
|
41202
|
+
name: "unique_teaching_load_index"
|
|
41203
|
+
}
|
|
41028
41204
|
]);
|
|
41029
41205
|
} catch (error) {
|
|
41030
41206
|
throw new Error("Failed to create index on teaching load.");
|
|
@@ -41044,7 +41220,11 @@ function useTeachingLoadRepo() {
|
|
|
41044
41220
|
if (error instanceof AppError21) {
|
|
41045
41221
|
throw error;
|
|
41046
41222
|
} else {
|
|
41047
|
-
|
|
41223
|
+
const isDuplicated = error.message.includes("duplicate");
|
|
41224
|
+
if (isDuplicated) {
|
|
41225
|
+
throw new BadRequestError56("Teaching load already exist.");
|
|
41226
|
+
}
|
|
41227
|
+
throw new InternalServerError18("Failed to create teaching load.");
|
|
41048
41228
|
}
|
|
41049
41229
|
}
|
|
41050
41230
|
}
|
|
@@ -41249,23 +41429,32 @@ function useTeachingLoadRepo() {
|
|
|
41249
41429
|
}
|
|
41250
41430
|
}
|
|
41251
41431
|
}
|
|
41252
|
-
async function getByTeacher(
|
|
41432
|
+
async function getByTeacher(options) {
|
|
41433
|
+
const query = {};
|
|
41434
|
+
const cacheKeyOptions = { tag: "getByTeacher" };
|
|
41435
|
+
if (options.status) {
|
|
41436
|
+
query.status = options.status;
|
|
41437
|
+
cacheKeyOptions.status = options.status;
|
|
41438
|
+
}
|
|
41253
41439
|
try {
|
|
41254
|
-
teacher = new ObjectId36(teacher);
|
|
41440
|
+
query.teacher = new ObjectId36(options.teacher);
|
|
41255
41441
|
} catch (error) {
|
|
41256
41442
|
throw new BadRequestError56("Invalid teacher ID.");
|
|
41257
41443
|
}
|
|
41258
|
-
|
|
41259
|
-
|
|
41260
|
-
|
|
41261
|
-
|
|
41262
|
-
if (schoolYear) {
|
|
41263
|
-
query.schoolYear = schoolYear;
|
|
41444
|
+
cacheKeyOptions.teacher = String(options.teacher);
|
|
41445
|
+
if (options.schoolYear) {
|
|
41446
|
+
query.schoolYear = options.schoolYear;
|
|
41447
|
+
cacheKeyOptions.schoolYear = options.schoolYear;
|
|
41264
41448
|
}
|
|
41265
|
-
|
|
41266
|
-
|
|
41267
|
-
|
|
41268
|
-
|
|
41449
|
+
if (options.school) {
|
|
41450
|
+
try {
|
|
41451
|
+
query.school = new ObjectId36(options.school);
|
|
41452
|
+
} catch (error) {
|
|
41453
|
+
throw new BadRequestError56("Invalid school ID.");
|
|
41454
|
+
}
|
|
41455
|
+
cacheKeyOptions.school = String(options.school);
|
|
41456
|
+
}
|
|
41457
|
+
const cacheKey = makeCacheKey19(namespace_collection, cacheKeyOptions);
|
|
41269
41458
|
try {
|
|
41270
41459
|
const cached = await getCache(cacheKey);
|
|
41271
41460
|
if (cached) {
|
|
@@ -41519,7 +41708,7 @@ function useTeachingLoadController() {
|
|
|
41519
41708
|
return;
|
|
41520
41709
|
}
|
|
41521
41710
|
try {
|
|
41522
|
-
const result = await _getByTeacher(teacher, schoolYear);
|
|
41711
|
+
const result = await _getByTeacher({ teacher, schoolYear });
|
|
41523
41712
|
res.json(result);
|
|
41524
41713
|
return;
|
|
41525
41714
|
} catch (error2) {
|
|
@@ -42382,7 +42571,9 @@ function usePersonnelRepo() {
|
|
|
42382
42571
|
page = 1,
|
|
42383
42572
|
limit = 10,
|
|
42384
42573
|
sort = {},
|
|
42385
|
-
status = "active"
|
|
42574
|
+
status = "active",
|
|
42575
|
+
gradeLevel = "",
|
|
42576
|
+
classification = ""
|
|
42386
42577
|
} = {}) {
|
|
42387
42578
|
page = page > 0 ? page - 1 : 0;
|
|
42388
42579
|
const query = {
|
|
@@ -42406,6 +42597,14 @@ function usePersonnelRepo() {
|
|
|
42406
42597
|
}
|
|
42407
42598
|
cacheParams.school = school;
|
|
42408
42599
|
}
|
|
42600
|
+
if (gradeLevel) {
|
|
42601
|
+
query.gradeLevels = gradeLevel;
|
|
42602
|
+
cacheParams.gradeLevel = gradeLevel;
|
|
42603
|
+
}
|
|
42604
|
+
if (classification) {
|
|
42605
|
+
query.classification = classification;
|
|
42606
|
+
cacheParams.classification = classification;
|
|
42607
|
+
}
|
|
42409
42608
|
const cacheKey = makeCacheKey21(namespace_collection, cacheParams);
|
|
42410
42609
|
logger37.log({
|
|
42411
42610
|
level: "info",
|
|
@@ -42794,13 +42993,13 @@ function usePersonnelController() {
|
|
|
42794
42993
|
function useSectionService() {
|
|
42795
42994
|
const { getCountByGradeLevel, getByGradeLevel: getLeanerByGradeLevel } = useLearnerRepo();
|
|
42796
42995
|
const { getByGradeLevel } = useGradeLevelRepo();
|
|
42797
|
-
const { add: createSection } = useSectionRepo();
|
|
42798
|
-
const { add: assignStudent } = useSectionStudentRepo();
|
|
42996
|
+
const { add: createSection, getSection } = useSectionRepo();
|
|
42997
|
+
const { add: assignStudent, getStudent } = useSectionStudentRepo();
|
|
42799
42998
|
const { getAll: getAllCurriculumSubjects } = useSubjectRepo();
|
|
42800
|
-
const { add: addSectionSubject } = useSectionSubjectRepo();
|
|
42999
|
+
const { add: addSectionSubject, getSectionSubject } = useSectionSubjectRepo();
|
|
42801
43000
|
const { getById: getSchoolById } = useSchoolRepo();
|
|
42802
43001
|
const { getAll: getAllPersonnel } = usePersonnelRepo();
|
|
42803
|
-
const { add: addTeachingLoad } = useTeachingLoadRepo();
|
|
43002
|
+
const { add: addTeachingLoad, getByTeacher } = useTeachingLoadRepo();
|
|
42804
43003
|
function distributeStudents(total, minPer, maxPer) {
|
|
42805
43004
|
if (total <= 0)
|
|
42806
43005
|
return [];
|
|
@@ -42871,12 +43070,6 @@ function useSectionService() {
|
|
|
42871
43070
|
}
|
|
42872
43071
|
const minPerSection = value.minStudents ?? gradeLevelData.minNumberOfLearners;
|
|
42873
43072
|
const maxPerSection = value.maxStudents ?? gradeLevelData.maxNumberOfLearners;
|
|
42874
|
-
const sectionsNeeded = Math.ceil(studentCount / minPerSection);
|
|
42875
|
-
if (sectionsNeeded > value.set.length) {
|
|
42876
|
-
throw new BadRequestError64(
|
|
42877
|
-
"Insufficient number of section names in set[]."
|
|
42878
|
-
);
|
|
42879
|
-
}
|
|
42880
43073
|
const sectionSizes = distributeStudents(
|
|
42881
43074
|
studentCount,
|
|
42882
43075
|
minPerSection,
|
|
@@ -42890,10 +43083,30 @@ function useSectionService() {
|
|
|
42890
43083
|
throw new BadRequestError64("School not found.");
|
|
42891
43084
|
}
|
|
42892
43085
|
let totalStudentsProcessed = 0;
|
|
43086
|
+
let sectionsGenerated = 0;
|
|
43087
|
+
let sectionsSkipped = 0;
|
|
43088
|
+
let teachingLoadsCreated = 0;
|
|
43089
|
+
let teachingLoadsSkipped = 0;
|
|
43090
|
+
let studentCreated = 0;
|
|
43091
|
+
let studentSkipped = 0;
|
|
43092
|
+
let subjectsAssigned = 0;
|
|
43093
|
+
let subjectsSkipped = 0;
|
|
42893
43094
|
for (let i = 0; i < sectionSizes.length; i++) {
|
|
42894
43095
|
const size = sectionSizes[i];
|
|
42895
|
-
const sectionName =
|
|
42896
|
-
const
|
|
43096
|
+
const sectionName = String(i + 1);
|
|
43097
|
+
const existingSection = await getSection({
|
|
43098
|
+
gradeLevel: value.gradeLevel,
|
|
43099
|
+
schoolYear: value.schoolYear,
|
|
43100
|
+
name: sectionName,
|
|
43101
|
+
school: value.school
|
|
43102
|
+
});
|
|
43103
|
+
let sectionId = "";
|
|
43104
|
+
if (existingSection) {
|
|
43105
|
+
sectionId = existingSection._id?.toString() || "";
|
|
43106
|
+
sectionsSkipped++;
|
|
43107
|
+
continue;
|
|
43108
|
+
}
|
|
43109
|
+
sectionId = await createSection(
|
|
42897
43110
|
{
|
|
42898
43111
|
school: value.school,
|
|
42899
43112
|
schoolYear: value.schoolYear,
|
|
@@ -42903,6 +43116,10 @@ function useSectionService() {
|
|
|
42903
43116
|
},
|
|
42904
43117
|
session
|
|
42905
43118
|
);
|
|
43119
|
+
if (!sectionId) {
|
|
43120
|
+
throw new InternalServerError21("Required section ID is missing.");
|
|
43121
|
+
}
|
|
43122
|
+
sectionsGenerated++;
|
|
42906
43123
|
const skip = totalStudentsProcessed;
|
|
42907
43124
|
const learners = await getLeanerByGradeLevel(
|
|
42908
43125
|
{
|
|
@@ -42924,9 +43141,19 @@ function useSectionService() {
|
|
|
42924
43141
|
if (!student.learnerInfo.lrn) {
|
|
42925
43142
|
throw new BadRequestError64("Learner LRN is missing.");
|
|
42926
43143
|
}
|
|
43144
|
+
const existingStudent = await getStudent({
|
|
43145
|
+
student: student._id.toString(),
|
|
43146
|
+
schoolYear: value.schoolYear,
|
|
43147
|
+
section: sectionId,
|
|
43148
|
+
gradeLevel: value.gradeLevel
|
|
43149
|
+
});
|
|
43150
|
+
if (existingStudent) {
|
|
43151
|
+
studentSkipped++;
|
|
43152
|
+
continue;
|
|
43153
|
+
}
|
|
42927
43154
|
await assignStudent(
|
|
42928
43155
|
{
|
|
42929
|
-
section:
|
|
43156
|
+
section: sectionId,
|
|
42930
43157
|
lrn: student.learnerInfo.lrn,
|
|
42931
43158
|
student: student._id?.toString(),
|
|
42932
43159
|
studentName: `${student.learnerInfo.firstName} ${student.learnerInfo.lastName}`,
|
|
@@ -42939,37 +43166,50 @@ function useSectionService() {
|
|
|
42939
43166
|
},
|
|
42940
43167
|
session
|
|
42941
43168
|
);
|
|
43169
|
+
studentCreated++;
|
|
42942
43170
|
}
|
|
42943
|
-
|
|
42944
|
-
|
|
42945
|
-
|
|
42946
|
-
|
|
42947
|
-
|
|
42948
|
-
|
|
42949
|
-
|
|
42950
|
-
{
|
|
42951
|
-
|
|
42952
|
-
school: value.school,
|
|
42953
|
-
schoolName: schoolData.name,
|
|
42954
|
-
gradeLevel: value.gradeLevel,
|
|
42955
|
-
educationLevel: gradeLevelData.educationLevel,
|
|
42956
|
-
schoolYear: value.schoolYear,
|
|
42957
|
-
section: section.toString(),
|
|
42958
|
-
sectionName,
|
|
43171
|
+
if (value.gradeLevel !== "kindergarten") {
|
|
43172
|
+
const curriculumSubjects = await getAllCurriculumSubjects({
|
|
43173
|
+
schoolYear: Number(value.schoolYear),
|
|
43174
|
+
gradeLevel: value.gradeLevel,
|
|
43175
|
+
limit: 20
|
|
43176
|
+
});
|
|
43177
|
+
for (const curriculumSubject of curriculumSubjects.items) {
|
|
43178
|
+
const existingSectionSubject = await getSectionSubject({
|
|
43179
|
+
section: sectionId,
|
|
42959
43180
|
subjectCode: curriculumSubject.subjectCode,
|
|
42960
|
-
|
|
42961
|
-
|
|
42962
|
-
|
|
42963
|
-
|
|
42964
|
-
|
|
42965
|
-
|
|
42966
|
-
|
|
42967
|
-
|
|
42968
|
-
|
|
42969
|
-
|
|
42970
|
-
|
|
42971
|
-
|
|
42972
|
-
|
|
43181
|
+
schoolYear: value.schoolYear
|
|
43182
|
+
});
|
|
43183
|
+
if (existingSectionSubject && existingSectionSubject.length) {
|
|
43184
|
+
subjectsSkipped++;
|
|
43185
|
+
continue;
|
|
43186
|
+
}
|
|
43187
|
+
await addSectionSubject(
|
|
43188
|
+
{
|
|
43189
|
+
curriculum: curriculumSubject.curriculum.toString(),
|
|
43190
|
+
school: value.school,
|
|
43191
|
+
schoolName: schoolData.name,
|
|
43192
|
+
gradeLevel: value.gradeLevel,
|
|
43193
|
+
educationLevel: gradeLevelData.educationLevel,
|
|
43194
|
+
schoolYear: value.schoolYear,
|
|
43195
|
+
section: sectionId,
|
|
43196
|
+
sectionName,
|
|
43197
|
+
subjectCode: curriculumSubject.subjectCode,
|
|
43198
|
+
subjectName: curriculumSubject.subjectName,
|
|
43199
|
+
teacher: "",
|
|
43200
|
+
teacherName: "",
|
|
43201
|
+
schedule: "",
|
|
43202
|
+
daysOfWeek: [],
|
|
43203
|
+
classroom: "",
|
|
43204
|
+
classroomName: "",
|
|
43205
|
+
sessionDuration: curriculumSubject.sessionDuration,
|
|
43206
|
+
sessionFrequency: curriculumSubject.sessionFrequency,
|
|
43207
|
+
status: "draft"
|
|
43208
|
+
},
|
|
43209
|
+
session
|
|
43210
|
+
);
|
|
43211
|
+
subjectsAssigned++;
|
|
43212
|
+
}
|
|
42973
43213
|
}
|
|
42974
43214
|
}
|
|
42975
43215
|
let pageTeacher = 1;
|
|
@@ -42978,7 +43218,9 @@ function useSectionService() {
|
|
|
42978
43218
|
do {
|
|
42979
43219
|
const teachersData = await getAllPersonnel({
|
|
42980
43220
|
school: value.school,
|
|
42981
|
-
limit: 100
|
|
43221
|
+
limit: 100,
|
|
43222
|
+
gradeLevel: value.gradeLevel,
|
|
43223
|
+
classification: "teaching"
|
|
42982
43224
|
});
|
|
42983
43225
|
pagesTeachers = teachersData.pages;
|
|
42984
43226
|
teachers.push(...teachersData.items);
|
|
@@ -42990,11 +43232,19 @@ function useSectionService() {
|
|
|
42990
43232
|
);
|
|
42991
43233
|
}
|
|
42992
43234
|
if (teachers.length) {
|
|
42993
|
-
for (
|
|
42994
|
-
const teacher = teachers[index];
|
|
43235
|
+
for (const teacher of teachers) {
|
|
42995
43236
|
if (!teacher._id) {
|
|
42996
43237
|
throw new BadRequestError64("Teacher ID is missing.");
|
|
42997
43238
|
}
|
|
43239
|
+
const existingLoad = await getByTeacher({
|
|
43240
|
+
teacher: teacher._id.toString(),
|
|
43241
|
+
school: value.school,
|
|
43242
|
+
schoolYear: value.schoolYear
|
|
43243
|
+
});
|
|
43244
|
+
if (existingLoad && existingLoad.length) {
|
|
43245
|
+
teachingLoadsSkipped++;
|
|
43246
|
+
continue;
|
|
43247
|
+
}
|
|
42998
43248
|
await addTeachingLoad(
|
|
42999
43249
|
{
|
|
43000
43250
|
school: value.school,
|
|
@@ -43006,10 +43256,26 @@ function useSectionService() {
|
|
|
43006
43256
|
},
|
|
43007
43257
|
session
|
|
43008
43258
|
);
|
|
43259
|
+
teachingLoadsCreated++;
|
|
43009
43260
|
}
|
|
43010
43261
|
}
|
|
43011
43262
|
await session.commitTransaction();
|
|
43012
|
-
return
|
|
43263
|
+
return {
|
|
43264
|
+
message: "Sections generated successfully.",
|
|
43265
|
+
summary: {
|
|
43266
|
+
sectionsGenerated,
|
|
43267
|
+
sectionsSkipped,
|
|
43268
|
+
totalSections: sectionsGenerated + sectionsSkipped,
|
|
43269
|
+
studentsProcessed: totalStudentsProcessed,
|
|
43270
|
+
studentCreated,
|
|
43271
|
+
studentSkipped,
|
|
43272
|
+
subjectsAssigned,
|
|
43273
|
+
subjectsSkipped,
|
|
43274
|
+
teachingLoadsCreated,
|
|
43275
|
+
teachingLoadsSkipped,
|
|
43276
|
+
totalStudents: studentCount
|
|
43277
|
+
}
|
|
43278
|
+
};
|
|
43013
43279
|
} catch (error2) {
|
|
43014
43280
|
await session.abortTransaction();
|
|
43015
43281
|
if (error2 instanceof AppError25) {
|
|
@@ -43047,12 +43313,6 @@ function useSectionService() {
|
|
|
43047
43313
|
}
|
|
43048
43314
|
const minPerSection = value.minStudents ?? gradeLevelData.minNumberOfLearners;
|
|
43049
43315
|
const maxPerSection = value.maxStudents ?? gradeLevelData.maxNumberOfLearners;
|
|
43050
|
-
const sectionsNeeded = Math.ceil(studentCount / minPerSection);
|
|
43051
|
-
if (sectionsNeeded > value.set.length) {
|
|
43052
|
-
throw new BadRequestError64(
|
|
43053
|
-
"Insufficient number of section names in set[]."
|
|
43054
|
-
);
|
|
43055
|
-
}
|
|
43056
43316
|
const sectionSizes = distributeStudents(
|
|
43057
43317
|
studentCount,
|
|
43058
43318
|
minPerSection,
|
|
@@ -43062,7 +43322,7 @@ function useSectionService() {
|
|
|
43062
43322
|
throw new BadRequestError64("Unable to compute section sizes.");
|
|
43063
43323
|
}
|
|
43064
43324
|
const sections = sectionSizes.map((size, index) => ({
|
|
43065
|
-
name:
|
|
43325
|
+
name: `${index + 1}`,
|
|
43066
43326
|
value: size
|
|
43067
43327
|
}));
|
|
43068
43328
|
return {
|