@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/CHANGELOG.md
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -473,6 +473,7 @@ declare function useGradeLevelController(): {
|
|
|
473
473
|
updateById: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
474
474
|
deleteById: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
475
475
|
getByEducationLevel: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
476
|
+
getByGradeLevel: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
476
477
|
};
|
|
477
478
|
|
|
478
479
|
type TRegion = {
|
|
@@ -870,6 +871,7 @@ declare function useLearnerRepo(): {
|
|
|
870
871
|
school: string | ObjectId;
|
|
871
872
|
schoolYear: string;
|
|
872
873
|
gradeLevel: string;
|
|
874
|
+
specialProgram?: string | ObjectId;
|
|
873
875
|
status?: string;
|
|
874
876
|
}, session?: ClientSession) => Promise<number>;
|
|
875
877
|
updateStatusById: (_id: string | ObjectId, status: string, session?: ClientSession) => Promise<mongodb.UpdateResult<bson.Document>>;
|
|
@@ -1013,6 +1015,7 @@ declare function useSectionRepo(): {
|
|
|
1013
1015
|
declare function useSectionController(): {
|
|
1014
1016
|
add: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
1015
1017
|
generateSections: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
1018
|
+
generateSectionPreview: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
1016
1019
|
getAll: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
1017
1020
|
getById: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
1018
1021
|
getByName: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
package/dist/index.js
CHANGED
|
@@ -3649,17 +3649,16 @@ function useLearnerRepo() {
|
|
|
3649
3649
|
school: import_joi7.default.string().hex().required(),
|
|
3650
3650
|
schoolYear: import_joi7.default.string().required(),
|
|
3651
3651
|
gradeLevel: import_joi7.default.string().required(),
|
|
3652
|
+
specialProgram: import_joi7.default.string().hex().optional().allow(null, ""),
|
|
3652
3653
|
status: import_joi7.default.string().optional()
|
|
3653
3654
|
});
|
|
3654
3655
|
const { error } = validation.validate(value);
|
|
3655
3656
|
if (error) {
|
|
3656
3657
|
throw new import_nodejs_utils10.BadRequestError(`Invalid data: ${error.message}`);
|
|
3657
3658
|
}
|
|
3658
|
-
const status = value.status ?? "active";
|
|
3659
3659
|
const query = {
|
|
3660
3660
|
schoolYear: value.schoolYear,
|
|
3661
|
-
gradeLevel: value.gradeLevel
|
|
3662
|
-
status
|
|
3661
|
+
gradeLevel: value.gradeLevel
|
|
3663
3662
|
};
|
|
3664
3663
|
const cacheKeyOptions = {
|
|
3665
3664
|
...query,
|
|
@@ -3673,6 +3672,16 @@ function useLearnerRepo() {
|
|
|
3673
3672
|
}
|
|
3674
3673
|
cacheKeyOptions.school = value.school.toString();
|
|
3675
3674
|
}
|
|
3675
|
+
if (value.specialProgram) {
|
|
3676
|
+
try {
|
|
3677
|
+
query["learnerInfo.specialProgram"] = new import_mongodb7.ObjectId(
|
|
3678
|
+
value.specialProgram
|
|
3679
|
+
);
|
|
3680
|
+
} catch (error2) {
|
|
3681
|
+
throw new import_nodejs_utils10.BadRequestError("Invalid special program ID.");
|
|
3682
|
+
}
|
|
3683
|
+
cacheKeyOptions.specialProgram = value.specialProgram.toString();
|
|
3684
|
+
}
|
|
3676
3685
|
const cacheKey = (0, import_nodejs_utils10.makeCacheKey)(namespace_collection, cacheKeyOptions);
|
|
3677
3686
|
const cachedData = await getCache(cacheKey);
|
|
3678
3687
|
if (cachedData !== void 0 && cachedData !== null) {
|
|
@@ -6287,7 +6296,8 @@ function useGradeLevelController() {
|
|
|
6287
6296
|
add: _add,
|
|
6288
6297
|
updateById: _updateById,
|
|
6289
6298
|
deleteById: _deleteById,
|
|
6290
|
-
getByEducationLevel: _getByEducationLevel
|
|
6299
|
+
getByEducationLevel: _getByEducationLevel,
|
|
6300
|
+
getByGradeLevel: _getByGradeLevel
|
|
6291
6301
|
} = useGradeLevelRepo();
|
|
6292
6302
|
async function add(req, res, next) {
|
|
6293
6303
|
const value = req.body;
|
|
@@ -6458,13 +6468,34 @@ function useGradeLevelController() {
|
|
|
6458
6468
|
next(error2);
|
|
6459
6469
|
}
|
|
6460
6470
|
}
|
|
6471
|
+
async function getByGradeLevel(req, res, next) {
|
|
6472
|
+
const gradeLevel = req.params.gradeLevel;
|
|
6473
|
+
const school = req.params.school;
|
|
6474
|
+
const validation = import_joi16.default.object({
|
|
6475
|
+
gradeLevel: import_joi16.default.string().required(),
|
|
6476
|
+
school: import_joi16.default.string().hex().required()
|
|
6477
|
+
});
|
|
6478
|
+
const { error } = validation.validate({ gradeLevel, school });
|
|
6479
|
+
if (error) {
|
|
6480
|
+
next(new import_nodejs_utils25.BadRequestError(error.message));
|
|
6481
|
+
return;
|
|
6482
|
+
}
|
|
6483
|
+
try {
|
|
6484
|
+
const data = await _getByGradeLevel({ gradeLevel, school });
|
|
6485
|
+
res.json(data);
|
|
6486
|
+
return;
|
|
6487
|
+
} catch (error2) {
|
|
6488
|
+
next(error2);
|
|
6489
|
+
}
|
|
6490
|
+
}
|
|
6461
6491
|
return {
|
|
6462
6492
|
add,
|
|
6463
6493
|
getAll,
|
|
6464
6494
|
getById,
|
|
6465
6495
|
updateById,
|
|
6466
6496
|
deleteById,
|
|
6467
|
-
getByEducationLevel
|
|
6497
|
+
getByEducationLevel,
|
|
6498
|
+
getByGradeLevel
|
|
6468
6499
|
};
|
|
6469
6500
|
}
|
|
6470
6501
|
|
|
@@ -39017,6 +39048,9 @@ var schemaGenerateSections = import_joi31.default.object({
|
|
|
39017
39048
|
school: import_joi31.default.string().hex().required(),
|
|
39018
39049
|
schoolYear: import_joi31.default.string().required(),
|
|
39019
39050
|
gradeLevel: import_joi31.default.string().required(),
|
|
39051
|
+
minStudents: import_joi31.default.number().integer().min(1).required(),
|
|
39052
|
+
maxStudents: import_joi31.default.number().integer().min(import_joi31.default.ref("minStudents")).required(),
|
|
39053
|
+
specialProgram: import_joi31.default.string().hex().optional().allow(null, ""),
|
|
39020
39054
|
set: import_joi31.default.array().items(import_joi31.default.string().min(1).max(100)).required()
|
|
39021
39055
|
});
|
|
39022
39056
|
function modelSection(value) {
|
|
@@ -42427,7 +42461,8 @@ function useSectionService() {
|
|
|
42427
42461
|
{
|
|
42428
42462
|
school: value.school,
|
|
42429
42463
|
schoolYear: value.schoolYear,
|
|
42430
|
-
gradeLevel: value.gradeLevel
|
|
42464
|
+
gradeLevel: value.gradeLevel,
|
|
42465
|
+
specialProgram: value.specialProgram
|
|
42431
42466
|
},
|
|
42432
42467
|
session
|
|
42433
42468
|
);
|
|
@@ -42444,8 +42479,8 @@ function useSectionService() {
|
|
|
42444
42479
|
if (!gradeLevelData) {
|
|
42445
42480
|
throw new import_nodejs_utils69.BadRequestError("Grade level not found.");
|
|
42446
42481
|
}
|
|
42447
|
-
const minPerSection = gradeLevelData.minNumberOfLearners;
|
|
42448
|
-
const maxPerSection = gradeLevelData.maxNumberOfLearners;
|
|
42482
|
+
const minPerSection = value.minStudents ?? gradeLevelData.minNumberOfLearners;
|
|
42483
|
+
const maxPerSection = value.maxStudents ?? gradeLevelData.maxNumberOfLearners;
|
|
42449
42484
|
const sectionsNeeded = Math.ceil(studentCount / minPerSection);
|
|
42450
42485
|
if (sectionsNeeded > value.set.length) {
|
|
42451
42486
|
throw new import_nodejs_utils69.BadRequestError(
|
|
@@ -42591,7 +42626,64 @@ function useSectionService() {
|
|
|
42591
42626
|
await session?.endSession();
|
|
42592
42627
|
}
|
|
42593
42628
|
}
|
|
42594
|
-
|
|
42629
|
+
async function generateSectionPreview(value) {
|
|
42630
|
+
const { error } = schemaGenerateSections.validate(value);
|
|
42631
|
+
if (error) {
|
|
42632
|
+
throw new import_nodejs_utils69.BadRequestError(
|
|
42633
|
+
`Invalid section generation data: ${error.message}`
|
|
42634
|
+
);
|
|
42635
|
+
}
|
|
42636
|
+
try {
|
|
42637
|
+
const studentCount = await getCountByGradeLevel({
|
|
42638
|
+
school: value.school,
|
|
42639
|
+
schoolYear: value.schoolYear,
|
|
42640
|
+
gradeLevel: value.gradeLevel,
|
|
42641
|
+
specialProgram: value.specialProgram
|
|
42642
|
+
});
|
|
42643
|
+
if (studentCount === 0) {
|
|
42644
|
+
throw new import_nodejs_utils69.BadRequestError("No learners found for this grade level.");
|
|
42645
|
+
}
|
|
42646
|
+
const gradeLevelData = await getByGradeLevel({
|
|
42647
|
+
school: value.school,
|
|
42648
|
+
gradeLevel: value.gradeLevel
|
|
42649
|
+
});
|
|
42650
|
+
if (!gradeLevelData) {
|
|
42651
|
+
throw new import_nodejs_utils69.BadRequestError("Grade level not found.");
|
|
42652
|
+
}
|
|
42653
|
+
const minPerSection = value.minStudents ?? gradeLevelData.minNumberOfLearners;
|
|
42654
|
+
const maxPerSection = value.maxStudents ?? gradeLevelData.maxNumberOfLearners;
|
|
42655
|
+
const sectionsNeeded = Math.ceil(studentCount / minPerSection);
|
|
42656
|
+
if (sectionsNeeded > value.set.length) {
|
|
42657
|
+
throw new import_nodejs_utils69.BadRequestError(
|
|
42658
|
+
"Insufficient number of section names in set[]."
|
|
42659
|
+
);
|
|
42660
|
+
}
|
|
42661
|
+
const sectionSizes = distributeStudents(
|
|
42662
|
+
studentCount,
|
|
42663
|
+
minPerSection,
|
|
42664
|
+
maxPerSection
|
|
42665
|
+
);
|
|
42666
|
+
if (sectionSizes.length === 0) {
|
|
42667
|
+
throw new import_nodejs_utils69.BadRequestError("Unable to compute section sizes.");
|
|
42668
|
+
}
|
|
42669
|
+
const sections = sectionSizes.map((size, index) => ({
|
|
42670
|
+
name: value.set[index],
|
|
42671
|
+
value: size
|
|
42672
|
+
}));
|
|
42673
|
+
return {
|
|
42674
|
+
totalSectionsGenerated: sectionSizes.length,
|
|
42675
|
+
totalStudentsAssigned: studentCount,
|
|
42676
|
+
sections
|
|
42677
|
+
};
|
|
42678
|
+
} catch (error2) {
|
|
42679
|
+
if (error2 instanceof import_nodejs_utils69.AppError) {
|
|
42680
|
+
throw error2;
|
|
42681
|
+
} else {
|
|
42682
|
+
throw new import_nodejs_utils69.InternalServerError("Failed to generate section preview.");
|
|
42683
|
+
}
|
|
42684
|
+
}
|
|
42685
|
+
}
|
|
42686
|
+
return { generateSections, generateSectionPreview };
|
|
42595
42687
|
}
|
|
42596
42688
|
|
|
42597
42689
|
// src/resources/section/section.controller.ts
|
|
@@ -42607,7 +42699,10 @@ function useSectionController() {
|
|
|
42607
42699
|
removeStudentFromSection: _removeStudentFromSection,
|
|
42608
42700
|
deleteById: _deleteById
|
|
42609
42701
|
} = useSectionRepo();
|
|
42610
|
-
const {
|
|
42702
|
+
const {
|
|
42703
|
+
generateSections: _generateSections,
|
|
42704
|
+
generateSectionPreview: _generateSectionPreview
|
|
42705
|
+
} = useSectionService();
|
|
42611
42706
|
async function add(req, res, next) {
|
|
42612
42707
|
const value = req.body;
|
|
42613
42708
|
const { error } = schemaSection.validate(value);
|
|
@@ -42644,6 +42739,21 @@ function useSectionController() {
|
|
|
42644
42739
|
next(error2);
|
|
42645
42740
|
}
|
|
42646
42741
|
}
|
|
42742
|
+
async function generateSectionPreview(req, res, next) {
|
|
42743
|
+
const value = req.body;
|
|
42744
|
+
const { error } = schemaGenerateSections.validate(value);
|
|
42745
|
+
if (error) {
|
|
42746
|
+
next(new import_nodejs_utils70.BadRequestError(error.message));
|
|
42747
|
+
return;
|
|
42748
|
+
}
|
|
42749
|
+
try {
|
|
42750
|
+
const data = await _generateSectionPreview(value);
|
|
42751
|
+
res.json(data);
|
|
42752
|
+
return;
|
|
42753
|
+
} catch (error2) {
|
|
42754
|
+
next(error2);
|
|
42755
|
+
}
|
|
42756
|
+
}
|
|
42647
42757
|
async function getAll(req, res, next) {
|
|
42648
42758
|
const query = req.query;
|
|
42649
42759
|
const validation = import_joi43.default.object({
|
|
@@ -42835,6 +42945,7 @@ function useSectionController() {
|
|
|
42835
42945
|
return {
|
|
42836
42946
|
add,
|
|
42837
42947
|
generateSections,
|
|
42948
|
+
generateSectionPreview,
|
|
42838
42949
|
getAll,
|
|
42839
42950
|
getById,
|
|
42840
42951
|
getByName,
|