@eeplatform/core 1.5.0 → 1.5.2

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
@@ -31293,14 +31293,20 @@ var schemaCurriculum = Joi45.object({
31293
31293
  _id: Joi45.string().hex().optional(),
31294
31294
  school: Joi45.string().hex().required(),
31295
31295
  code: Joi45.string().required(),
31296
- educationLevel: Joi45.string().required(),
31297
- gradeLevel: Joi45.string().required(),
31298
- subjectCode: Joi45.string().required(),
31299
- subjectName: Joi45.string().required(),
31300
- subjectType: Joi45.string().required(),
31301
- sessionFrequency: Joi45.number().integer().min(0).required(),
31302
- sessionDuration: Joi45.number().integer().min(0).required(),
31303
- totalMinutesPerWeek: Joi45.number().integer().min(0).required(),
31296
+ effectiveSchoolYear: Joi45.string().required(),
31297
+ maxTeachingHoursPerDay: Joi45.number().integer().min(1).required(),
31298
+ subjects: Joi45.array().items(
31299
+ Joi45.object({
31300
+ educationLevel: Joi45.string().required(),
31301
+ gradeLevel: Joi45.string().required(),
31302
+ subjectCode: Joi45.string().required(),
31303
+ subjectName: Joi45.string().required(),
31304
+ subjectType: Joi45.string().required(),
31305
+ sessionFrequency: Joi45.number().integer().min(0).required(),
31306
+ sessionDuration: Joi45.number().integer().min(0).required(),
31307
+ totalMinutesPerWeek: Joi45.number().integer().min(0).required()
31308
+ })
31309
+ ),
31304
31310
  curriculumMemoRef: Joi45.string().optional().allow("", null),
31305
31311
  status: Joi45.string().optional().allow("", null),
31306
31312
  createdAt: Joi45.date().optional().allow("", null),
@@ -31327,14 +31333,9 @@ function MCurriculum(value) {
31327
31333
  _id: value._id ?? void 0,
31328
31334
  school: value.school ?? "",
31329
31335
  code: value.code ?? "",
31330
- educationLevel: value.educationLevel ?? "",
31331
- gradeLevel: value.gradeLevel ?? "",
31332
- subjectCode: value.subjectCode ?? "",
31333
- subjectName: value.subjectName ?? "",
31334
- subjectType: value.subjectType ?? "",
31335
- sessionFrequency: value.sessionFrequency ?? 0,
31336
- sessionDuration: value.sessionDuration ?? 0,
31337
- totalMinutesPerWeek: value.totalMinutesPerWeek ?? 0,
31336
+ effectiveSchoolYear: value.effectiveSchoolYear ?? "",
31337
+ maxTeachingHoursPerDay: value.maxTeachingHoursPerDay ?? 0,
31338
+ subjects: value.subjects ?? [],
31338
31339
  curriculumMemoRef: value.curriculumMemoRef ?? "",
31339
31340
  status: value.status ?? "active",
31340
31341
  createdAt: value.createdAt ?? /* @__PURE__ */ new Date(),
@@ -31369,10 +31370,16 @@ function useCurriculumRepo() {
31369
31370
  async function createIndexes() {
31370
31371
  try {
31371
31372
  await collection.createIndexes([
31372
- { key: { code: 1 }, unique: true, name: "unique_code_index" },
31373
- { key: { educationLevel: 1 } },
31374
- { key: { gradeLevel: 1 } },
31375
- { key: { subjectCode: 1 } },
31373
+ {
31374
+ key: {
31375
+ school: 1,
31376
+ code: 1,
31377
+ status: 1
31378
+ },
31379
+ unique: true,
31380
+ partialFilterExpression: { status: "active" },
31381
+ name: "unique_code_index"
31382
+ },
31376
31383
  { key: { status: 1 } }
31377
31384
  ]);
31378
31385
  } catch (error) {
@@ -31432,9 +31439,6 @@ function useCurriculumRepo() {
31432
31439
  page = 1,
31433
31440
  limit = 10,
31434
31441
  sort = {},
31435
- educationLevel = "",
31436
- gradeLevel = "",
31437
- subjectCode = "",
31438
31442
  status = "active"
31439
31443
  } = {}) {
31440
31444
  page = page > 0 ? page - 1 : 0;
@@ -31449,15 +31453,6 @@ function useCurriculumRepo() {
31449
31453
  { subjectCode: { $regex: search, $options: "i" } }
31450
31454
  ];
31451
31455
  }
31452
- if (educationLevel) {
31453
- query.educationLevel = educationLevel;
31454
- }
31455
- if (gradeLevel) {
31456
- query.gradeLevel = gradeLevel;
31457
- }
31458
- if (subjectCode) {
31459
- query.subjectCode = subjectCode;
31460
- }
31461
31456
  const cacheParams = {
31462
31457
  page,
31463
31458
  limit,
@@ -31465,12 +31460,6 @@ function useCurriculumRepo() {
31465
31460
  };
31466
31461
  if (search)
31467
31462
  cacheParams.search = search;
31468
- if (educationLevel)
31469
- cacheParams.educationLevel = educationLevel;
31470
- if (gradeLevel)
31471
- cacheParams.gradeLevel = gradeLevel;
31472
- if (subjectCode)
31473
- cacheParams.subjectCode = subjectCode;
31474
31463
  if (status !== "active")
31475
31464
  cacheParams.status = status;
31476
31465
  const cacheKey = makeCacheKey25(namespace_collection, cacheParams);
@@ -31612,21 +31601,7 @@ function useCurriculumController() {
31612
31601
  } = useCurriculumRepo();
31613
31602
  async function add(req, res, next) {
31614
31603
  const value = req.body;
31615
- const validation = Joi46.object({
31616
- code: Joi46.string().required(),
31617
- school: Joi46.string().hex().required(),
31618
- educationLevel: Joi46.string().required(),
31619
- gradeLevel: Joi46.string().required(),
31620
- subjectCode: Joi46.string().required(),
31621
- subjectName: Joi46.string().required(),
31622
- subjectType: Joi46.string().required(),
31623
- sessionFrequency: Joi46.number().integer().min(0).required(),
31624
- sessionDuration: Joi46.number().integer().min(0).required(),
31625
- totalMinutesPerWeek: Joi46.number().integer().min(0).required(),
31626
- curriculumMemoRef: Joi46.string().optional().allow("", null),
31627
- status: Joi46.string().optional().allow("", null)
31628
- });
31629
- const { error } = validation.validate(value);
31604
+ const { error } = schemaCurriculum.validate(value);
31630
31605
  if (error) {
31631
31606
  next(new BadRequestError84(error.message));
31632
31607
  logger42.info(`Controller: ${error.message}`);
@@ -31678,9 +31653,6 @@ function useCurriculumController() {
31678
31653
  page: Joi46.number().min(1).optional().allow("", null),
31679
31654
  limit: Joi46.number().min(1).optional().allow("", null),
31680
31655
  search: Joi46.string().optional().allow("", null),
31681
- educationLevel: Joi46.string().optional().allow("", null),
31682
- gradeLevel: Joi46.string().optional().allow("", null),
31683
- subjectCode: Joi46.string().optional().allow("", null),
31684
31656
  status: Joi46.string().optional().allow("", null)
31685
31657
  });
31686
31658
  const { error } = validation.validate(query);
@@ -31700,9 +31672,6 @@ function useCurriculumController() {
31700
31672
  });
31701
31673
  }
31702
31674
  const status = req.query.status ?? "active";
31703
- const educationLevel = req.query.educationLevel ?? "";
31704
- const gradeLevel = req.query.gradeLevel ?? "";
31705
- const subjectCode = req.query.subjectCode ?? "";
31706
31675
  const search = req.query.search ?? "";
31707
31676
  try {
31708
31677
  const curriculums = await _getAll({
@@ -31710,9 +31679,6 @@ function useCurriculumController() {
31710
31679
  limit,
31711
31680
  sort: sortObj,
31712
31681
  status,
31713
- educationLevel,
31714
- gradeLevel,
31715
- subjectCode,
31716
31682
  search
31717
31683
  });
31718
31684
  res.json(curriculums);
@@ -31771,6 +31737,624 @@ function useCurriculumController() {
31771
31737
  deleteById
31772
31738
  };
31773
31739
  }
31740
+
31741
+ // src/models/grade-level.model.ts
31742
+ import { BadRequestError as BadRequestError85, logger as logger43 } from "@eeplatform/nodejs-utils";
31743
+ import Joi47 from "joi";
31744
+ import { ObjectId as ObjectId52 } from "mongodb";
31745
+ var schemaGradeLevel = Joi47.object({
31746
+ _id: Joi47.string().hex().optional(),
31747
+ school: Joi47.string().hex().optional(),
31748
+ educationLevel: Joi47.string().required(),
31749
+ gradeLevel: Joi47.string().required(),
31750
+ teachingStyle: Joi47.string().required(),
31751
+ maxNumberOfLearners: Joi47.number().required(),
31752
+ defaultStartTime: Joi47.string().optional().allow("", null),
31753
+ defaultEndTime: Joi47.string().optional().allow("", null),
31754
+ status: Joi47.string().optional().allow("", null),
31755
+ createdAt: Joi47.date().optional().allow("", null),
31756
+ updatedAt: Joi47.date().optional().allow("", null),
31757
+ deletedAt: Joi47.date().optional().allow("", null),
31758
+ createdBy: Joi47.string().optional().allow("", null),
31759
+ updatedBy: Joi47.string().optional().allow("", null),
31760
+ deletedBy: Joi47.string().optional().allow("", null)
31761
+ });
31762
+ function MGradeLevel(value) {
31763
+ const { error } = schemaGradeLevel.validate(value);
31764
+ if (error) {
31765
+ logger43.info(`Grade Level Model: ${error.message}`);
31766
+ throw new BadRequestError85(error.message);
31767
+ }
31768
+ if (value._id && typeof value._id === "string") {
31769
+ try {
31770
+ value._id = new ObjectId52(value._id);
31771
+ } catch (error2) {
31772
+ throw new BadRequestError85("Invalid _id format");
31773
+ }
31774
+ }
31775
+ if (value.school && typeof value.school === "string") {
31776
+ try {
31777
+ value.school = new ObjectId52(value.school);
31778
+ } catch (error2) {
31779
+ throw new BadRequestError85("Invalid school format");
31780
+ }
31781
+ }
31782
+ return {
31783
+ _id: value._id ?? void 0,
31784
+ school: value.school ?? void 0,
31785
+ educationLevel: value.educationLevel ?? "",
31786
+ gradeLevel: value.gradeLevel ?? "",
31787
+ teachingStyle: value.teachingStyle ?? "",
31788
+ maxNumberOfLearners: value.maxNumberOfLearners ?? 0,
31789
+ defaultStartTime: value.defaultStartTime ?? "",
31790
+ defaultEndTime: value.defaultEndTime ?? "",
31791
+ status: value.status ?? "active",
31792
+ createdAt: value.createdAt ?? /* @__PURE__ */ new Date(),
31793
+ updatedAt: value.updatedAt ?? "",
31794
+ deletedAt: value.deletedAt ?? "",
31795
+ createdBy: value.createdBy ?? "",
31796
+ updatedBy: value.updatedBy ?? "",
31797
+ deletedBy: value.deletedBy ?? ""
31798
+ };
31799
+ }
31800
+
31801
+ // src/repositories/grade-level.repository.ts
31802
+ import {
31803
+ AppError as AppError21,
31804
+ BadRequestError as BadRequestError86,
31805
+ InternalServerError as InternalServerError31,
31806
+ logger as logger44,
31807
+ makeCacheKey as makeCacheKey26,
31808
+ paginate as paginate22,
31809
+ useAtlas as useAtlas43,
31810
+ useCache as useCache27
31811
+ } from "@eeplatform/nodejs-utils";
31812
+ import { ObjectId as ObjectId53 } from "mongodb";
31813
+ function useGradeLevelRepo() {
31814
+ const db = useAtlas43.getDb();
31815
+ if (!db) {
31816
+ throw new Error("Unable to connect to server.");
31817
+ }
31818
+ const namespace_collection = "school.grade-levels";
31819
+ const collection = db.collection(namespace_collection);
31820
+ const { getCache, setCache, delNamespace } = useCache27(namespace_collection);
31821
+ async function createIndexes() {
31822
+ try {
31823
+ await collection.createIndexes([
31824
+ { key: { educationLevel: 1 } },
31825
+ { key: { gradeLevel: 1 } },
31826
+ { key: { teachingStyle: 1 } },
31827
+ { key: { school: 1 } },
31828
+ { key: { status: 1 } },
31829
+ {
31830
+ key: { educationLevel: 1, gradeLevel: 1, school: 1 },
31831
+ unique: true,
31832
+ partialFilterExpression: { status: { $in: ["active", "suspended"] } },
31833
+ name: "unique_grade_level_per_school_index"
31834
+ }
31835
+ ]);
31836
+ } catch (error) {
31837
+ throw new Error("Failed to create index on grade levels.");
31838
+ }
31839
+ }
31840
+ async function add(value, session) {
31841
+ try {
31842
+ value = MGradeLevel(value);
31843
+ const res = await collection.insertOne(value, { session });
31844
+ delCachedData();
31845
+ return res.insertedId;
31846
+ } catch (error) {
31847
+ logger44.log({
31848
+ level: "error",
31849
+ message: error.message
31850
+ });
31851
+ if (error instanceof AppError21) {
31852
+ throw error;
31853
+ } else {
31854
+ const isDuplicated = error.message.includes("duplicate");
31855
+ if (isDuplicated) {
31856
+ throw new BadRequestError86(
31857
+ "Grade level already exists for this education level and school."
31858
+ );
31859
+ }
31860
+ throw new Error("Failed to create grade level.");
31861
+ }
31862
+ }
31863
+ }
31864
+ async function updateById(_id, value, session) {
31865
+ try {
31866
+ _id = new ObjectId53(_id);
31867
+ } catch (error) {
31868
+ throw new BadRequestError86("Invalid ID.");
31869
+ }
31870
+ if (value.school && typeof value.school === "string") {
31871
+ try {
31872
+ value.school = new ObjectId53(value.school);
31873
+ } catch (error) {
31874
+ throw new BadRequestError86("Invalid school ID format.");
31875
+ }
31876
+ }
31877
+ try {
31878
+ const res = await collection.updateOne(
31879
+ { _id },
31880
+ { $set: { ...value, updatedAt: /* @__PURE__ */ new Date() } },
31881
+ { session }
31882
+ );
31883
+ delCachedData();
31884
+ return res;
31885
+ } catch (error) {
31886
+ logger44.log({
31887
+ level: "error",
31888
+ message: error.message
31889
+ });
31890
+ if (error instanceof AppError21) {
31891
+ throw error;
31892
+ } else {
31893
+ const isDuplicated = error.message.includes("duplicate");
31894
+ if (isDuplicated) {
31895
+ throw new BadRequestError86(
31896
+ "Grade level already exists for this education level and school."
31897
+ );
31898
+ }
31899
+ throw new Error("Failed to update grade level.");
31900
+ }
31901
+ }
31902
+ }
31903
+ async function getAll({
31904
+ search = "",
31905
+ page = 1,
31906
+ limit = 10,
31907
+ sort = {},
31908
+ educationLevel = "",
31909
+ gradeLevel = "",
31910
+ teachingStyle = "",
31911
+ school = "",
31912
+ status = "active"
31913
+ } = {}) {
31914
+ page = page > 0 ? page - 1 : 0;
31915
+ const query = {
31916
+ status
31917
+ };
31918
+ sort = Object.keys(sort).length > 0 ? sort : { _id: -1 };
31919
+ if (search) {
31920
+ query.$or = [
31921
+ { educationLevel: { $regex: search, $options: "i" } },
31922
+ { gradeLevel: { $regex: search, $options: "i" } },
31923
+ { teachingStyle: { $regex: search, $options: "i" } }
31924
+ ];
31925
+ }
31926
+ if (educationLevel) {
31927
+ query.educationLevel = educationLevel;
31928
+ }
31929
+ if (gradeLevel) {
31930
+ query.gradeLevel = gradeLevel;
31931
+ }
31932
+ if (teachingStyle) {
31933
+ query.teachingStyle = teachingStyle;
31934
+ }
31935
+ if (school) {
31936
+ try {
31937
+ query.school = new ObjectId53(school);
31938
+ } catch (error) {
31939
+ throw new BadRequestError86("Invalid school ID format.");
31940
+ }
31941
+ }
31942
+ const cacheParams = {
31943
+ page,
31944
+ limit,
31945
+ sort: JSON.stringify(sort)
31946
+ };
31947
+ if (search)
31948
+ cacheParams.search = search;
31949
+ if (educationLevel)
31950
+ cacheParams.educationLevel = educationLevel;
31951
+ if (gradeLevel)
31952
+ cacheParams.gradeLevel = gradeLevel;
31953
+ if (teachingStyle)
31954
+ cacheParams.teachingStyle = teachingStyle;
31955
+ if (school)
31956
+ cacheParams.school = school;
31957
+ if (status !== "active")
31958
+ cacheParams.status = status;
31959
+ const cacheKey = makeCacheKey26(namespace_collection, cacheParams);
31960
+ logger44.log({
31961
+ level: "info",
31962
+ message: `Cache key for getAll grade levels: ${cacheKey}`
31963
+ });
31964
+ try {
31965
+ const cached = await getCache(cacheKey);
31966
+ if (cached) {
31967
+ logger44.log({
31968
+ level: "info",
31969
+ message: `Cache hit for getAll grade levels: ${cacheKey}`
31970
+ });
31971
+ return cached;
31972
+ }
31973
+ const items = await collection.aggregate([
31974
+ { $match: query },
31975
+ { $sort: sort },
31976
+ { $skip: page * limit },
31977
+ { $limit: limit },
31978
+ {
31979
+ $lookup: {
31980
+ from: "school.schools",
31981
+ localField: "school",
31982
+ foreignField: "_id",
31983
+ as: "schoolDetails"
31984
+ }
31985
+ },
31986
+ {
31987
+ $addFields: {
31988
+ schoolName: { $arrayElemAt: ["$schoolDetails.name", 0] }
31989
+ }
31990
+ },
31991
+ {
31992
+ $project: {
31993
+ schoolDetails: 0
31994
+ }
31995
+ }
31996
+ ]).toArray();
31997
+ const length = await collection.countDocuments(query);
31998
+ const data = paginate22(items, page, limit, length);
31999
+ setCache(cacheKey, data, 600).then(() => {
32000
+ logger44.log({
32001
+ level: "info",
32002
+ message: `Cache set for getAll grade levels: ${cacheKey}`
32003
+ });
32004
+ }).catch((err) => {
32005
+ logger44.log({
32006
+ level: "error",
32007
+ message: `Failed to set cache for getAll grade levels: ${err.message}`
32008
+ });
32009
+ });
32010
+ return data;
32011
+ } catch (error) {
32012
+ logger44.log({ level: "error", message: `${error}` });
32013
+ throw error;
32014
+ }
32015
+ }
32016
+ async function getById(_id) {
32017
+ try {
32018
+ _id = new ObjectId53(_id);
32019
+ } catch (error) {
32020
+ throw new BadRequestError86("Invalid ID.");
32021
+ }
32022
+ const cacheKey = makeCacheKey26(namespace_collection, { _id: String(_id) });
32023
+ try {
32024
+ const cached = await getCache(cacheKey);
32025
+ if (cached) {
32026
+ logger44.log({
32027
+ level: "info",
32028
+ message: `Cache hit for getById grade level: ${cacheKey}`
32029
+ });
32030
+ return cached;
32031
+ }
32032
+ const result = await collection.aggregate([
32033
+ { $match: { _id } },
32034
+ {
32035
+ $lookup: {
32036
+ from: "school.schools",
32037
+ localField: "school",
32038
+ foreignField: "_id",
32039
+ as: "schoolDetails"
32040
+ }
32041
+ },
32042
+ {
32043
+ $addFields: {
32044
+ schoolName: { $arrayElemAt: ["$schoolDetails.name", 0] }
32045
+ }
32046
+ },
32047
+ {
32048
+ $project: {
32049
+ schoolDetails: 0
32050
+ }
32051
+ }
32052
+ ]).toArray();
32053
+ const gradeLevel = result[0] || null;
32054
+ setCache(cacheKey, gradeLevel, 300).then(() => {
32055
+ logger44.log({
32056
+ level: "info",
32057
+ message: `Cache set for grade level by id: ${cacheKey}`
32058
+ });
32059
+ }).catch((err) => {
32060
+ logger44.log({
32061
+ level: "error",
32062
+ message: `Failed to set cache for grade level by id: ${err.message}`
32063
+ });
32064
+ });
32065
+ return gradeLevel;
32066
+ } catch (error) {
32067
+ if (error instanceof AppError21) {
32068
+ throw error;
32069
+ } else {
32070
+ throw new InternalServerError31("Failed to get grade level.");
32071
+ }
32072
+ }
32073
+ }
32074
+ async function deleteById(_id, session) {
32075
+ try {
32076
+ _id = new ObjectId53(_id);
32077
+ } catch (error) {
32078
+ throw new BadRequestError86("Invalid ID.");
32079
+ }
32080
+ try {
32081
+ const res = await collection.updateOne(
32082
+ { _id },
32083
+ { $set: { status: "deleted", deletedAt: /* @__PURE__ */ new Date() } },
32084
+ { session }
32085
+ );
32086
+ delCachedData();
32087
+ return res;
32088
+ } catch (error) {
32089
+ logger44.log({
32090
+ level: "error",
32091
+ message: error.message
32092
+ });
32093
+ if (error instanceof AppError21) {
32094
+ throw error;
32095
+ } else {
32096
+ throw new InternalServerError31("Failed to delete grade level.");
32097
+ }
32098
+ }
32099
+ }
32100
+ async function getByEducationLevel(educationLevel, school) {
32101
+ const query = {
32102
+ educationLevel,
32103
+ status: "active"
32104
+ };
32105
+ if (school) {
32106
+ try {
32107
+ query.school = new ObjectId53(school);
32108
+ } catch (error) {
32109
+ throw new BadRequestError86("Invalid school ID format.");
32110
+ }
32111
+ }
32112
+ const cacheKey = makeCacheKey26(namespace_collection, {
32113
+ educationLevel,
32114
+ school: school || "all",
32115
+ method: "getByEducationLevel"
32116
+ });
32117
+ try {
32118
+ const cached = await getCache(cacheKey);
32119
+ if (cached) {
32120
+ logger44.log({
32121
+ level: "info",
32122
+ message: `Cache hit for getByEducationLevel: ${cacheKey}`
32123
+ });
32124
+ return cached;
32125
+ }
32126
+ const result = await collection.find(query).sort({ gradeLevel: 1 }).toArray();
32127
+ setCache(cacheKey, result, 300).then(() => {
32128
+ logger44.log({
32129
+ level: "info",
32130
+ message: `Cache set for getByEducationLevel: ${cacheKey}`
32131
+ });
32132
+ }).catch((err) => {
32133
+ logger44.log({
32134
+ level: "error",
32135
+ message: `Failed to set cache for getByEducationLevel: ${err.message}`
32136
+ });
32137
+ });
32138
+ return result;
32139
+ } catch (error) {
32140
+ logger44.log({ level: "error", message: `${error}` });
32141
+ throw error;
32142
+ }
32143
+ }
32144
+ function delCachedData() {
32145
+ delNamespace().then(() => {
32146
+ logger44.log({
32147
+ level: "info",
32148
+ message: `Cache namespace cleared for ${namespace_collection}`
32149
+ });
32150
+ }).catch((err) => {
32151
+ logger44.log({
32152
+ level: "error",
32153
+ message: `Failed to clear cache namespace for ${namespace_collection}: ${err.message}`
32154
+ });
32155
+ });
32156
+ }
32157
+ return {
32158
+ createIndexes,
32159
+ add,
32160
+ getAll,
32161
+ getById,
32162
+ updateById,
32163
+ deleteById,
32164
+ getByEducationLevel
32165
+ };
32166
+ }
32167
+
32168
+ // src/controllers/grade-level.controller.ts
32169
+ import { BadRequestError as BadRequestError87, logger as logger45 } from "@eeplatform/nodejs-utils";
32170
+ import Joi48 from "joi";
32171
+ function useGradeLevelController() {
32172
+ const {
32173
+ getAll: _getAll,
32174
+ getById: _getById,
32175
+ add: _add,
32176
+ updateById: _updateById,
32177
+ deleteById: _deleteById,
32178
+ getByEducationLevel: _getByEducationLevel
32179
+ } = useGradeLevelRepo();
32180
+ async function add(req, res, next) {
32181
+ const value = req.body;
32182
+ const { error } = schemaGradeLevel.validate(value);
32183
+ if (error) {
32184
+ next(new BadRequestError87(error.message));
32185
+ logger45.info(`Controller: ${error.message}`);
32186
+ return;
32187
+ }
32188
+ try {
32189
+ const result = await _add(value);
32190
+ res.json({
32191
+ message: "Successfully created grade level.",
32192
+ data: { _id: result }
32193
+ });
32194
+ return;
32195
+ } catch (error2) {
32196
+ next(error2);
32197
+ }
32198
+ }
32199
+ async function updateById(req, res, next) {
32200
+ const value = req.body;
32201
+ const id = req.params.id ?? "";
32202
+ const validation = Joi48.object({
32203
+ id: Joi48.string().hex().required(),
32204
+ value: Joi48.object({
32205
+ school: Joi48.string().hex().optional(),
32206
+ educationLevel: Joi48.string().optional(),
32207
+ gradeLevel: Joi48.string().optional(),
32208
+ teachingStyle: Joi48.string().optional(),
32209
+ maxTeachingHoursPerDay: Joi48.number().integer().min(0).optional(),
32210
+ maxTeachingHoursPerWeek: Joi48.number().integer().min(0).optional(),
32211
+ defaultStartTime: Joi48.string().optional().allow("", null),
32212
+ defaultEndTime: Joi48.string().optional().allow("", null)
32213
+ }).min(1)
32214
+ });
32215
+ const { error } = validation.validate({ id, value });
32216
+ if (error) {
32217
+ next(new BadRequestError87(error.message));
32218
+ logger45.info(`Controller: ${error.message}`);
32219
+ return;
32220
+ }
32221
+ try {
32222
+ const result = await _updateById(id, value);
32223
+ res.json({
32224
+ message: "Successfully updated grade level.",
32225
+ data: result
32226
+ });
32227
+ return;
32228
+ } catch (error2) {
32229
+ next(error2);
32230
+ }
32231
+ }
32232
+ async function getAll(req, res, next) {
32233
+ const query = req.query;
32234
+ const validation = Joi48.object({
32235
+ page: Joi48.number().min(1).optional().allow("", null),
32236
+ limit: Joi48.number().min(1).optional().allow("", null),
32237
+ search: Joi48.string().optional().allow("", null),
32238
+ educationLevel: Joi48.string().optional().allow("", null),
32239
+ gradeLevel: Joi48.string().optional().allow("", null),
32240
+ teachingStyle: Joi48.string().optional().allow("", null),
32241
+ school: Joi48.string().hex().optional().allow("", null),
32242
+ status: Joi48.string().optional().allow("", null)
32243
+ });
32244
+ const { error } = validation.validate(query);
32245
+ if (error) {
32246
+ next(new BadRequestError87(error.message));
32247
+ return;
32248
+ }
32249
+ const page = parseInt(req.query.page) ?? 1;
32250
+ let limit = parseInt(req.query.limit) ?? 20;
32251
+ limit = isNaN(limit) ? 20 : limit;
32252
+ const sort = req.query.sort ? String(req.query.sort).split(",") : "";
32253
+ const sortOrder = req.query.sortOrder ? String(req.query.sortOrder).split(",") : "";
32254
+ const sortObj = {};
32255
+ if (sort && Array.isArray(sort) && sort.length && sortOrder && Array.isArray(sortOrder) && sortOrder.length) {
32256
+ sort.forEach((field, index) => {
32257
+ sortObj[field] = sortOrder[index] === "desc" ? -1 : 1;
32258
+ });
32259
+ }
32260
+ const status = req.query.status ?? "active";
32261
+ const educationLevel = req.query.educationLevel ?? "";
32262
+ const gradeLevel = req.query.gradeLevel ?? "";
32263
+ const teachingStyle = req.query.teachingStyle ?? "";
32264
+ const school = req.query.school ?? "";
32265
+ const search = req.query.search ?? "";
32266
+ try {
32267
+ const gradeLevels = await _getAll({
32268
+ page,
32269
+ limit,
32270
+ sort: sortObj,
32271
+ status,
32272
+ educationLevel,
32273
+ gradeLevel,
32274
+ teachingStyle,
32275
+ school,
32276
+ search
32277
+ });
32278
+ res.json(gradeLevels);
32279
+ return;
32280
+ } catch (error2) {
32281
+ next(error2);
32282
+ }
32283
+ }
32284
+ async function getById(req, res, next) {
32285
+ const id = req.params.id;
32286
+ const validation = Joi48.object({
32287
+ id: Joi48.string().hex().required()
32288
+ });
32289
+ const { error } = validation.validate({ id });
32290
+ if (error) {
32291
+ next(new BadRequestError87(error.message));
32292
+ return;
32293
+ }
32294
+ try {
32295
+ const gradeLevel = await _getById(id);
32296
+ res.json({
32297
+ message: "Successfully retrieved grade level.",
32298
+ data: { gradeLevel }
32299
+ });
32300
+ return;
32301
+ } catch (error2) {
32302
+ next(error2);
32303
+ }
32304
+ }
32305
+ async function deleteById(req, res, next) {
32306
+ const id = req.params.id;
32307
+ const validation = Joi48.object({
32308
+ id: Joi48.string().hex().required()
32309
+ });
32310
+ const { error } = validation.validate({ id });
32311
+ if (error) {
32312
+ next(new BadRequestError87(error.message));
32313
+ return;
32314
+ }
32315
+ try {
32316
+ const result = await _deleteById(id);
32317
+ res.json({
32318
+ message: "Successfully deleted grade level.",
32319
+ data: result
32320
+ });
32321
+ return;
32322
+ } catch (error2) {
32323
+ next(error2);
32324
+ }
32325
+ }
32326
+ async function getByEducationLevel(req, res, next) {
32327
+ const educationLevel = req.params.educationLevel;
32328
+ const school = req.query.school;
32329
+ const validation = Joi48.object({
32330
+ educationLevel: Joi48.string().required(),
32331
+ school: Joi48.string().hex().optional().allow("", null)
32332
+ });
32333
+ const { error } = validation.validate({ educationLevel, school });
32334
+ if (error) {
32335
+ next(new BadRequestError87(error.message));
32336
+ return;
32337
+ }
32338
+ try {
32339
+ const gradeLevels = await _getByEducationLevel(educationLevel, school);
32340
+ res.json({
32341
+ message: "Successfully retrieved grade levels by education level.",
32342
+ data: { gradeLevels }
32343
+ });
32344
+ return;
32345
+ } catch (error2) {
32346
+ next(error2);
32347
+ }
32348
+ }
32349
+ return {
32350
+ add,
32351
+ getAll,
32352
+ getById,
32353
+ updateById,
32354
+ deleteById,
32355
+ getByEducationLevel
32356
+ };
32357
+ }
31774
32358
  export {
31775
32359
  ACCESS_TOKEN_EXPIRY,
31776
32360
  ACCESS_TOKEN_SECRET,
@@ -31796,6 +32380,7 @@ export {
31796
32380
  MDivision,
31797
32381
  MEntity,
31798
32382
  MFile,
32383
+ MGradeLevel,
31799
32384
  MMember,
31800
32385
  MONGO_DB,
31801
32386
  MONGO_URI,
@@ -31842,6 +32427,7 @@ export {
31842
32427
  schemaBuildingUnit,
31843
32428
  schemaCurriculum,
31844
32429
  schemaDivision,
32430
+ schemaGradeLevel,
31845
32431
  schemaOffice,
31846
32432
  schemaPlantilla,
31847
32433
  schemaRegion,
@@ -31871,6 +32457,8 @@ export {
31871
32457
  useFileRepo,
31872
32458
  useFileService,
31873
32459
  useGitHubService,
32460
+ useGradeLevelController,
32461
+ useGradeLevelRepo,
31874
32462
  useInvoiceController,
31875
32463
  useInvoiceModel,
31876
32464
  useInvoiceRepo,