@eeplatform/basic-edu 1.8.7 → 1.8.8
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 +3 -0
- package/dist/index.js +121 -10
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +121 -10
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -3580,17 +3580,16 @@ function useLearnerRepo() {
|
|
|
3580
3580
|
school: Joi7.string().hex().required(),
|
|
3581
3581
|
schoolYear: Joi7.string().required(),
|
|
3582
3582
|
gradeLevel: Joi7.string().required(),
|
|
3583
|
+
specialProgram: Joi7.string().hex().optional().allow(null, ""),
|
|
3583
3584
|
status: Joi7.string().optional()
|
|
3584
3585
|
});
|
|
3585
3586
|
const { error } = validation.validate(value);
|
|
3586
3587
|
if (error) {
|
|
3587
3588
|
throw new BadRequestError9(`Invalid data: ${error.message}`);
|
|
3588
3589
|
}
|
|
3589
|
-
const status = value.status ?? "active";
|
|
3590
3590
|
const query = {
|
|
3591
3591
|
schoolYear: value.schoolYear,
|
|
3592
|
-
gradeLevel: value.gradeLevel
|
|
3593
|
-
status
|
|
3592
|
+
gradeLevel: value.gradeLevel
|
|
3594
3593
|
};
|
|
3595
3594
|
const cacheKeyOptions = {
|
|
3596
3595
|
...query,
|
|
@@ -3604,6 +3603,16 @@ function useLearnerRepo() {
|
|
|
3604
3603
|
}
|
|
3605
3604
|
cacheKeyOptions.school = value.school.toString();
|
|
3606
3605
|
}
|
|
3606
|
+
if (value.specialProgram) {
|
|
3607
|
+
try {
|
|
3608
|
+
query["learnerInfo.specialProgram"] = new ObjectId7(
|
|
3609
|
+
value.specialProgram
|
|
3610
|
+
);
|
|
3611
|
+
} catch (error2) {
|
|
3612
|
+
throw new BadRequestError9("Invalid special program ID.");
|
|
3613
|
+
}
|
|
3614
|
+
cacheKeyOptions.specialProgram = value.specialProgram.toString();
|
|
3615
|
+
}
|
|
3607
3616
|
const cacheKey = makeCacheKey4(namespace_collection, cacheKeyOptions);
|
|
3608
3617
|
const cachedData = await getCache(cacheKey);
|
|
3609
3618
|
if (cachedData !== void 0 && cachedData !== null) {
|
|
@@ -6252,7 +6261,8 @@ function useGradeLevelController() {
|
|
|
6252
6261
|
add: _add,
|
|
6253
6262
|
updateById: _updateById,
|
|
6254
6263
|
deleteById: _deleteById,
|
|
6255
|
-
getByEducationLevel: _getByEducationLevel
|
|
6264
|
+
getByEducationLevel: _getByEducationLevel,
|
|
6265
|
+
getByGradeLevel: _getByGradeLevel
|
|
6256
6266
|
} = useGradeLevelRepo();
|
|
6257
6267
|
async function add(req, res, next) {
|
|
6258
6268
|
const value = req.body;
|
|
@@ -6423,13 +6433,34 @@ function useGradeLevelController() {
|
|
|
6423
6433
|
next(error2);
|
|
6424
6434
|
}
|
|
6425
6435
|
}
|
|
6436
|
+
async function getByGradeLevel(req, res, next) {
|
|
6437
|
+
const gradeLevel = req.params.gradeLevel;
|
|
6438
|
+
const school = req.params.school;
|
|
6439
|
+
const validation = Joi16.object({
|
|
6440
|
+
gradeLevel: Joi16.string().required(),
|
|
6441
|
+
school: Joi16.string().hex().required()
|
|
6442
|
+
});
|
|
6443
|
+
const { error } = validation.validate({ gradeLevel, school });
|
|
6444
|
+
if (error) {
|
|
6445
|
+
next(new BadRequestError23(error.message));
|
|
6446
|
+
return;
|
|
6447
|
+
}
|
|
6448
|
+
try {
|
|
6449
|
+
const data = await _getByGradeLevel({ gradeLevel, school });
|
|
6450
|
+
res.json(data);
|
|
6451
|
+
return;
|
|
6452
|
+
} catch (error2) {
|
|
6453
|
+
next(error2);
|
|
6454
|
+
}
|
|
6455
|
+
}
|
|
6426
6456
|
return {
|
|
6427
6457
|
add,
|
|
6428
6458
|
getAll,
|
|
6429
6459
|
getById,
|
|
6430
6460
|
updateById,
|
|
6431
6461
|
deleteById,
|
|
6432
|
-
getByEducationLevel
|
|
6462
|
+
getByEducationLevel,
|
|
6463
|
+
getByGradeLevel
|
|
6433
6464
|
};
|
|
6434
6465
|
}
|
|
6435
6466
|
|
|
@@ -39050,6 +39081,9 @@ var schemaGenerateSections = Joi31.object({
|
|
|
39050
39081
|
school: Joi31.string().hex().required(),
|
|
39051
39082
|
schoolYear: Joi31.string().required(),
|
|
39052
39083
|
gradeLevel: Joi31.string().required(),
|
|
39084
|
+
minStudents: Joi31.number().integer().min(1).required(),
|
|
39085
|
+
maxStudents: Joi31.number().integer().min(Joi31.ref("minStudents")).required(),
|
|
39086
|
+
specialProgram: Joi31.string().hex().optional().allow(null, ""),
|
|
39053
39087
|
set: Joi31.array().items(Joi31.string().min(1).max(100)).required()
|
|
39054
39088
|
});
|
|
39055
39089
|
function modelSection(value) {
|
|
@@ -42519,7 +42553,8 @@ function useSectionService() {
|
|
|
42519
42553
|
{
|
|
42520
42554
|
school: value.school,
|
|
42521
42555
|
schoolYear: value.schoolYear,
|
|
42522
|
-
gradeLevel: value.gradeLevel
|
|
42556
|
+
gradeLevel: value.gradeLevel,
|
|
42557
|
+
specialProgram: value.specialProgram
|
|
42523
42558
|
},
|
|
42524
42559
|
session
|
|
42525
42560
|
);
|
|
@@ -42536,8 +42571,8 @@ function useSectionService() {
|
|
|
42536
42571
|
if (!gradeLevelData) {
|
|
42537
42572
|
throw new BadRequestError64("Grade level not found.");
|
|
42538
42573
|
}
|
|
42539
|
-
const minPerSection = gradeLevelData.minNumberOfLearners;
|
|
42540
|
-
const maxPerSection = gradeLevelData.maxNumberOfLearners;
|
|
42574
|
+
const minPerSection = value.minStudents ?? gradeLevelData.minNumberOfLearners;
|
|
42575
|
+
const maxPerSection = value.maxStudents ?? gradeLevelData.maxNumberOfLearners;
|
|
42541
42576
|
const sectionsNeeded = Math.ceil(studentCount / minPerSection);
|
|
42542
42577
|
if (sectionsNeeded > value.set.length) {
|
|
42543
42578
|
throw new BadRequestError64(
|
|
@@ -42683,7 +42718,64 @@ function useSectionService() {
|
|
|
42683
42718
|
await session?.endSession();
|
|
42684
42719
|
}
|
|
42685
42720
|
}
|
|
42686
|
-
|
|
42721
|
+
async function generateSectionPreview(value) {
|
|
42722
|
+
const { error } = schemaGenerateSections.validate(value);
|
|
42723
|
+
if (error) {
|
|
42724
|
+
throw new BadRequestError64(
|
|
42725
|
+
`Invalid section generation data: ${error.message}`
|
|
42726
|
+
);
|
|
42727
|
+
}
|
|
42728
|
+
try {
|
|
42729
|
+
const studentCount = await getCountByGradeLevel({
|
|
42730
|
+
school: value.school,
|
|
42731
|
+
schoolYear: value.schoolYear,
|
|
42732
|
+
gradeLevel: value.gradeLevel,
|
|
42733
|
+
specialProgram: value.specialProgram
|
|
42734
|
+
});
|
|
42735
|
+
if (studentCount === 0) {
|
|
42736
|
+
throw new BadRequestError64("No learners found for this grade level.");
|
|
42737
|
+
}
|
|
42738
|
+
const gradeLevelData = await getByGradeLevel({
|
|
42739
|
+
school: value.school,
|
|
42740
|
+
gradeLevel: value.gradeLevel
|
|
42741
|
+
});
|
|
42742
|
+
if (!gradeLevelData) {
|
|
42743
|
+
throw new BadRequestError64("Grade level not found.");
|
|
42744
|
+
}
|
|
42745
|
+
const minPerSection = value.minStudents ?? gradeLevelData.minNumberOfLearners;
|
|
42746
|
+
const maxPerSection = value.maxStudents ?? gradeLevelData.maxNumberOfLearners;
|
|
42747
|
+
const sectionsNeeded = Math.ceil(studentCount / minPerSection);
|
|
42748
|
+
if (sectionsNeeded > value.set.length) {
|
|
42749
|
+
throw new BadRequestError64(
|
|
42750
|
+
"Insufficient number of section names in set[]."
|
|
42751
|
+
);
|
|
42752
|
+
}
|
|
42753
|
+
const sectionSizes = distributeStudents(
|
|
42754
|
+
studentCount,
|
|
42755
|
+
minPerSection,
|
|
42756
|
+
maxPerSection
|
|
42757
|
+
);
|
|
42758
|
+
if (sectionSizes.length === 0) {
|
|
42759
|
+
throw new BadRequestError64("Unable to compute section sizes.");
|
|
42760
|
+
}
|
|
42761
|
+
const sections = sectionSizes.map((size, index) => ({
|
|
42762
|
+
name: value.set[index],
|
|
42763
|
+
value: size
|
|
42764
|
+
}));
|
|
42765
|
+
return {
|
|
42766
|
+
totalSectionsGenerated: sectionSizes.length,
|
|
42767
|
+
totalStudentsAssigned: studentCount,
|
|
42768
|
+
sections
|
|
42769
|
+
};
|
|
42770
|
+
} catch (error2) {
|
|
42771
|
+
if (error2 instanceof AppError25) {
|
|
42772
|
+
throw error2;
|
|
42773
|
+
} else {
|
|
42774
|
+
throw new InternalServerError21("Failed to generate section preview.");
|
|
42775
|
+
}
|
|
42776
|
+
}
|
|
42777
|
+
}
|
|
42778
|
+
return { generateSections, generateSectionPreview };
|
|
42687
42779
|
}
|
|
42688
42780
|
|
|
42689
42781
|
// src/resources/section/section.controller.ts
|
|
@@ -42699,7 +42791,10 @@ function useSectionController() {
|
|
|
42699
42791
|
removeStudentFromSection: _removeStudentFromSection,
|
|
42700
42792
|
deleteById: _deleteById
|
|
42701
42793
|
} = useSectionRepo();
|
|
42702
|
-
const {
|
|
42794
|
+
const {
|
|
42795
|
+
generateSections: _generateSections,
|
|
42796
|
+
generateSectionPreview: _generateSectionPreview
|
|
42797
|
+
} = useSectionService();
|
|
42703
42798
|
async function add(req, res, next) {
|
|
42704
42799
|
const value = req.body;
|
|
42705
42800
|
const { error } = schemaSection.validate(value);
|
|
@@ -42736,6 +42831,21 @@ function useSectionController() {
|
|
|
42736
42831
|
next(error2);
|
|
42737
42832
|
}
|
|
42738
42833
|
}
|
|
42834
|
+
async function generateSectionPreview(req, res, next) {
|
|
42835
|
+
const value = req.body;
|
|
42836
|
+
const { error } = schemaGenerateSections.validate(value);
|
|
42837
|
+
if (error) {
|
|
42838
|
+
next(new BadRequestError65(error.message));
|
|
42839
|
+
return;
|
|
42840
|
+
}
|
|
42841
|
+
try {
|
|
42842
|
+
const data = await _generateSectionPreview(value);
|
|
42843
|
+
res.json(data);
|
|
42844
|
+
return;
|
|
42845
|
+
} catch (error2) {
|
|
42846
|
+
next(error2);
|
|
42847
|
+
}
|
|
42848
|
+
}
|
|
42739
42849
|
async function getAll(req, res, next) {
|
|
42740
42850
|
const query = req.query;
|
|
42741
42851
|
const validation = Joi43.object({
|
|
@@ -42927,6 +43037,7 @@ function useSectionController() {
|
|
|
42927
43037
|
return {
|
|
42928
43038
|
add,
|
|
42929
43039
|
generateSections,
|
|
43040
|
+
generateSectionPreview,
|
|
42930
43041
|
getAll,
|
|
42931
43042
|
getById,
|
|
42932
43043
|
getByName,
|