@eeplatform/basic-edu 1.10.11 → 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,18 @@
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
+
10
+ ## 1.10.12
11
+
12
+ ### Patch Changes
13
+
14
+ - 64d11a9: Fix
15
+
3
16
  ## 1.10.11
4
17
 
5
18
  ### 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;
@@ -2195,7 +2213,7 @@ var schemaSubjectAdd = import_joi3.default.object({
2195
2213
  curriculum: import_joi3.default.string().hex().required(),
2196
2214
  curriculumName: import_joi3.default.string().required(),
2197
2215
  effectiveSchoolYear: import_joi3.default.array().items(import_joi3.default.number().integer().min(1900)).optional(),
2198
- gradeLevel: import_joi3.default.array().items(import_joi3.default.string()).required(),
2216
+ gradeLevel: import_joi3.default.array().items(import_joi3.default.string()).min(1).required(),
2199
2217
  track: import_joi3.default.string().hex().optional().allow("", null),
2200
2218
  trackName: import_joi3.default.string().optional().allow("", null),
2201
2219
  strand: import_joi3.default.string().hex().optional().allow("", null),
@@ -5122,11 +5140,13 @@ function useProgramRepo() {
5122
5140
  {
5123
5141
  key: { name: 1, school: 1, status: 1 },
5124
5142
  unique: true,
5143
+ partialFilterExpression: { status: "active" },
5125
5144
  name: "unique_program_per_school"
5126
5145
  },
5127
5146
  {
5128
5147
  key: { code: 1, school: 1, status: 1 },
5129
5148
  unique: true,
5149
+ partialFilterExpression: { status: "active" },
5130
5150
  name: "unique_program_code_per_school"
5131
5151
  }
5132
5152
  ]);
@@ -5176,7 +5196,8 @@ function useProgramRepo() {
5176
5196
  sort = {},
5177
5197
  status = "active",
5178
5198
  school = "",
5179
- isDefault
5199
+ isDefault,
5200
+ gradeLevel = []
5180
5201
  } = {}) {
5181
5202
  page = page > 0 ? page - 1 : 0;
5182
5203
  const query = {
@@ -5206,6 +5227,10 @@ function useProgramRepo() {
5206
5227
  query.isDefault = isDefault;
5207
5228
  cacheKeyOptions.isDefault = isDefault;
5208
5229
  }
5230
+ if (gradeLevel && Array.isArray(gradeLevel) && gradeLevel.length > 0) {
5231
+ query.gradeLevels = { $in: gradeLevel };
5232
+ cacheKeyOptions.gradeLevel = gradeLevel.join(",");
5233
+ }
5209
5234
  const cacheKey = (0, import_nodejs_utils19.makeCacheKey)(namespace_collection, cacheKeyOptions);
5210
5235
  import_nodejs_utils19.logger.log({
5211
5236
  level: "info",
@@ -5455,7 +5480,8 @@ function useProgramController() {
5455
5480
  search: import_joi13.default.string().optional().allow("", null),
5456
5481
  status: import_joi13.default.string().optional().allow("", null),
5457
5482
  school: import_joi13.default.string().hex().optional().allow("", null),
5458
- 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)
5459
5485
  });
5460
5486
  const { error } = validation.validate(query);
5461
5487
  const page = typeof req.query.page === "string" ? Number(req.query.page) : 1;
@@ -5464,6 +5490,7 @@ function useProgramController() {
5464
5490
  const status = req.query.status ?? "active";
5465
5491
  const school = req.query.school ?? "";
5466
5492
  const isDefault = req.query.isDefault === "true" ? true : req.query.isDefault === "false" ? false : void 0;
5493
+ const gradeLevel = req.query.gradeLevel?.split(",") ?? [];
5467
5494
  const isPageNumber = isFinite(page);
5468
5495
  if (!isPageNumber) {
5469
5496
  next(new import_nodejs_utils20.BadRequestError("Invalid page number."));
@@ -5485,7 +5512,8 @@ function useProgramController() {
5485
5512
  search,
5486
5513
  status,
5487
5514
  school,
5488
- isDefault
5515
+ isDefault,
5516
+ gradeLevel
5489
5517
  });
5490
5518
  res.json(data);
5491
5519
  return;
@@ -5737,7 +5765,7 @@ function useSchoolRepo() {
5737
5765
  await collection.createIndexes([
5738
5766
  { key: { name: 1 } },
5739
5767
  { key: { createdAt: 1 } },
5740
- { key: { name: "text" } },
5768
+ { key: { name: "text", id: "text" } },
5741
5769
  { key: { id: 1, status: 1 }, unique: true, name: "unique_school_id" }
5742
5770
  ]);
5743
5771
  } catch (error) {