@eeplatform/basic-edu 1.10.8 → 1.10.9

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/dist/index.mjs CHANGED
@@ -2038,7 +2038,7 @@ import Joi3 from "joi";
2038
2038
  import { ObjectId as ObjectId3 } from "mongodb";
2039
2039
  var schemaSubject = Joi3.object({
2040
2040
  _id: Joi3.string().hex().optional(),
2041
- school: Joi3.string().hex().optional().allow("", null),
2041
+ school: Joi3.string().hex().required(),
2042
2042
  schoolName: Joi3.string().optional().allow("", null),
2043
2043
  curriculum: Joi3.string().hex().required(),
2044
2044
  curriculumName: Joi3.string().required(),
@@ -2065,6 +2065,8 @@ var schemaSubject = Joi3.object({
2065
2065
  deletedBy: Joi3.string().optional().allow("", null)
2066
2066
  });
2067
2067
  var schemaSubjectAdd = Joi3.object({
2068
+ school: Joi3.string().hex().required(),
2069
+ schoolName: Joi3.string().optional().allow("", null),
2068
2070
  curriculum: Joi3.string().hex().required(),
2069
2071
  curriculumName: Joi3.string().required(),
2070
2072
  effectiveSchoolYear: Joi3.array().items(Joi3.number().integer().min(1900)).optional(),
@@ -2088,6 +2090,11 @@ function modelSubject(value) {
2088
2090
  logger4.info(`Subject Model: ${error.message}`);
2089
2091
  throw new BadRequestError4(error.message);
2090
2092
  }
2093
+ try {
2094
+ value.school = new ObjectId3(value.school);
2095
+ } catch (error2) {
2096
+ throw new BadRequestError4("Invalid school ID format");
2097
+ }
2091
2098
  if (value._id && typeof value._id === "string") {
2092
2099
  try {
2093
2100
  value._id = new ObjectId3(value._id);
@@ -2102,13 +2109,6 @@ function modelSubject(value) {
2102
2109
  throw new BadRequestError4("Invalid curriculum ID format");
2103
2110
  }
2104
2111
  }
2105
- if (value.school && typeof value.school === "string") {
2106
- try {
2107
- value.school = new ObjectId3(value.school);
2108
- } catch (error2) {
2109
- throw new BadRequestError4("Invalid school ID format");
2110
- }
2111
- }
2112
2112
  if (value.program && typeof value.program === "string") {
2113
2113
  try {
2114
2114
  value.program = new ObjectId3(value.program);
@@ -2237,6 +2237,7 @@ function useSubjectRepo() {
2237
2237
  }
2238
2238
  }
2239
2239
  async function getAll({
2240
+ school = "",
2240
2241
  search = "",
2241
2242
  page = 1,
2242
2243
  limit = 10,
@@ -2244,18 +2245,27 @@ function useSubjectRepo() {
2244
2245
  status = "active",
2245
2246
  curriculum,
2246
2247
  educationLevel,
2247
- gradeLevel,
2248
- schoolYear = 0
2248
+ gradeLevel
2249
2249
  } = {}) {
2250
2250
  page = page > 0 ? page - 1 : 0;
2251
- const query = {
2252
- status
2253
- };
2251
+ const query = {};
2254
2252
  const cacheParams = {
2255
2253
  page,
2256
2254
  limit,
2257
2255
  sort: JSON.stringify(sort)
2258
2256
  };
2257
+ if (status) {
2258
+ query.status = status;
2259
+ cacheParams.status = status;
2260
+ }
2261
+ if (school) {
2262
+ try {
2263
+ query.school = new ObjectId4(school);
2264
+ } catch (error) {
2265
+ throw new BadRequestError5("Invalid school ID format.");
2266
+ }
2267
+ cacheParams.school = school;
2268
+ }
2259
2269
  if (curriculum) {
2260
2270
  try {
2261
2271
  query.curriculum = new ObjectId4(curriculum);
@@ -2272,10 +2282,6 @@ function useSubjectRepo() {
2272
2282
  query.gradeLevel = gradeLevel;
2273
2283
  cacheParams.gradeLevel = gradeLevel;
2274
2284
  }
2275
- if (schoolYear) {
2276
- query.effectiveSchoolYear = schoolYear;
2277
- cacheParams.schoolYear = schoolYear;
2278
- }
2279
2285
  sort = Object.keys(sort).length > 0 ? sort : { _id: -1 };
2280
2286
  if (search) {
2281
2287
  query.$or = [
@@ -2587,6 +2593,8 @@ function useSubjectService() {
2587
2593
  const gradeLevel = value.gradeLevel[index];
2588
2594
  await add(
2589
2595
  {
2596
+ school: value.school,
2597
+ schoolName: value.schoolName,
2590
2598
  curriculum: value.curriculum,
2591
2599
  curriculumName: value.curriculumName,
2592
2600
  effectiveSchoolYear: value.effectiveSchoolYear,
@@ -2738,6 +2746,62 @@ function useSubjectController() {
2738
2746
  next(error2);
2739
2747
  }
2740
2748
  }
2749
+ async function getBySchool(req, res, next) {
2750
+ const school = req.params.school ?? "";
2751
+ const { error: errorSchool } = Joi4.string().hex().required().validate(school);
2752
+ if (errorSchool) {
2753
+ next(new BadRequestError6(errorSchool.message));
2754
+ return;
2755
+ }
2756
+ const query = req.query;
2757
+ const validation = Joi4.object({
2758
+ page: Joi4.number().min(1).optional().allow("", null),
2759
+ limit: Joi4.number().min(1).optional().allow("", null),
2760
+ search: Joi4.string().optional().allow("", null),
2761
+ status: Joi4.string().optional().allow("", null),
2762
+ curriculum: Joi4.string().hex().optional().allow("", null),
2763
+ educationLevel: Joi4.string().optional().allow("", null),
2764
+ gradeLevel: Joi4.string().optional().allow("", null)
2765
+ });
2766
+ const { error } = validation.validate(query);
2767
+ if (error) {
2768
+ next(new BadRequestError6(error.message));
2769
+ return;
2770
+ }
2771
+ const page = parseInt(req.query.page) ?? 1;
2772
+ let limit = parseInt(req.query.limit) ?? 20;
2773
+ limit = isNaN(limit) ? 20 : limit;
2774
+ const sort = req.query.sort ? String(req.query.sort).split(",") : "";
2775
+ const sortOrder = req.query.sortOrder ? String(req.query.sortOrder).split(",") : "";
2776
+ const sortObj = {};
2777
+ if (sort && Array.isArray(sort) && sort.length && sortOrder && Array.isArray(sortOrder) && sortOrder.length) {
2778
+ sort.forEach((field, index) => {
2779
+ sortObj[field] = sortOrder[index] === "desc" ? -1 : 1;
2780
+ });
2781
+ }
2782
+ const status = req.query.status ?? "active";
2783
+ const search = req.query.search ?? "";
2784
+ const curriculum = req.query.curriculum ?? "";
2785
+ const educationLevel = req.query.educationLevel ?? "";
2786
+ const gradeLevel = req.query.gradeLevel ?? "";
2787
+ try {
2788
+ const curriculumSubjects = await _getAll({
2789
+ school,
2790
+ page,
2791
+ limit,
2792
+ sort: sortObj,
2793
+ status,
2794
+ search,
2795
+ curriculum,
2796
+ educationLevel,
2797
+ gradeLevel
2798
+ });
2799
+ res.json(curriculumSubjects);
2800
+ return;
2801
+ } catch (error2) {
2802
+ next(error2);
2803
+ }
2804
+ }
2741
2805
  async function getAsOptions(req, res, next) {
2742
2806
  const query = req.query;
2743
2807
  const validation = Joi4.object({
@@ -2845,6 +2909,7 @@ function useSubjectController() {
2845
2909
  return {
2846
2910
  add,
2847
2911
  addMany,
2912
+ getBySchool,
2848
2913
  getAll,
2849
2914
  getById,
2850
2915
  getByCurriculum,
@@ -42525,6 +42590,32 @@ function useTeachingLoadSlotRepo() {
42525
42590
  }
42526
42591
  }
42527
42592
  }
42593
+ async function deleteBySection(section, session) {
42594
+ try {
42595
+ section = new ObjectId40(section);
42596
+ } catch (error) {
42597
+ throw new BadRequestError63(namespace_collection + " Invalid section ID.");
42598
+ }
42599
+ try {
42600
+ const res = await collection.updateOne(
42601
+ { section },
42602
+ { $set: { status: "deleted", deletedAt: /* @__PURE__ */ new Date() } },
42603
+ { session }
42604
+ );
42605
+ delCachedData();
42606
+ return res;
42607
+ } catch (error) {
42608
+ logger35.log({
42609
+ level: "error",
42610
+ message: error.message
42611
+ });
42612
+ if (error instanceof AppError23) {
42613
+ throw error;
42614
+ } else {
42615
+ throw new InternalServerError19("Failed to delete teaching load slot.");
42616
+ }
42617
+ }
42618
+ }
42528
42619
  function delCachedData() {
42529
42620
  delNamespace().then(() => {
42530
42621
  logger35.log({
@@ -42545,7 +42636,8 @@ function useTeachingLoadSlotRepo() {
42545
42636
  getAll,
42546
42637
  getById,
42547
42638
  deleteById,
42548
- delCachedData
42639
+ delCachedData,
42640
+ deleteBySection
42549
42641
  };
42550
42642
  }
42551
42643
 
@@ -42661,6 +42753,43 @@ function useTeachingLoadSlotController() {
42661
42753
  next(error2);
42662
42754
  }
42663
42755
  }
42756
+ async function getBySection(req, res, next) {
42757
+ const section = req.params.section ?? "";
42758
+ const validation = Joi42.string().hex().required();
42759
+ const { error: errorTeacher } = validation.validate(section);
42760
+ if (errorTeacher) {
42761
+ next(new BadRequestError64(errorTeacher.message));
42762
+ logger36.info(`Controller: ${errorTeacher.message}`);
42763
+ return;
42764
+ }
42765
+ const query = req.query;
42766
+ const schema = Joi42.object({
42767
+ page: Joi42.number().min(1).optional().allow("", null),
42768
+ limit: Joi42.number().min(1).max(100).optional().allow("", null),
42769
+ status: Joi42.string().optional().allow("", null)
42770
+ });
42771
+ const { error } = schema.validate(query);
42772
+ if (error) {
42773
+ next(new BadRequestError64(error.message));
42774
+ logger36.info(`Controller: ${error.message}`);
42775
+ return;
42776
+ }
42777
+ const page = Number(req.query.page ?? 1);
42778
+ const limit = Number(req.query.limit ?? 10);
42779
+ const status = req.query.status ?? "active";
42780
+ try {
42781
+ const result = await _getAll({
42782
+ section,
42783
+ page,
42784
+ limit,
42785
+ status
42786
+ });
42787
+ res.json(result);
42788
+ return;
42789
+ } catch (error2) {
42790
+ next(error2);
42791
+ }
42792
+ }
42664
42793
  async function getByTeacher(req, res, next) {
42665
42794
  const teacher = req.params.teacher ?? "";
42666
42795
  const schemaTeacher = Joi42.string().hex().required();
@@ -42849,7 +42978,8 @@ function useTeachingLoadSlotController() {
42849
42978
  getById,
42850
42979
  deleteById,
42851
42980
  getByTeachingLoad,
42852
- getByTeacher
42981
+ getByTeacher,
42982
+ getBySection
42853
42983
  };
42854
42984
  }
42855
42985
 
@@ -43441,6 +43571,7 @@ function useSectionService() {
43441
43571
  const { getById: getSchoolById } = useSchoolRepo();
43442
43572
  const { getAll: getAllPersonnel } = usePersonnelRepo();
43443
43573
  const { add: addTeachingLoad, getByTeacher } = useTeachingLoadRepo();
43574
+ const { deleteBySection: deleteTeachingLoadSlotsBySection } = useTeachingLoadSlotRepo();
43444
43575
  function distributeStudents(total, minPer, maxPer) {
43445
43576
  if (total <= 0)
43446
43577
  return [];
@@ -43542,7 +43673,6 @@ function useSectionService() {
43542
43673
  let subjectsSkipped = 0;
43543
43674
  await delCachedSectionData();
43544
43675
  await delCachedSectionStudentData();
43545
- console.log("SECTION SIZES:", sectionSizes);
43546
43676
  for (let i = 0; i < sectionSizes.length; i++) {
43547
43677
  const size = sectionSizes[i];
43548
43678
  const sectionName = String(i + 1);
@@ -43705,6 +43835,7 @@ function useSectionService() {
43705
43835
  continue;
43706
43836
  }
43707
43837
  await deleteSectionById(sectionId, session);
43838
+ await deleteTeachingLoadSlotsBySection(sectionId, session);
43708
43839
  }
43709
43840
  }
43710
43841
  await session.commitTransaction();
@@ -43725,7 +43856,6 @@ function useSectionService() {
43725
43856
  }
43726
43857
  };
43727
43858
  } catch (error2) {
43728
- console.log(error2);
43729
43859
  await session.abortTransaction();
43730
43860
  if (error2 instanceof AppError26) {
43731
43861
  throw error2;