@eeplatform/basic-edu 1.10.12 → 1.10.13

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
@@ -1347,6 +1347,7 @@ import Joi from "joi";
1347
1347
  import { ObjectId } from "mongodb";
1348
1348
  var schemaCurriculum = Joi.object({
1349
1349
  _id: Joi.string().hex().optional(),
1350
+ school: Joi.string().hex().required(),
1350
1351
  name: Joi.string().required(),
1351
1352
  effectiveSchoolYear: Joi.string().required(),
1352
1353
  maxTeachingHoursPerDay: Joi.number().integer().min(1).required(),
@@ -1373,8 +1374,14 @@ function MCurriculum(value) {
1373
1374
  throw new BadRequestError("Invalid _id format");
1374
1375
  }
1375
1376
  }
1377
+ try {
1378
+ value.school = new ObjectId(value.school);
1379
+ } catch (error2) {
1380
+ throw new BadRequestError("Invalid school format");
1381
+ }
1376
1382
  return {
1377
1383
  _id: value._id ?? void 0,
1384
+ school: value.school,
1378
1385
  name: value.name ?? "",
1379
1386
  effectiveSchoolYear: value.effectiveSchoolYear ?? "",
1380
1387
  maxTeachingHoursPerDay: value.maxTeachingHoursPerDay ?? 0,
@@ -1416,6 +1423,7 @@ function useCurriculumRepo() {
1416
1423
  {
1417
1424
  key: {
1418
1425
  name: 1,
1426
+ school: 1,
1419
1427
  effectiveSchoolYear: 1,
1420
1428
  status: 1
1421
1429
  },
@@ -1488,12 +1496,19 @@ function useCurriculumRepo() {
1488
1496
  page = 1,
1489
1497
  limit = 10,
1490
1498
  sort = {},
1491
- status = "active"
1499
+ status = "active",
1500
+ school = ""
1492
1501
  } = {}) {
1493
1502
  page = page > 0 ? page - 1 : 0;
1494
1503
  const query = {
1495
1504
  status
1496
1505
  };
1506
+ const cacheKeyOptions = {
1507
+ page,
1508
+ limit,
1509
+ sort: JSON.stringify(sort),
1510
+ status
1511
+ };
1497
1512
  sort = Object.keys(sort).length > 0 ? sort : { _id: -1 };
1498
1513
  if (search) {
1499
1514
  query.$or = [
@@ -1501,16 +1516,17 @@ function useCurriculumRepo() {
1501
1516
  { effectiveSchoolYear: { $regex: search, $options: "i" } },
1502
1517
  { curriculumMemoRef: { $regex: search, $options: "i" } }
1503
1518
  ];
1519
+ cacheKeyOptions.search = search;
1504
1520
  }
1505
- const cacheParams = {
1506
- page,
1507
- limit,
1508
- sort: JSON.stringify(sort)
1509
- };
1510
- if (search)
1511
- cacheParams.search = search;
1512
- if (status !== "active")
1513
- cacheParams.status = status;
1521
+ if (school) {
1522
+ try {
1523
+ query.school = new ObjectId2(school);
1524
+ } catch (error) {
1525
+ throw new BadRequestError2("Invalid school ID format.");
1526
+ }
1527
+ cacheKeyOptions.school = school;
1528
+ }
1529
+ const cacheParams = cacheKeyOptions;
1514
1530
  const cacheKey = makeCacheKey(namespace_collection, cacheParams);
1515
1531
  logger2.log({
1516
1532
  level: "info",
@@ -1860,6 +1876,7 @@ function useCurriculumController() {
1860
1876
  limit = isNaN(limit) ? 20 : limit;
1861
1877
  const sort = req.query.sort ? String(req.query.sort).split(",") : "";
1862
1878
  const sortOrder = req.query.sortOrder ? String(req.query.sortOrder).split(",") : "";
1879
+ const school = req.query.school;
1863
1880
  const sortObj = {};
1864
1881
  if (sort && Array.isArray(sort) && sort.length && sortOrder && Array.isArray(sortOrder) && sortOrder.length) {
1865
1882
  sort.forEach((field, index) => {
@@ -1874,7 +1891,8 @@ function useCurriculumController() {
1874
1891
  limit,
1875
1892
  sort: sortObj,
1876
1893
  status,
1877
- search
1894
+ search,
1895
+ school
1878
1896
  });
1879
1897
  res.json(curriculums);
1880
1898
  return;
@@ -5116,7 +5134,8 @@ function useProgramRepo() {
5116
5134
  sort = {},
5117
5135
  status = "active",
5118
5136
  school = "",
5119
- isDefault
5137
+ isDefault,
5138
+ gradeLevel = []
5120
5139
  } = {}) {
5121
5140
  page = page > 0 ? page - 1 : 0;
5122
5141
  const query = {
@@ -5146,6 +5165,10 @@ function useProgramRepo() {
5146
5165
  query.isDefault = isDefault;
5147
5166
  cacheKeyOptions.isDefault = isDefault;
5148
5167
  }
5168
+ if (gradeLevel && Array.isArray(gradeLevel) && gradeLevel.length > 0) {
5169
+ query.gradeLevels = { $in: gradeLevel };
5170
+ cacheKeyOptions.gradeLevel = gradeLevel.join(",");
5171
+ }
5149
5172
  const cacheKey = makeCacheKey7(namespace_collection, cacheKeyOptions);
5150
5173
  logger12.log({
5151
5174
  level: "info",
@@ -5395,7 +5418,8 @@ function useProgramController() {
5395
5418
  search: Joi13.string().optional().allow("", null),
5396
5419
  status: Joi13.string().optional().allow("", null),
5397
5420
  school: Joi13.string().hex().optional().allow("", null),
5398
- isDefault: Joi13.boolean().optional().allow("", null)
5421
+ isDefault: Joi13.boolean().optional().allow("", null),
5422
+ gradeLevel: Joi13.string().optional().allow("", null)
5399
5423
  });
5400
5424
  const { error } = validation.validate(query);
5401
5425
  const page = typeof req.query.page === "string" ? Number(req.query.page) : 1;
@@ -5404,6 +5428,7 @@ function useProgramController() {
5404
5428
  const status = req.query.status ?? "active";
5405
5429
  const school = req.query.school ?? "";
5406
5430
  const isDefault = req.query.isDefault === "true" ? true : req.query.isDefault === "false" ? false : void 0;
5431
+ const gradeLevel = req.query.gradeLevel?.split(",") ?? [];
5407
5432
  const isPageNumber = isFinite(page);
5408
5433
  if (!isPageNumber) {
5409
5434
  next(new BadRequestError19("Invalid page number."));
@@ -5425,7 +5450,8 @@ function useProgramController() {
5425
5450
  search,
5426
5451
  status,
5427
5452
  school,
5428
- isDefault
5453
+ isDefault,
5454
+ gradeLevel
5429
5455
  });
5430
5456
  res.json(data);
5431
5457
  return;