@eeplatform/basic-edu 1.10.1 → 1.10.2
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 +6 -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.js
CHANGED
|
@@ -39329,6 +39329,7 @@ var schemaSection = import_joi31.default.object({
|
|
|
39329
39329
|
_id: import_joi31.default.string().hex().optional().allow(null, ""),
|
|
39330
39330
|
school: import_joi31.default.string().hex().required(),
|
|
39331
39331
|
name: import_joi31.default.string().min(1).max(100).required(),
|
|
39332
|
+
label: import_joi31.default.string().max(100).optional().allow(null, ""),
|
|
39332
39333
|
schoolYear: import_joi31.default.string().required(),
|
|
39333
39334
|
gradeLevel: import_joi31.default.string().required(),
|
|
39334
39335
|
students: import_joi31.default.number().integer().min(0).optional(),
|
|
@@ -39345,8 +39346,7 @@ var schemaGenerateSections = import_joi31.default.object({
|
|
|
39345
39346
|
gradeLevel: import_joi31.default.string().required(),
|
|
39346
39347
|
minStudents: import_joi31.default.number().integer().min(1).required(),
|
|
39347
39348
|
maxStudents: import_joi31.default.number().integer().min(import_joi31.default.ref("minStudents")).required(),
|
|
39348
|
-
specialProgram: import_joi31.default.string().hex().optional().allow(null, "")
|
|
39349
|
-
set: import_joi31.default.array().items(import_joi31.default.string().min(1).max(100)).required()
|
|
39349
|
+
specialProgram: import_joi31.default.string().hex().optional().allow(null, "")
|
|
39350
39350
|
});
|
|
39351
39351
|
function modelSection(value) {
|
|
39352
39352
|
const { error } = schemaSection.validate(value);
|
|
@@ -39378,6 +39378,7 @@ function modelSection(value) {
|
|
|
39378
39378
|
_id: value._id,
|
|
39379
39379
|
school: value.school,
|
|
39380
39380
|
name: value.name,
|
|
39381
|
+
label: value.label ?? "",
|
|
39381
39382
|
schoolYear: value.schoolYear,
|
|
39382
39383
|
gradeLevel: value.gradeLevel,
|
|
39383
39384
|
adviser: value.adviser,
|
|
@@ -39412,7 +39413,7 @@ function useSectionRepo() {
|
|
|
39412
39413
|
{ key: { createdAt: 1 } },
|
|
39413
39414
|
{ key: { name: "text", schoolYear: "text", gradeLevel: "text" } },
|
|
39414
39415
|
{
|
|
39415
|
-
key: { school: 1,
|
|
39416
|
+
key: { school: 1, teacher: 1, schoolYear: 1, status: 1 },
|
|
39416
39417
|
unique: true,
|
|
39417
39418
|
name: "unique_section"
|
|
39418
39419
|
}
|
|
@@ -39439,7 +39440,7 @@ function useSectionRepo() {
|
|
|
39439
39440
|
value = modelSection(value);
|
|
39440
39441
|
const res = await collection.insertOne(value, { session });
|
|
39441
39442
|
delCachedData();
|
|
39442
|
-
return res.insertedId;
|
|
39443
|
+
return res.insertedId.toString();
|
|
39443
39444
|
} catch (error) {
|
|
39444
39445
|
import_nodejs_utils52.logger.log({
|
|
39445
39446
|
level: "error",
|
|
@@ -39580,6 +39581,54 @@ function useSectionRepo() {
|
|
|
39580
39581
|
}
|
|
39581
39582
|
}
|
|
39582
39583
|
}
|
|
39584
|
+
async function getSection(options) {
|
|
39585
|
+
const query = {};
|
|
39586
|
+
const cacheKeyOptions = { tag: "getSection" };
|
|
39587
|
+
try {
|
|
39588
|
+
query.school = new import_mongodb30.ObjectId(options.school);
|
|
39589
|
+
cacheKeyOptions.school = String(options.school);
|
|
39590
|
+
} catch (error) {
|
|
39591
|
+
throw new import_nodejs_utils52.BadRequestError("Invalid school ID.");
|
|
39592
|
+
}
|
|
39593
|
+
query.gradeLevel = options.gradeLevel;
|
|
39594
|
+
cacheKeyOptions.gradeLevel = options.gradeLevel;
|
|
39595
|
+
query.name = options.name;
|
|
39596
|
+
cacheKeyOptions.name = options.name;
|
|
39597
|
+
if (options.schoolYear) {
|
|
39598
|
+
query.schoolYear = options.schoolYear;
|
|
39599
|
+
cacheKeyOptions.schoolYear = options.schoolYear;
|
|
39600
|
+
}
|
|
39601
|
+
const cacheKey = (0, import_nodejs_utils52.makeCacheKey)(namespace_collection, cacheKeyOptions);
|
|
39602
|
+
try {
|
|
39603
|
+
const cached = await getCache(cacheKey);
|
|
39604
|
+
if (cached) {
|
|
39605
|
+
import_nodejs_utils52.logger.log({
|
|
39606
|
+
level: "info",
|
|
39607
|
+
message: `Cache hit for getSection: ${cacheKey}`
|
|
39608
|
+
});
|
|
39609
|
+
return cached;
|
|
39610
|
+
}
|
|
39611
|
+
const result = await collection.findOne(query);
|
|
39612
|
+
setCache(cacheKey, result, 300).then(() => {
|
|
39613
|
+
import_nodejs_utils52.logger.log({
|
|
39614
|
+
level: "info",
|
|
39615
|
+
message: `Cache set for section: ${cacheKey}`
|
|
39616
|
+
});
|
|
39617
|
+
}).catch((err) => {
|
|
39618
|
+
import_nodejs_utils52.logger.log({
|
|
39619
|
+
level: "error",
|
|
39620
|
+
message: `Failed to set cache for section: ${err.message}`
|
|
39621
|
+
});
|
|
39622
|
+
});
|
|
39623
|
+
return result;
|
|
39624
|
+
} catch (error) {
|
|
39625
|
+
if (error instanceof import_nodejs_utils52.AppError) {
|
|
39626
|
+
throw error;
|
|
39627
|
+
} else {
|
|
39628
|
+
throw new import_nodejs_utils52.InternalServerError("Failed to get section.");
|
|
39629
|
+
}
|
|
39630
|
+
}
|
|
39631
|
+
}
|
|
39583
39632
|
async function getByName(name) {
|
|
39584
39633
|
const cacheKey = (0, import_nodejs_utils52.makeCacheKey)(namespace_collection, { name });
|
|
39585
39634
|
try {
|
|
@@ -39763,6 +39812,7 @@ function useSectionRepo() {
|
|
|
39763
39812
|
add,
|
|
39764
39813
|
getAll,
|
|
39765
39814
|
getById,
|
|
39815
|
+
getSection,
|
|
39766
39816
|
getByName,
|
|
39767
39817
|
getBySchool,
|
|
39768
39818
|
updateFieldById,
|
|
@@ -40007,11 +40057,73 @@ function useSectionStudentRepo() {
|
|
|
40007
40057
|
});
|
|
40008
40058
|
return data;
|
|
40009
40059
|
}
|
|
40060
|
+
async function getStudent(options) {
|
|
40061
|
+
const query = {};
|
|
40062
|
+
const cacheKeyOptions = { tag: "getStudent" };
|
|
40063
|
+
if (options.learner) {
|
|
40064
|
+
try {
|
|
40065
|
+
query.learner = new import_mongodb32.ObjectId(options.learner);
|
|
40066
|
+
cacheKeyOptions.learner = String(options.learner);
|
|
40067
|
+
} catch (error) {
|
|
40068
|
+
throw new import_nodejs_utils54.BadRequestError("Invalid learner ID.");
|
|
40069
|
+
}
|
|
40070
|
+
}
|
|
40071
|
+
if (options.schoolYear) {
|
|
40072
|
+
query.schoolYear = options.schoolYear;
|
|
40073
|
+
cacheKeyOptions.schoolYear = options.schoolYear;
|
|
40074
|
+
}
|
|
40075
|
+
if (options.section) {
|
|
40076
|
+
try {
|
|
40077
|
+
query.section = new import_mongodb32.ObjectId(options.section);
|
|
40078
|
+
cacheKeyOptions.section = String(options.section);
|
|
40079
|
+
} catch (error) {
|
|
40080
|
+
throw new import_nodejs_utils54.BadRequestError("Invalid section ID.");
|
|
40081
|
+
}
|
|
40082
|
+
}
|
|
40083
|
+
if (options.gradeLevel) {
|
|
40084
|
+
query.gradeLevel = options.gradeLevel;
|
|
40085
|
+
cacheKeyOptions.gradeLevel = options.gradeLevel;
|
|
40086
|
+
}
|
|
40087
|
+
try {
|
|
40088
|
+
query.student = new import_mongodb32.ObjectId(options.student);
|
|
40089
|
+
cacheKeyOptions.student = String(options.student);
|
|
40090
|
+
} catch (error) {
|
|
40091
|
+
throw new import_nodejs_utils54.BadRequestError("Invalid student ID.");
|
|
40092
|
+
}
|
|
40093
|
+
const cacheKey = (0, import_nodejs_utils54.makeCacheKey)(namespace_collection, cacheKeyOptions);
|
|
40094
|
+
try {
|
|
40095
|
+
const cached = await getCache(cacheKey);
|
|
40096
|
+
if (cached) {
|
|
40097
|
+
import_nodejs_utils54.logger.log({
|
|
40098
|
+
level: "info",
|
|
40099
|
+
message: `Cache hit for getStudent section student: ${cacheKey}`
|
|
40100
|
+
});
|
|
40101
|
+
return cached;
|
|
40102
|
+
}
|
|
40103
|
+
const item = await collection.findOne(query);
|
|
40104
|
+
setCache(cacheKey, item, 600).then(() => {
|
|
40105
|
+
import_nodejs_utils54.logger.log({
|
|
40106
|
+
level: "info",
|
|
40107
|
+
message: `Cache set for getStudent section student: ${cacheKey}`
|
|
40108
|
+
});
|
|
40109
|
+
}).catch((err) => {
|
|
40110
|
+
import_nodejs_utils54.logger.log({
|
|
40111
|
+
level: "error",
|
|
40112
|
+
message: `Failed to set cache for getStudent section student: ${err.message}`
|
|
40113
|
+
});
|
|
40114
|
+
});
|
|
40115
|
+
return item;
|
|
40116
|
+
} catch (error) {
|
|
40117
|
+
import_nodejs_utils54.logger.log({ level: "error", message: `${error}` });
|
|
40118
|
+
throw error;
|
|
40119
|
+
}
|
|
40120
|
+
}
|
|
40010
40121
|
return {
|
|
40011
40122
|
createIndexes,
|
|
40012
40123
|
delCachedData,
|
|
40013
40124
|
add,
|
|
40014
|
-
getAll
|
|
40125
|
+
getAll,
|
|
40126
|
+
getStudent
|
|
40015
40127
|
};
|
|
40016
40128
|
}
|
|
40017
40129
|
|
|
@@ -40348,6 +40460,63 @@ function useSectionSubjectRepo() {
|
|
|
40348
40460
|
}
|
|
40349
40461
|
}
|
|
40350
40462
|
}
|
|
40463
|
+
async function getSectionSubject(options) {
|
|
40464
|
+
const query = {};
|
|
40465
|
+
const cacheKeyOptions = { tag: "getSectionSubject" };
|
|
40466
|
+
if (options.gradeLevel) {
|
|
40467
|
+
query.gradeLevel = options.gradeLevel;
|
|
40468
|
+
cacheKeyOptions.gradeLevel = options.gradeLevel;
|
|
40469
|
+
}
|
|
40470
|
+
if (options.schoolYear) {
|
|
40471
|
+
query.schoolYear = options.schoolYear;
|
|
40472
|
+
cacheKeyOptions.schoolYear = options.schoolYear;
|
|
40473
|
+
}
|
|
40474
|
+
if (options.subjectCode) {
|
|
40475
|
+
query.subjectCode = options.subjectCode;
|
|
40476
|
+
cacheKeyOptions.subjectCode = options.subjectCode;
|
|
40477
|
+
}
|
|
40478
|
+
try {
|
|
40479
|
+
query.section = new import_mongodb34.ObjectId(options.section);
|
|
40480
|
+
cacheKeyOptions.section = String(options.section);
|
|
40481
|
+
} catch (error) {
|
|
40482
|
+
throw new import_nodejs_utils56.BadRequestError("Invalid section ID.");
|
|
40483
|
+
}
|
|
40484
|
+
const cacheKey = (0, import_nodejs_utils56.makeCacheKey)(namespace_collection, cacheKeyOptions);
|
|
40485
|
+
try {
|
|
40486
|
+
const cached = await getCache(cacheKey);
|
|
40487
|
+
if (cached) {
|
|
40488
|
+
import_nodejs_utils56.logger.log({
|
|
40489
|
+
level: "info",
|
|
40490
|
+
message: `Cache hit for getSectionSubject section subjects: ${cacheKey}`
|
|
40491
|
+
});
|
|
40492
|
+
return cached;
|
|
40493
|
+
}
|
|
40494
|
+
const result = await collection.find({
|
|
40495
|
+
...query,
|
|
40496
|
+
deletedAt: { $in: ["", null] }
|
|
40497
|
+
}).toArray();
|
|
40498
|
+
setCache(cacheKey, result, 300).then(() => {
|
|
40499
|
+
import_nodejs_utils56.logger.log({
|
|
40500
|
+
level: "info",
|
|
40501
|
+
message: `Cache set for section subjects by getSectionSubject: ${cacheKey}`
|
|
40502
|
+
});
|
|
40503
|
+
}).catch((err) => {
|
|
40504
|
+
import_nodejs_utils56.logger.log({
|
|
40505
|
+
level: "error",
|
|
40506
|
+
message: `Failed to set cache for section subjects by getSectionSubject: ${err.message}`
|
|
40507
|
+
});
|
|
40508
|
+
});
|
|
40509
|
+
return result;
|
|
40510
|
+
} catch (error) {
|
|
40511
|
+
if (error instanceof import_nodejs_utils56.AppError) {
|
|
40512
|
+
throw error;
|
|
40513
|
+
} else {
|
|
40514
|
+
throw new import_nodejs_utils56.InternalServerError(
|
|
40515
|
+
"Failed to get section subjects by getSectionSubject."
|
|
40516
|
+
);
|
|
40517
|
+
}
|
|
40518
|
+
}
|
|
40519
|
+
}
|
|
40351
40520
|
async function getBySection(section) {
|
|
40352
40521
|
try {
|
|
40353
40522
|
section = new import_mongodb34.ObjectId(section);
|
|
@@ -40580,6 +40749,7 @@ function useSectionSubjectRepo() {
|
|
|
40580
40749
|
add,
|
|
40581
40750
|
getAll,
|
|
40582
40751
|
getById,
|
|
40752
|
+
getSectionSubject,
|
|
40583
40753
|
getBySection,
|
|
40584
40754
|
getByTeacher,
|
|
40585
40755
|
getBySchool,
|
|
@@ -40960,7 +41130,13 @@ function useTeachingLoadRepo() {
|
|
|
40960
41130
|
{ key: { status: 1 } },
|
|
40961
41131
|
{ key: { school: 1 } },
|
|
40962
41132
|
{ key: { teacher: 1 } },
|
|
40963
|
-
{ key: {
|
|
41133
|
+
{ key: { gradeLevel: 1 } },
|
|
41134
|
+
{ key: { schoolYear: 1 } },
|
|
41135
|
+
{
|
|
41136
|
+
key: { school: 1, teacher: 1, schoolYear: 1, gradeLevel: 1 },
|
|
41137
|
+
unique: true,
|
|
41138
|
+
name: "unique_teaching_load_index"
|
|
41139
|
+
}
|
|
40964
41140
|
]);
|
|
40965
41141
|
} catch (error) {
|
|
40966
41142
|
throw new Error("Failed to create index on teaching load.");
|
|
@@ -40980,7 +41156,11 @@ function useTeachingLoadRepo() {
|
|
|
40980
41156
|
if (error instanceof import_nodejs_utils60.AppError) {
|
|
40981
41157
|
throw error;
|
|
40982
41158
|
} else {
|
|
40983
|
-
|
|
41159
|
+
const isDuplicated = error.message.includes("duplicate");
|
|
41160
|
+
if (isDuplicated) {
|
|
41161
|
+
throw new import_nodejs_utils60.BadRequestError("Teaching load already exist.");
|
|
41162
|
+
}
|
|
41163
|
+
throw new import_nodejs_utils60.InternalServerError("Failed to create teaching load.");
|
|
40984
41164
|
}
|
|
40985
41165
|
}
|
|
40986
41166
|
}
|
|
@@ -41185,23 +41365,32 @@ function useTeachingLoadRepo() {
|
|
|
41185
41365
|
}
|
|
41186
41366
|
}
|
|
41187
41367
|
}
|
|
41188
|
-
async function getByTeacher(
|
|
41368
|
+
async function getByTeacher(options) {
|
|
41369
|
+
const query = {};
|
|
41370
|
+
const cacheKeyOptions = { tag: "getByTeacher" };
|
|
41371
|
+
if (options.status) {
|
|
41372
|
+
query.status = options.status;
|
|
41373
|
+
cacheKeyOptions.status = options.status;
|
|
41374
|
+
}
|
|
41189
41375
|
try {
|
|
41190
|
-
teacher = new import_mongodb36.ObjectId(teacher);
|
|
41376
|
+
query.teacher = new import_mongodb36.ObjectId(options.teacher);
|
|
41191
41377
|
} catch (error) {
|
|
41192
41378
|
throw new import_nodejs_utils60.BadRequestError("Invalid teacher ID.");
|
|
41193
41379
|
}
|
|
41194
|
-
|
|
41195
|
-
|
|
41196
|
-
|
|
41197
|
-
|
|
41198
|
-
if (schoolYear) {
|
|
41199
|
-
query.schoolYear = schoolYear;
|
|
41380
|
+
cacheKeyOptions.teacher = String(options.teacher);
|
|
41381
|
+
if (options.schoolYear) {
|
|
41382
|
+
query.schoolYear = options.schoolYear;
|
|
41383
|
+
cacheKeyOptions.schoolYear = options.schoolYear;
|
|
41200
41384
|
}
|
|
41201
|
-
|
|
41202
|
-
|
|
41203
|
-
|
|
41204
|
-
|
|
41385
|
+
if (options.school) {
|
|
41386
|
+
try {
|
|
41387
|
+
query.school = new import_mongodb36.ObjectId(options.school);
|
|
41388
|
+
} catch (error) {
|
|
41389
|
+
throw new import_nodejs_utils60.BadRequestError("Invalid school ID.");
|
|
41390
|
+
}
|
|
41391
|
+
cacheKeyOptions.school = String(options.school);
|
|
41392
|
+
}
|
|
41393
|
+
const cacheKey = (0, import_nodejs_utils60.makeCacheKey)(namespace_collection, cacheKeyOptions);
|
|
41205
41394
|
try {
|
|
41206
41395
|
const cached = await getCache(cacheKey);
|
|
41207
41396
|
if (cached) {
|
|
@@ -41455,7 +41644,7 @@ function useTeachingLoadController() {
|
|
|
41455
41644
|
return;
|
|
41456
41645
|
}
|
|
41457
41646
|
try {
|
|
41458
|
-
const result = await _getByTeacher(teacher, schoolYear);
|
|
41647
|
+
const result = await _getByTeacher({ teacher, schoolYear });
|
|
41459
41648
|
res.json(result);
|
|
41460
41649
|
return;
|
|
41461
41650
|
} catch (error2) {
|
|
@@ -42300,7 +42489,9 @@ function usePersonnelRepo() {
|
|
|
42300
42489
|
page = 1,
|
|
42301
42490
|
limit = 10,
|
|
42302
42491
|
sort = {},
|
|
42303
|
-
status = "active"
|
|
42492
|
+
status = "active",
|
|
42493
|
+
gradeLevel = "",
|
|
42494
|
+
classification = ""
|
|
42304
42495
|
} = {}) {
|
|
42305
42496
|
page = page > 0 ? page - 1 : 0;
|
|
42306
42497
|
const query = {
|
|
@@ -42324,6 +42515,14 @@ function usePersonnelRepo() {
|
|
|
42324
42515
|
}
|
|
42325
42516
|
cacheParams.school = school;
|
|
42326
42517
|
}
|
|
42518
|
+
if (gradeLevel) {
|
|
42519
|
+
query.gradeLevels = gradeLevel;
|
|
42520
|
+
cacheParams.gradeLevel = gradeLevel;
|
|
42521
|
+
}
|
|
42522
|
+
if (classification) {
|
|
42523
|
+
query.classification = classification;
|
|
42524
|
+
cacheParams.classification = classification;
|
|
42525
|
+
}
|
|
42327
42526
|
const cacheKey = (0, import_nodejs_utils67.makeCacheKey)(namespace_collection, cacheParams);
|
|
42328
42527
|
import_nodejs_utils67.logger.log({
|
|
42329
42528
|
level: "info",
|
|
@@ -42712,13 +42911,13 @@ function usePersonnelController() {
|
|
|
42712
42911
|
function useSectionService() {
|
|
42713
42912
|
const { getCountByGradeLevel, getByGradeLevel: getLeanerByGradeLevel } = useLearnerRepo();
|
|
42714
42913
|
const { getByGradeLevel } = useGradeLevelRepo();
|
|
42715
|
-
const { add: createSection } = useSectionRepo();
|
|
42716
|
-
const { add: assignStudent } = useSectionStudentRepo();
|
|
42914
|
+
const { add: createSection, getSection } = useSectionRepo();
|
|
42915
|
+
const { add: assignStudent, getStudent } = useSectionStudentRepo();
|
|
42717
42916
|
const { getAll: getAllCurriculumSubjects } = useSubjectRepo();
|
|
42718
|
-
const { add: addSectionSubject } = useSectionSubjectRepo();
|
|
42917
|
+
const { add: addSectionSubject, getSectionSubject } = useSectionSubjectRepo();
|
|
42719
42918
|
const { getById: getSchoolById } = useSchoolRepo();
|
|
42720
42919
|
const { getAll: getAllPersonnel } = usePersonnelRepo();
|
|
42721
|
-
const { add: addTeachingLoad } = useTeachingLoadRepo();
|
|
42920
|
+
const { add: addTeachingLoad, getByTeacher } = useTeachingLoadRepo();
|
|
42722
42921
|
function distributeStudents(total, minPer, maxPer) {
|
|
42723
42922
|
if (total <= 0)
|
|
42724
42923
|
return [];
|
|
@@ -42789,12 +42988,6 @@ function useSectionService() {
|
|
|
42789
42988
|
}
|
|
42790
42989
|
const minPerSection = value.minStudents ?? gradeLevelData.minNumberOfLearners;
|
|
42791
42990
|
const maxPerSection = value.maxStudents ?? gradeLevelData.maxNumberOfLearners;
|
|
42792
|
-
const sectionsNeeded = Math.ceil(studentCount / minPerSection);
|
|
42793
|
-
if (sectionsNeeded > value.set.length) {
|
|
42794
|
-
throw new import_nodejs_utils69.BadRequestError(
|
|
42795
|
-
"Insufficient number of section names in set[]."
|
|
42796
|
-
);
|
|
42797
|
-
}
|
|
42798
42991
|
const sectionSizes = distributeStudents(
|
|
42799
42992
|
studentCount,
|
|
42800
42993
|
minPerSection,
|
|
@@ -42808,10 +43001,30 @@ function useSectionService() {
|
|
|
42808
43001
|
throw new import_nodejs_utils69.BadRequestError("School not found.");
|
|
42809
43002
|
}
|
|
42810
43003
|
let totalStudentsProcessed = 0;
|
|
43004
|
+
let sectionsGenerated = 0;
|
|
43005
|
+
let sectionsSkipped = 0;
|
|
43006
|
+
let teachingLoadsCreated = 0;
|
|
43007
|
+
let teachingLoadsSkipped = 0;
|
|
43008
|
+
let studentCreated = 0;
|
|
43009
|
+
let studentSkipped = 0;
|
|
43010
|
+
let subjectsAssigned = 0;
|
|
43011
|
+
let subjectsSkipped = 0;
|
|
42811
43012
|
for (let i = 0; i < sectionSizes.length; i++) {
|
|
42812
43013
|
const size = sectionSizes[i];
|
|
42813
|
-
const sectionName =
|
|
42814
|
-
const
|
|
43014
|
+
const sectionName = String(i + 1);
|
|
43015
|
+
const existingSection = await getSection({
|
|
43016
|
+
gradeLevel: value.gradeLevel,
|
|
43017
|
+
schoolYear: value.schoolYear,
|
|
43018
|
+
name: sectionName,
|
|
43019
|
+
school: value.school
|
|
43020
|
+
});
|
|
43021
|
+
let sectionId = "";
|
|
43022
|
+
if (existingSection) {
|
|
43023
|
+
sectionId = existingSection._id?.toString() || "";
|
|
43024
|
+
sectionsSkipped++;
|
|
43025
|
+
continue;
|
|
43026
|
+
}
|
|
43027
|
+
sectionId = await createSection(
|
|
42815
43028
|
{
|
|
42816
43029
|
school: value.school,
|
|
42817
43030
|
schoolYear: value.schoolYear,
|
|
@@ -42821,6 +43034,10 @@ function useSectionService() {
|
|
|
42821
43034
|
},
|
|
42822
43035
|
session
|
|
42823
43036
|
);
|
|
43037
|
+
if (!sectionId) {
|
|
43038
|
+
throw new import_nodejs_utils69.InternalServerError("Required section ID is missing.");
|
|
43039
|
+
}
|
|
43040
|
+
sectionsGenerated++;
|
|
42824
43041
|
const skip = totalStudentsProcessed;
|
|
42825
43042
|
const learners = await getLeanerByGradeLevel(
|
|
42826
43043
|
{
|
|
@@ -42842,9 +43059,19 @@ function useSectionService() {
|
|
|
42842
43059
|
if (!student.learnerInfo.lrn) {
|
|
42843
43060
|
throw new import_nodejs_utils69.BadRequestError("Learner LRN is missing.");
|
|
42844
43061
|
}
|
|
43062
|
+
const existingStudent = await getStudent({
|
|
43063
|
+
student: student._id.toString(),
|
|
43064
|
+
schoolYear: value.schoolYear,
|
|
43065
|
+
section: sectionId,
|
|
43066
|
+
gradeLevel: value.gradeLevel
|
|
43067
|
+
});
|
|
43068
|
+
if (existingStudent) {
|
|
43069
|
+
studentSkipped++;
|
|
43070
|
+
continue;
|
|
43071
|
+
}
|
|
42845
43072
|
await assignStudent(
|
|
42846
43073
|
{
|
|
42847
|
-
section:
|
|
43074
|
+
section: sectionId,
|
|
42848
43075
|
lrn: student.learnerInfo.lrn,
|
|
42849
43076
|
student: student._id?.toString(),
|
|
42850
43077
|
studentName: `${student.learnerInfo.firstName} ${student.learnerInfo.lastName}`,
|
|
@@ -42857,37 +43084,50 @@ function useSectionService() {
|
|
|
42857
43084
|
},
|
|
42858
43085
|
session
|
|
42859
43086
|
);
|
|
43087
|
+
studentCreated++;
|
|
42860
43088
|
}
|
|
42861
|
-
|
|
42862
|
-
|
|
42863
|
-
|
|
42864
|
-
|
|
42865
|
-
|
|
42866
|
-
|
|
42867
|
-
|
|
42868
|
-
{
|
|
42869
|
-
|
|
42870
|
-
school: value.school,
|
|
42871
|
-
schoolName: schoolData.name,
|
|
42872
|
-
gradeLevel: value.gradeLevel,
|
|
42873
|
-
educationLevel: gradeLevelData.educationLevel,
|
|
42874
|
-
schoolYear: value.schoolYear,
|
|
42875
|
-
section: section.toString(),
|
|
42876
|
-
sectionName,
|
|
43089
|
+
if (value.gradeLevel !== "kindergarten") {
|
|
43090
|
+
const curriculumSubjects = await getAllCurriculumSubjects({
|
|
43091
|
+
schoolYear: Number(value.schoolYear),
|
|
43092
|
+
gradeLevel: value.gradeLevel,
|
|
43093
|
+
limit: 20
|
|
43094
|
+
});
|
|
43095
|
+
for (const curriculumSubject of curriculumSubjects.items) {
|
|
43096
|
+
const existingSectionSubject = await getSectionSubject({
|
|
43097
|
+
section: sectionId,
|
|
42877
43098
|
subjectCode: curriculumSubject.subjectCode,
|
|
42878
|
-
|
|
42879
|
-
|
|
42880
|
-
|
|
42881
|
-
|
|
42882
|
-
|
|
42883
|
-
|
|
42884
|
-
|
|
42885
|
-
|
|
42886
|
-
|
|
42887
|
-
|
|
42888
|
-
|
|
42889
|
-
|
|
42890
|
-
|
|
43099
|
+
schoolYear: value.schoolYear
|
|
43100
|
+
});
|
|
43101
|
+
if (existingSectionSubject) {
|
|
43102
|
+
subjectsSkipped++;
|
|
43103
|
+
continue;
|
|
43104
|
+
}
|
|
43105
|
+
await addSectionSubject(
|
|
43106
|
+
{
|
|
43107
|
+
curriculum: curriculumSubject.curriculum.toString(),
|
|
43108
|
+
school: value.school,
|
|
43109
|
+
schoolName: schoolData.name,
|
|
43110
|
+
gradeLevel: value.gradeLevel,
|
|
43111
|
+
educationLevel: gradeLevelData.educationLevel,
|
|
43112
|
+
schoolYear: value.schoolYear,
|
|
43113
|
+
section: sectionId,
|
|
43114
|
+
sectionName,
|
|
43115
|
+
subjectCode: curriculumSubject.subjectCode,
|
|
43116
|
+
subjectName: curriculumSubject.subjectName,
|
|
43117
|
+
teacher: "",
|
|
43118
|
+
teacherName: "",
|
|
43119
|
+
schedule: "",
|
|
43120
|
+
daysOfWeek: [],
|
|
43121
|
+
classroom: "",
|
|
43122
|
+
classroomName: "",
|
|
43123
|
+
sessionDuration: curriculumSubject.sessionDuration,
|
|
43124
|
+
sessionFrequency: curriculumSubject.sessionFrequency,
|
|
43125
|
+
status: "draft"
|
|
43126
|
+
},
|
|
43127
|
+
session
|
|
43128
|
+
);
|
|
43129
|
+
subjectsAssigned++;
|
|
43130
|
+
}
|
|
42891
43131
|
}
|
|
42892
43132
|
}
|
|
42893
43133
|
let pageTeacher = 1;
|
|
@@ -42896,7 +43136,9 @@ function useSectionService() {
|
|
|
42896
43136
|
do {
|
|
42897
43137
|
const teachersData = await getAllPersonnel({
|
|
42898
43138
|
school: value.school,
|
|
42899
|
-
limit: 100
|
|
43139
|
+
limit: 100,
|
|
43140
|
+
gradeLevel: value.gradeLevel,
|
|
43141
|
+
classification: "teaching"
|
|
42900
43142
|
});
|
|
42901
43143
|
pagesTeachers = teachersData.pages;
|
|
42902
43144
|
teachers.push(...teachersData.items);
|
|
@@ -42908,11 +43150,19 @@ function useSectionService() {
|
|
|
42908
43150
|
);
|
|
42909
43151
|
}
|
|
42910
43152
|
if (teachers.length) {
|
|
42911
|
-
for (
|
|
42912
|
-
const teacher = teachers[index];
|
|
43153
|
+
for (const teacher of teachers) {
|
|
42913
43154
|
if (!teacher._id) {
|
|
42914
43155
|
throw new import_nodejs_utils69.BadRequestError("Teacher ID is missing.");
|
|
42915
43156
|
}
|
|
43157
|
+
const existingLoad = await getByTeacher({
|
|
43158
|
+
teacher: teacher._id.toString(),
|
|
43159
|
+
school: value.school,
|
|
43160
|
+
schoolYear: value.schoolYear
|
|
43161
|
+
});
|
|
43162
|
+
if (existingLoad) {
|
|
43163
|
+
teachingLoadsSkipped++;
|
|
43164
|
+
continue;
|
|
43165
|
+
}
|
|
42916
43166
|
await addTeachingLoad(
|
|
42917
43167
|
{
|
|
42918
43168
|
school: value.school,
|
|
@@ -42924,10 +43174,26 @@ function useSectionService() {
|
|
|
42924
43174
|
},
|
|
42925
43175
|
session
|
|
42926
43176
|
);
|
|
43177
|
+
teachingLoadsCreated++;
|
|
42927
43178
|
}
|
|
42928
43179
|
}
|
|
42929
43180
|
await session.commitTransaction();
|
|
42930
|
-
return
|
|
43181
|
+
return {
|
|
43182
|
+
message: "Sections generated successfully.",
|
|
43183
|
+
summary: {
|
|
43184
|
+
sectionsGenerated,
|
|
43185
|
+
sectionsSkipped,
|
|
43186
|
+
totalSections: sectionsGenerated + sectionsSkipped,
|
|
43187
|
+
studentsProcessed: totalStudentsProcessed,
|
|
43188
|
+
studentCreated,
|
|
43189
|
+
studentSkipped,
|
|
43190
|
+
subjectsAssigned,
|
|
43191
|
+
subjectsSkipped,
|
|
43192
|
+
teachingLoadsCreated,
|
|
43193
|
+
teachingLoadsSkipped,
|
|
43194
|
+
totalStudents: studentCount
|
|
43195
|
+
}
|
|
43196
|
+
};
|
|
42931
43197
|
} catch (error2) {
|
|
42932
43198
|
await session.abortTransaction();
|
|
42933
43199
|
if (error2 instanceof import_nodejs_utils69.AppError) {
|
|
@@ -42965,12 +43231,6 @@ function useSectionService() {
|
|
|
42965
43231
|
}
|
|
42966
43232
|
const minPerSection = value.minStudents ?? gradeLevelData.minNumberOfLearners;
|
|
42967
43233
|
const maxPerSection = value.maxStudents ?? gradeLevelData.maxNumberOfLearners;
|
|
42968
|
-
const sectionsNeeded = Math.ceil(studentCount / minPerSection);
|
|
42969
|
-
if (sectionsNeeded > value.set.length) {
|
|
42970
|
-
throw new import_nodejs_utils69.BadRequestError(
|
|
42971
|
-
"Insufficient number of section names in set[]."
|
|
42972
|
-
);
|
|
42973
|
-
}
|
|
42974
43234
|
const sectionSizes = distributeStudents(
|
|
42975
43235
|
studentCount,
|
|
42976
43236
|
minPerSection,
|
|
@@ -42980,7 +43240,7 @@ function useSectionService() {
|
|
|
42980
43240
|
throw new import_nodejs_utils69.BadRequestError("Unable to compute section sizes.");
|
|
42981
43241
|
}
|
|
42982
43242
|
const sections = sectionSizes.map((size, index) => ({
|
|
42983
|
-
name:
|
|
43243
|
+
name: `${index + 1}`,
|
|
42984
43244
|
value: size
|
|
42985
43245
|
}));
|
|
42986
43246
|
return {
|