@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/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # @eeplatform/basic-edu
2
2
 
3
+ ## 1.10.13
4
+
5
+ ### Patch Changes
6
+
7
+ - cc35ba8: Fix program management
8
+ - ae32710: Fix curriculum management
9
+
3
10
  ## 1.10.12
4
11
 
5
12
  ### Patch Changes
package/dist/index.d.ts CHANGED
@@ -6,6 +6,7 @@ import { Request, Response, NextFunction } from 'express';
6
6
 
7
7
  type TCurriculum = {
8
8
  _id?: ObjectId;
9
+ school: ObjectId;
9
10
  name: string;
10
11
  effectiveSchoolYear: string;
11
12
  maxTeachingHoursPerDay: number;
@@ -22,6 +23,7 @@ type TCurriculum = {
22
23
  declare const schemaCurriculum: Joi.ObjectSchema<any>;
23
24
  declare function MCurriculum(value: TCurriculum): {
24
25
  _id: ObjectId | undefined;
26
+ school: ObjectId;
25
27
  name: string;
26
28
  effectiveSchoolYear: string;
27
29
  maxTeachingHoursPerDay: number;
@@ -39,12 +41,13 @@ declare function MCurriculum(value: TCurriculum): {
39
41
  declare function useCurriculumRepo(): {
40
42
  createIndexes: () => Promise<void>;
41
43
  add: (value: TCurriculum, session?: ClientSession) => Promise<ObjectId>;
42
- getAll: ({ search, page, limit, sort, status, }?: {
44
+ getAll: ({ search, page, limit, sort, status, school, }?: {
43
45
  search?: string | undefined;
44
46
  page?: number | undefined;
45
47
  limit?: number | undefined;
46
48
  sort?: {} | undefined;
47
49
  status?: string | undefined;
50
+ school?: string | undefined;
48
51
  }) => Promise<Record<string, any> | {
49
52
  items: any[];
50
53
  pages: number;
@@ -1629,7 +1632,7 @@ declare function modelProgram(value: TProgram): TProgram;
1629
1632
  declare function useProgramRepo(): {
1630
1633
  createIndexes: () => Promise<void>;
1631
1634
  add: (value: TProgram, session?: ClientSession) => Promise<ObjectId>;
1632
- getAll: ({ search, page, limit, sort, status, school, isDefault, }?: {
1635
+ getAll: ({ search, page, limit, sort, status, school, isDefault, gradeLevel, }?: {
1633
1636
  search?: string;
1634
1637
  page?: number;
1635
1638
  limit?: number;
@@ -1637,6 +1640,7 @@ declare function useProgramRepo(): {
1637
1640
  status?: string;
1638
1641
  school?: string;
1639
1642
  isDefault?: boolean;
1643
+ gradeLevel?: string[];
1640
1644
  }) => Promise<Record<string, any> | {
1641
1645
  items: any[];
1642
1646
  pages: number;
package/dist/index.js CHANGED
@@ -1481,6 +1481,7 @@ var import_joi = __toESM(require("joi"));
1481
1481
  var import_mongodb = require("mongodb");
1482
1482
  var schemaCurriculum = import_joi.default.object({
1483
1483
  _id: import_joi.default.string().hex().optional(),
1484
+ school: import_joi.default.string().hex().required(),
1484
1485
  name: import_joi.default.string().required(),
1485
1486
  effectiveSchoolYear: import_joi.default.string().required(),
1486
1487
  maxTeachingHoursPerDay: import_joi.default.number().integer().min(1).required(),
@@ -1507,8 +1508,14 @@ function MCurriculum(value) {
1507
1508
  throw new import_nodejs_utils.BadRequestError("Invalid _id format");
1508
1509
  }
1509
1510
  }
1511
+ try {
1512
+ value.school = new import_mongodb.ObjectId(value.school);
1513
+ } catch (error2) {
1514
+ throw new import_nodejs_utils.BadRequestError("Invalid school format");
1515
+ }
1510
1516
  return {
1511
1517
  _id: value._id ?? void 0,
1518
+ school: value.school,
1512
1519
  name: value.name ?? "",
1513
1520
  effectiveSchoolYear: value.effectiveSchoolYear ?? "",
1514
1521
  maxTeachingHoursPerDay: value.maxTeachingHoursPerDay ?? 0,
@@ -1541,6 +1548,7 @@ function useCurriculumRepo() {
1541
1548
  {
1542
1549
  key: {
1543
1550
  name: 1,
1551
+ school: 1,
1544
1552
  effectiveSchoolYear: 1,
1545
1553
  status: 1
1546
1554
  },
@@ -1613,12 +1621,19 @@ function useCurriculumRepo() {
1613
1621
  page = 1,
1614
1622
  limit = 10,
1615
1623
  sort = {},
1616
- status = "active"
1624
+ status = "active",
1625
+ school = ""
1617
1626
  } = {}) {
1618
1627
  page = page > 0 ? page - 1 : 0;
1619
1628
  const query = {
1620
1629
  status
1621
1630
  };
1631
+ const cacheKeyOptions = {
1632
+ page,
1633
+ limit,
1634
+ sort: JSON.stringify(sort),
1635
+ status
1636
+ };
1622
1637
  sort = Object.keys(sort).length > 0 ? sort : { _id: -1 };
1623
1638
  if (search) {
1624
1639
  query.$or = [
@@ -1626,16 +1641,17 @@ function useCurriculumRepo() {
1626
1641
  { effectiveSchoolYear: { $regex: search, $options: "i" } },
1627
1642
  { curriculumMemoRef: { $regex: search, $options: "i" } }
1628
1643
  ];
1644
+ cacheKeyOptions.search = search;
1629
1645
  }
1630
- const cacheParams = {
1631
- page,
1632
- limit,
1633
- sort: JSON.stringify(sort)
1634
- };
1635
- if (search)
1636
- cacheParams.search = search;
1637
- if (status !== "active")
1638
- cacheParams.status = status;
1646
+ if (school) {
1647
+ try {
1648
+ query.school = new import_mongodb2.ObjectId(school);
1649
+ } catch (error) {
1650
+ throw new import_nodejs_utils2.BadRequestError("Invalid school ID format.");
1651
+ }
1652
+ cacheKeyOptions.school = school;
1653
+ }
1654
+ const cacheParams = cacheKeyOptions;
1639
1655
  const cacheKey = (0, import_nodejs_utils2.makeCacheKey)(namespace_collection, cacheParams);
1640
1656
  import_nodejs_utils2.logger.log({
1641
1657
  level: "info",
@@ -1985,6 +2001,7 @@ function useCurriculumController() {
1985
2001
  limit = isNaN(limit) ? 20 : limit;
1986
2002
  const sort = req.query.sort ? String(req.query.sort).split(",") : "";
1987
2003
  const sortOrder = req.query.sortOrder ? String(req.query.sortOrder).split(",") : "";
2004
+ const school = req.query.school;
1988
2005
  const sortObj = {};
1989
2006
  if (sort && Array.isArray(sort) && sort.length && sortOrder && Array.isArray(sortOrder) && sortOrder.length) {
1990
2007
  sort.forEach((field, index) => {
@@ -1999,7 +2016,8 @@ function useCurriculumController() {
1999
2016
  limit,
2000
2017
  sort: sortObj,
2001
2018
  status,
2002
- search
2019
+ search,
2020
+ school
2003
2021
  });
2004
2022
  res.json(curriculums);
2005
2023
  return;
@@ -5178,7 +5196,8 @@ function useProgramRepo() {
5178
5196
  sort = {},
5179
5197
  status = "active",
5180
5198
  school = "",
5181
- isDefault
5199
+ isDefault,
5200
+ gradeLevel = []
5182
5201
  } = {}) {
5183
5202
  page = page > 0 ? page - 1 : 0;
5184
5203
  const query = {
@@ -5208,6 +5227,10 @@ function useProgramRepo() {
5208
5227
  query.isDefault = isDefault;
5209
5228
  cacheKeyOptions.isDefault = isDefault;
5210
5229
  }
5230
+ if (gradeLevel && Array.isArray(gradeLevel) && gradeLevel.length > 0) {
5231
+ query.gradeLevels = { $in: gradeLevel };
5232
+ cacheKeyOptions.gradeLevel = gradeLevel.join(",");
5233
+ }
5211
5234
  const cacheKey = (0, import_nodejs_utils19.makeCacheKey)(namespace_collection, cacheKeyOptions);
5212
5235
  import_nodejs_utils19.logger.log({
5213
5236
  level: "info",
@@ -5457,7 +5480,8 @@ function useProgramController() {
5457
5480
  search: import_joi13.default.string().optional().allow("", null),
5458
5481
  status: import_joi13.default.string().optional().allow("", null),
5459
5482
  school: import_joi13.default.string().hex().optional().allow("", null),
5460
- isDefault: import_joi13.default.boolean().optional().allow("", null)
5483
+ isDefault: import_joi13.default.boolean().optional().allow("", null),
5484
+ gradeLevel: import_joi13.default.string().optional().allow("", null)
5461
5485
  });
5462
5486
  const { error } = validation.validate(query);
5463
5487
  const page = typeof req.query.page === "string" ? Number(req.query.page) : 1;
@@ -5466,6 +5490,7 @@ function useProgramController() {
5466
5490
  const status = req.query.status ?? "active";
5467
5491
  const school = req.query.school ?? "";
5468
5492
  const isDefault = req.query.isDefault === "true" ? true : req.query.isDefault === "false" ? false : void 0;
5493
+ const gradeLevel = req.query.gradeLevel?.split(",") ?? [];
5469
5494
  const isPageNumber = isFinite(page);
5470
5495
  if (!isPageNumber) {
5471
5496
  next(new import_nodejs_utils20.BadRequestError("Invalid page number."));
@@ -5487,7 +5512,8 @@ function useProgramController() {
5487
5512
  search,
5488
5513
  status,
5489
5514
  school,
5490
- isDefault
5515
+ isDefault,
5516
+ gradeLevel
5491
5517
  });
5492
5518
  res.json(data);
5493
5519
  return;