@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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @eeplatform/basic-edu
2
2
 
3
+ ## 1.10.9
4
+
5
+ ### Patch Changes
6
+
7
+ - 113f487: Section management - fix section generation
8
+
3
9
  ## 1.10.8
4
10
 
5
11
  ### Patch Changes
package/dist/index.d.ts CHANGED
@@ -80,7 +80,7 @@ declare function useCurriculumController(): {
80
80
 
81
81
  type TSubject = {
82
82
  _id?: ObjectId;
83
- school?: ObjectId;
83
+ school: string | ObjectId;
84
84
  schoolName?: string;
85
85
  curriculum: ObjectId | string;
86
86
  curriculumName: string;
@@ -110,7 +110,7 @@ declare const schemaSubject: Joi.ObjectSchema<any>;
110
110
  declare const schemaSubjectAdd: Joi.ObjectSchema<any>;
111
111
  declare function modelSubject(value: TSubject): {
112
112
  _id: ObjectId | undefined;
113
- school: ObjectId | undefined;
113
+ school: ObjectId;
114
114
  schoolName: string;
115
115
  curriculum: ObjectId;
116
116
  curriculumName: string;
@@ -140,7 +140,8 @@ declare function modelSubject(value: TSubject): {
140
140
  declare function useSubjectRepo(): {
141
141
  createIndexes: () => Promise<void>;
142
142
  add: (value: TSubject, session?: ClientSession) => Promise<ObjectId>;
143
- getAll: ({ search, page, limit, sort, status, curriculum, educationLevel, gradeLevel, schoolYear, }?: {
143
+ getAll: ({ school, search, page, limit, sort, status, curriculum, educationLevel, gradeLevel, }?: {
144
+ school?: string | ObjectId;
144
145
  search?: string;
145
146
  page?: number;
146
147
  limit?: number;
@@ -166,6 +167,8 @@ declare function useSubjectRepo(): {
166
167
  declare function useSubjectController(): {
167
168
  add: (req: Request, res: Response, next: NextFunction) => Promise<void>;
168
169
  addMany: (value: {
170
+ school: string;
171
+ schoolName?: string;
169
172
  curriculum: string;
170
173
  curriculumName: string;
171
174
  effectiveSchoolYear?: number[];
@@ -178,6 +181,7 @@ declare function useSubjectController(): {
178
181
  sessionDuration: number;
179
182
  totalMinutesPerWeek: number;
180
183
  }) => Promise<string>;
184
+ getBySchool: (req: Request, res: Response, next: NextFunction) => Promise<void>;
181
185
  getAll: (req: Request, res: Response, next: NextFunction) => Promise<void>;
182
186
  getById: (req: Request, res: Response, next: NextFunction) => Promise<void>;
183
187
  getByCurriculum: (req: Request, res: Response, next: NextFunction) => Promise<void>;
@@ -189,6 +193,8 @@ declare function useSubjectController(): {
189
193
 
190
194
  declare function useSubjectService(): {
191
195
  addMany: (value: {
196
+ school: string;
197
+ schoolName?: string;
192
198
  curriculum: string;
193
199
  curriculumName: string;
194
200
  effectiveSchoolYear?: number[];
@@ -1584,6 +1590,7 @@ declare function useTeachingLoadSlotRepo(): {
1584
1590
  getById: (_id: string | ObjectId) => Promise<TTeachingLoadSlot | null>;
1585
1591
  deleteById: (_id: string | ObjectId, session?: ClientSession) => Promise<mongodb.UpdateResult<bson.Document>>;
1586
1592
  delCachedData: () => void;
1593
+ deleteBySection: (section: string | ObjectId, session?: ClientSession) => Promise<mongodb.UpdateResult<bson.Document>>;
1587
1594
  };
1588
1595
 
1589
1596
  declare function useTeachingLoadSlotController(): {
@@ -1594,6 +1601,7 @@ declare function useTeachingLoadSlotController(): {
1594
1601
  deleteById: (req: Request, res: Response, next: NextFunction) => Promise<void>;
1595
1602
  getByTeachingLoad: (req: Request, res: Response, next: NextFunction) => Promise<void>;
1596
1603
  getByTeacher: (req: Request, res: Response, next: NextFunction) => Promise<void>;
1604
+ getBySection: (req: Request, res: Response, next: NextFunction) => Promise<void>;
1597
1605
  };
1598
1606
 
1599
1607
  type TProgram = {
package/dist/index.js CHANGED
@@ -2163,7 +2163,7 @@ var import_joi3 = __toESM(require("joi"));
2163
2163
  var import_mongodb3 = require("mongodb");
2164
2164
  var schemaSubject = import_joi3.default.object({
2165
2165
  _id: import_joi3.default.string().hex().optional(),
2166
- school: import_joi3.default.string().hex().optional().allow("", null),
2166
+ school: import_joi3.default.string().hex().required(),
2167
2167
  schoolName: import_joi3.default.string().optional().allow("", null),
2168
2168
  curriculum: import_joi3.default.string().hex().required(),
2169
2169
  curriculumName: import_joi3.default.string().required(),
@@ -2190,6 +2190,8 @@ var schemaSubject = import_joi3.default.object({
2190
2190
  deletedBy: import_joi3.default.string().optional().allow("", null)
2191
2191
  });
2192
2192
  var schemaSubjectAdd = import_joi3.default.object({
2193
+ school: import_joi3.default.string().hex().required(),
2194
+ schoolName: import_joi3.default.string().optional().allow("", null),
2193
2195
  curriculum: import_joi3.default.string().hex().required(),
2194
2196
  curriculumName: import_joi3.default.string().required(),
2195
2197
  effectiveSchoolYear: import_joi3.default.array().items(import_joi3.default.number().integer().min(1900)).optional(),
@@ -2213,6 +2215,11 @@ function modelSubject(value) {
2213
2215
  import_nodejs_utils4.logger.info(`Subject Model: ${error.message}`);
2214
2216
  throw new import_nodejs_utils4.BadRequestError(error.message);
2215
2217
  }
2218
+ try {
2219
+ value.school = new import_mongodb3.ObjectId(value.school);
2220
+ } catch (error2) {
2221
+ throw new import_nodejs_utils4.BadRequestError("Invalid school ID format");
2222
+ }
2216
2223
  if (value._id && typeof value._id === "string") {
2217
2224
  try {
2218
2225
  value._id = new import_mongodb3.ObjectId(value._id);
@@ -2227,13 +2234,6 @@ function modelSubject(value) {
2227
2234
  throw new import_nodejs_utils4.BadRequestError("Invalid curriculum ID format");
2228
2235
  }
2229
2236
  }
2230
- if (value.school && typeof value.school === "string") {
2231
- try {
2232
- value.school = new import_mongodb3.ObjectId(value.school);
2233
- } catch (error2) {
2234
- throw new import_nodejs_utils4.BadRequestError("Invalid school ID format");
2235
- }
2236
- }
2237
2237
  if (value.program && typeof value.program === "string") {
2238
2238
  try {
2239
2239
  value.program = new import_mongodb3.ObjectId(value.program);
@@ -2353,6 +2353,7 @@ function useSubjectRepo() {
2353
2353
  }
2354
2354
  }
2355
2355
  async function getAll({
2356
+ school = "",
2356
2357
  search = "",
2357
2358
  page = 1,
2358
2359
  limit = 10,
@@ -2360,18 +2361,27 @@ function useSubjectRepo() {
2360
2361
  status = "active",
2361
2362
  curriculum,
2362
2363
  educationLevel,
2363
- gradeLevel,
2364
- schoolYear = 0
2364
+ gradeLevel
2365
2365
  } = {}) {
2366
2366
  page = page > 0 ? page - 1 : 0;
2367
- const query = {
2368
- status
2369
- };
2367
+ const query = {};
2370
2368
  const cacheParams = {
2371
2369
  page,
2372
2370
  limit,
2373
2371
  sort: JSON.stringify(sort)
2374
2372
  };
2373
+ if (status) {
2374
+ query.status = status;
2375
+ cacheParams.status = status;
2376
+ }
2377
+ if (school) {
2378
+ try {
2379
+ query.school = new import_mongodb4.ObjectId(school);
2380
+ } catch (error) {
2381
+ throw new import_nodejs_utils5.BadRequestError("Invalid school ID format.");
2382
+ }
2383
+ cacheParams.school = school;
2384
+ }
2375
2385
  if (curriculum) {
2376
2386
  try {
2377
2387
  query.curriculum = new import_mongodb4.ObjectId(curriculum);
@@ -2388,10 +2398,6 @@ function useSubjectRepo() {
2388
2398
  query.gradeLevel = gradeLevel;
2389
2399
  cacheParams.gradeLevel = gradeLevel;
2390
2400
  }
2391
- if (schoolYear) {
2392
- query.effectiveSchoolYear = schoolYear;
2393
- cacheParams.schoolYear = schoolYear;
2394
- }
2395
2401
  sort = Object.keys(sort).length > 0 ? sort : { _id: -1 };
2396
2402
  if (search) {
2397
2403
  query.$or = [
@@ -2699,6 +2705,8 @@ function useSubjectService() {
2699
2705
  const gradeLevel = value.gradeLevel[index];
2700
2706
  await add(
2701
2707
  {
2708
+ school: value.school,
2709
+ schoolName: value.schoolName,
2702
2710
  curriculum: value.curriculum,
2703
2711
  curriculumName: value.curriculumName,
2704
2712
  effectiveSchoolYear: value.effectiveSchoolYear,
@@ -2850,6 +2858,62 @@ function useSubjectController() {
2850
2858
  next(error2);
2851
2859
  }
2852
2860
  }
2861
+ async function getBySchool(req, res, next) {
2862
+ const school = req.params.school ?? "";
2863
+ const { error: errorSchool } = import_joi4.default.string().hex().required().validate(school);
2864
+ if (errorSchool) {
2865
+ next(new import_nodejs_utils7.BadRequestError(errorSchool.message));
2866
+ return;
2867
+ }
2868
+ const query = req.query;
2869
+ const validation = import_joi4.default.object({
2870
+ page: import_joi4.default.number().min(1).optional().allow("", null),
2871
+ limit: import_joi4.default.number().min(1).optional().allow("", null),
2872
+ search: import_joi4.default.string().optional().allow("", null),
2873
+ status: import_joi4.default.string().optional().allow("", null),
2874
+ curriculum: import_joi4.default.string().hex().optional().allow("", null),
2875
+ educationLevel: import_joi4.default.string().optional().allow("", null),
2876
+ gradeLevel: import_joi4.default.string().optional().allow("", null)
2877
+ });
2878
+ const { error } = validation.validate(query);
2879
+ if (error) {
2880
+ next(new import_nodejs_utils7.BadRequestError(error.message));
2881
+ return;
2882
+ }
2883
+ const page = parseInt(req.query.page) ?? 1;
2884
+ let limit = parseInt(req.query.limit) ?? 20;
2885
+ limit = isNaN(limit) ? 20 : limit;
2886
+ const sort = req.query.sort ? String(req.query.sort).split(",") : "";
2887
+ const sortOrder = req.query.sortOrder ? String(req.query.sortOrder).split(",") : "";
2888
+ const sortObj = {};
2889
+ if (sort && Array.isArray(sort) && sort.length && sortOrder && Array.isArray(sortOrder) && sortOrder.length) {
2890
+ sort.forEach((field, index) => {
2891
+ sortObj[field] = sortOrder[index] === "desc" ? -1 : 1;
2892
+ });
2893
+ }
2894
+ const status = req.query.status ?? "active";
2895
+ const search = req.query.search ?? "";
2896
+ const curriculum = req.query.curriculum ?? "";
2897
+ const educationLevel = req.query.educationLevel ?? "";
2898
+ const gradeLevel = req.query.gradeLevel ?? "";
2899
+ try {
2900
+ const curriculumSubjects = await _getAll({
2901
+ school,
2902
+ page,
2903
+ limit,
2904
+ sort: sortObj,
2905
+ status,
2906
+ search,
2907
+ curriculum,
2908
+ educationLevel,
2909
+ gradeLevel
2910
+ });
2911
+ res.json(curriculumSubjects);
2912
+ return;
2913
+ } catch (error2) {
2914
+ next(error2);
2915
+ }
2916
+ }
2853
2917
  async function getAsOptions(req, res, next) {
2854
2918
  const query = req.query;
2855
2919
  const validation = import_joi4.default.object({
@@ -2957,6 +3021,7 @@ function useSubjectController() {
2957
3021
  return {
2958
3022
  add,
2959
3023
  addMany,
3024
+ getBySchool,
2960
3025
  getAll,
2961
3026
  getById,
2962
3027
  getByCurriculum,
@@ -42452,6 +42517,32 @@ function useTeachingLoadSlotRepo() {
42452
42517
  }
42453
42518
  }
42454
42519
  }
42520
+ async function deleteBySection(section, session) {
42521
+ try {
42522
+ section = new import_mongodb40.ObjectId(section);
42523
+ } catch (error) {
42524
+ throw new import_nodejs_utils66.BadRequestError(namespace_collection + " Invalid section ID.");
42525
+ }
42526
+ try {
42527
+ const res = await collection.updateOne(
42528
+ { section },
42529
+ { $set: { status: "deleted", deletedAt: /* @__PURE__ */ new Date() } },
42530
+ { session }
42531
+ );
42532
+ delCachedData();
42533
+ return res;
42534
+ } catch (error) {
42535
+ import_nodejs_utils66.logger.log({
42536
+ level: "error",
42537
+ message: error.message
42538
+ });
42539
+ if (error instanceof import_nodejs_utils66.AppError) {
42540
+ throw error;
42541
+ } else {
42542
+ throw new import_nodejs_utils66.InternalServerError("Failed to delete teaching load slot.");
42543
+ }
42544
+ }
42545
+ }
42455
42546
  function delCachedData() {
42456
42547
  delNamespace().then(() => {
42457
42548
  import_nodejs_utils66.logger.log({
@@ -42472,7 +42563,8 @@ function useTeachingLoadSlotRepo() {
42472
42563
  getAll,
42473
42564
  getById,
42474
42565
  deleteById,
42475
- delCachedData
42566
+ delCachedData,
42567
+ deleteBySection
42476
42568
  };
42477
42569
  }
42478
42570
 
@@ -42588,6 +42680,43 @@ function useTeachingLoadSlotController() {
42588
42680
  next(error2);
42589
42681
  }
42590
42682
  }
42683
+ async function getBySection(req, res, next) {
42684
+ const section = req.params.section ?? "";
42685
+ const validation = import_joi42.default.string().hex().required();
42686
+ const { error: errorTeacher } = validation.validate(section);
42687
+ if (errorTeacher) {
42688
+ next(new import_nodejs_utils68.BadRequestError(errorTeacher.message));
42689
+ import_nodejs_utils68.logger.info(`Controller: ${errorTeacher.message}`);
42690
+ return;
42691
+ }
42692
+ const query = req.query;
42693
+ const schema = import_joi42.default.object({
42694
+ page: import_joi42.default.number().min(1).optional().allow("", null),
42695
+ limit: import_joi42.default.number().min(1).max(100).optional().allow("", null),
42696
+ status: import_joi42.default.string().optional().allow("", null)
42697
+ });
42698
+ const { error } = schema.validate(query);
42699
+ if (error) {
42700
+ next(new import_nodejs_utils68.BadRequestError(error.message));
42701
+ import_nodejs_utils68.logger.info(`Controller: ${error.message}`);
42702
+ return;
42703
+ }
42704
+ const page = Number(req.query.page ?? 1);
42705
+ const limit = Number(req.query.limit ?? 10);
42706
+ const status = req.query.status ?? "active";
42707
+ try {
42708
+ const result = await _getAll({
42709
+ section,
42710
+ page,
42711
+ limit,
42712
+ status
42713
+ });
42714
+ res.json(result);
42715
+ return;
42716
+ } catch (error2) {
42717
+ next(error2);
42718
+ }
42719
+ }
42591
42720
  async function getByTeacher(req, res, next) {
42592
42721
  const teacher = req.params.teacher ?? "";
42593
42722
  const schemaTeacher = import_joi42.default.string().hex().required();
@@ -42776,7 +42905,8 @@ function useTeachingLoadSlotController() {
42776
42905
  getById,
42777
42906
  deleteById,
42778
42907
  getByTeachingLoad,
42779
- getByTeacher
42908
+ getByTeacher,
42909
+ getBySection
42780
42910
  };
42781
42911
  }
42782
42912
 
@@ -43359,6 +43489,7 @@ function useSectionService() {
43359
43489
  const { getById: getSchoolById } = useSchoolRepo();
43360
43490
  const { getAll: getAllPersonnel } = usePersonnelRepo();
43361
43491
  const { add: addTeachingLoad, getByTeacher } = useTeachingLoadRepo();
43492
+ const { deleteBySection: deleteTeachingLoadSlotsBySection } = useTeachingLoadSlotRepo();
43362
43493
  function distributeStudents(total, minPer, maxPer) {
43363
43494
  if (total <= 0)
43364
43495
  return [];
@@ -43460,7 +43591,6 @@ function useSectionService() {
43460
43591
  let subjectsSkipped = 0;
43461
43592
  await delCachedSectionData();
43462
43593
  await delCachedSectionStudentData();
43463
- console.log("SECTION SIZES:", sectionSizes);
43464
43594
  for (let i = 0; i < sectionSizes.length; i++) {
43465
43595
  const size = sectionSizes[i];
43466
43596
  const sectionName = String(i + 1);
@@ -43623,6 +43753,7 @@ function useSectionService() {
43623
43753
  continue;
43624
43754
  }
43625
43755
  await deleteSectionById(sectionId, session);
43756
+ await deleteTeachingLoadSlotsBySection(sectionId, session);
43626
43757
  }
43627
43758
  }
43628
43759
  await session.commitTransaction();
@@ -43643,7 +43774,6 @@ function useSectionService() {
43643
43774
  }
43644
43775
  };
43645
43776
  } catch (error2) {
43646
- console.log(error2);
43647
43777
  await session.abortTransaction();
43648
43778
  if (error2 instanceof import_nodejs_utils72.AppError) {
43649
43779
  throw error2;