@eeplatform/basic-edu 1.10.2 → 1.10.4

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.js CHANGED
@@ -1365,9 +1365,11 @@ __export(src_exports, {
1365
1365
  modelSectionPreset: () => modelSectionPreset,
1366
1366
  modelSectionStudent: () => modelSectionStudent,
1367
1367
  modelSectionSubject: () => modelSectionSubject,
1368
+ modelStrand: () => modelStrand,
1368
1369
  modelSubject: () => modelSubject,
1369
1370
  modelTeachingLoad: () => modelTeachingLoad,
1370
1371
  modelTeachingLoadSlot: () => modelTeachingLoadSlot,
1372
+ modelTrack: () => modelTrack,
1371
1373
  schemaAsset: () => schemaAsset,
1372
1374
  schemaAssetUpdateOption: () => schemaAssetUpdateOption,
1373
1375
  schemaBasicEduCount: () => schemaBasicEduCount,
@@ -1397,10 +1399,12 @@ __export(src_exports, {
1397
1399
  schemaSectionSubject: () => schemaSectionSubject,
1398
1400
  schemaSectionSubjectSetup: () => schemaSectionSubjectSetup,
1399
1401
  schemaStockCard: () => schemaStockCard,
1402
+ schemaStrand: () => schemaStrand,
1400
1403
  schemaSubject: () => schemaSubject,
1401
1404
  schemaSubjectAdd: () => schemaSubjectAdd,
1402
1405
  schemaTeachingLoad: () => schemaTeachingLoad,
1403
1406
  schemaTeachingLoadSlot: () => schemaTeachingLoadSlot,
1407
+ schemaTrack: () => schemaTrack,
1404
1408
  schemaUpdateOptions: () => schemaUpdateOptions,
1405
1409
  schemaUpdateStatus: () => schemaUpdateStatus,
1406
1410
  statusesProgramScreening: () => statusesProgramScreening,
@@ -1456,13 +1460,18 @@ __export(src_exports, {
1456
1460
  useStockCardController: () => useStockCardController,
1457
1461
  useStockCardRepository: () => useStockCardRepository,
1458
1462
  useStockCardService: () => useStockCardService,
1463
+ useStrandController: () => useStrandController,
1464
+ useStrandRepo: () => useStrandRepo,
1459
1465
  useSubjectController: () => useSubjectController,
1460
1466
  useSubjectRepo: () => useSubjectRepo,
1461
1467
  useSubjectService: () => useSubjectService,
1462
1468
  useTeachingLoadController: () => useTeachingLoadController,
1463
1469
  useTeachingLoadRepo: () => useTeachingLoadRepo,
1464
1470
  useTeachingLoadSlotController: () => useTeachingLoadSlotController,
1465
- useTeachingLoadSlotRepo: () => useTeachingLoadSlotRepo
1471
+ useTeachingLoadSlotRepo: () => useTeachingLoadSlotRepo,
1472
+ useTrackController: () => useTrackController,
1473
+ useTrackRepo: () => useTrackRepo,
1474
+ useTrackService: () => useTrackService
1466
1475
  });
1467
1476
  module.exports = __toCommonJS(src_exports);
1468
1477
 
@@ -2159,7 +2168,6 @@ var schemaSubject = import_joi3.default.object({
2159
2168
  curriculum: import_joi3.default.string().hex().required(),
2160
2169
  curriculumName: import_joi3.default.string().required(),
2161
2170
  effectiveSchoolYear: import_joi3.default.array().items(import_joi3.default.number().integer().min(1900)).optional(),
2162
- educationLevel: import_joi3.default.string().required(),
2163
2171
  gradeLevel: import_joi3.default.string().required(),
2164
2172
  program: import_joi3.default.string().hex().optional().allow("", null),
2165
2173
  programName: import_joi3.default.string().optional().allow("", null),
@@ -2181,7 +2189,6 @@ var schemaSubjectAdd = import_joi3.default.object({
2181
2189
  curriculum: import_joi3.default.string().hex().required(),
2182
2190
  curriculumName: import_joi3.default.string().required(),
2183
2191
  effectiveSchoolYear: import_joi3.default.array().items(import_joi3.default.number().integer().min(1900)).optional(),
2184
- educationLevel: import_joi3.default.string().required(),
2185
2192
  gradeLevel: import_joi3.default.array().items(import_joi3.default.string()).required(),
2186
2193
  program: import_joi3.default.string().hex().optional().allow("", null),
2187
2194
  programName: import_joi3.default.string().optional().allow("", null),
@@ -2233,7 +2240,6 @@ function modelSubject(value) {
2233
2240
  curriculum: value.curriculum,
2234
2241
  curriculumName: value.curriculumName ?? "",
2235
2242
  effectiveSchoolYear: value.effectiveSchoolYear ?? [],
2236
- educationLevel: value.educationLevel ?? "",
2237
2243
  gradeLevel: value.gradeLevel ?? "",
2238
2244
  program: value.program,
2239
2245
  programName: value.programName ?? "",
@@ -2678,7 +2684,6 @@ function useSubjectService() {
2678
2684
  curriculum: value.curriculum,
2679
2685
  curriculumName: value.curriculumName,
2680
2686
  effectiveSchoolYear: value.effectiveSchoolYear,
2681
- educationLevel: value.educationLevel,
2682
2687
  gradeLevel,
2683
2688
  subjectCode: value.subjectCode,
2684
2689
  subjectName: value.subjectName,
@@ -2747,7 +2752,6 @@ function useSubjectController() {
2747
2752
  id: import_joi4.default.string().hex().required(),
2748
2753
  value: import_joi4.default.object({
2749
2754
  curriculum: import_joi4.default.string().hex().optional(),
2750
- educationLevel: import_joi4.default.string().optional(),
2751
2755
  gradeLevel: import_joi4.default.string().optional(),
2752
2756
  subjectCode: import_joi4.default.string().optional(),
2753
2757
  subjectName: import_joi4.default.string().optional(),
@@ -35377,8 +35381,6 @@ var schemaGradeLevel = import_joi17.default.object({
35377
35381
  school: import_joi17.default.string().hex().optional(),
35378
35382
  educationLevel: import_joi17.default.string().required(),
35379
35383
  gradeLevel: import_joi17.default.string().required(),
35380
- tracks: import_joi17.default.array().items(import_joi17.default.string()).optional(),
35381
- trackStrands: import_joi17.default.array().items(import_joi17.default.string()).optional(),
35382
35384
  teachingStyle: import_joi17.default.string().required(),
35383
35385
  maxNumberOfLearners: import_joi17.default.number().required(),
35384
35386
  minNumberOfLearners: import_joi17.default.number().required(),
@@ -35422,8 +35424,6 @@ function MGradeLevel(value) {
35422
35424
  school: value.school ?? void 0,
35423
35425
  educationLevel: value.educationLevel ?? "",
35424
35426
  gradeLevel: value.gradeLevel ?? "",
35425
- tracks: value.tracks ?? [],
35426
- trackStrands: value.trackStrands ?? [],
35427
35427
  teachingStyle: value.teachingStyle ?? "",
35428
35428
  maxNumberOfLearners: value.maxNumberOfLearners ?? 0,
35429
35429
  minNumberOfLearners: value.minNumberOfLearners ?? 0,
@@ -39413,7 +39413,7 @@ function useSectionRepo() {
39413
39413
  { key: { createdAt: 1 } },
39414
39414
  { key: { name: "text", schoolYear: "text", gradeLevel: "text" } },
39415
39415
  {
39416
- key: { school: 1, teacher: 1, schoolYear: 1, status: 1 },
39416
+ key: { name: 1, school: 1, gradeLevel: 1, schoolYear: 1, status: 1 },
39417
39417
  unique: true,
39418
39418
  name: "unique_section"
39419
39419
  }
@@ -39883,6 +39883,13 @@ function modelSectionStudent(value) {
39883
39883
  throw new Error("Invalid school ID.");
39884
39884
  }
39885
39885
  }
39886
+ if (value.student && typeof value.student === "string") {
39887
+ try {
39888
+ value.student = new import_mongodb31.ObjectId(value.student);
39889
+ } catch (error2) {
39890
+ throw new Error("Invalid student ID.");
39891
+ }
39892
+ }
39886
39893
  return {
39887
39894
  _id: value._id,
39888
39895
  lrn: value.lrn,
@@ -40060,14 +40067,6 @@ function useSectionStudentRepo() {
40060
40067
  async function getStudent(options) {
40061
40068
  const query = {};
40062
40069
  const cacheKeyOptions = { tag: "getStudent" };
40063
- if (options.learner) {
40064
- try {
40065
- query.learner = new import_mongodb32.ObjectId(options.learner);
40066
- cacheKeyOptions.learner = String(options.learner);
40067
- } catch (error) {
40068
- throw new import_nodejs_utils54.BadRequestError("Invalid learner ID.");
40069
- }
40070
- }
40071
40070
  if (options.schoolYear) {
40072
40071
  query.schoolYear = options.schoolYear;
40073
40072
  cacheKeyOptions.schoolYear = options.schoolYear;
@@ -40139,7 +40138,6 @@ var schemaSectionSubject = import_joi34.default.object({
40139
40138
  section: import_joi34.default.string().hex().required(),
40140
40139
  sectionName: import_joi34.default.string().required(),
40141
40140
  gradeLevel: import_joi34.default.string().required(),
40142
- educationLevel: import_joi34.default.string().required(),
40143
40141
  schoolYear: import_joi34.default.string().required(),
40144
40142
  subjectCode: import_joi34.default.string().required(),
40145
40143
  subjectName: import_joi34.default.string().required(),
@@ -40212,7 +40210,6 @@ function modelSectionSubject(value) {
40212
40210
  section: value.section,
40213
40211
  sectionName: value.sectionName,
40214
40212
  gradeLevel: value.gradeLevel,
40215
- educationLevel: value.educationLevel,
40216
40213
  schoolYear: value.schoolYear,
40217
40214
  subjectCode: value.subjectCode,
40218
40215
  subjectName: value.subjectName,
@@ -42350,7 +42347,6 @@ var import_nodejs_utils66 = require("@eeplatform/nodejs-utils");
42350
42347
  var import_joi41 = __toESM(require("joi"));
42351
42348
  var import_mongodb39 = require("mongodb");
42352
42349
  var schemaPersonnel = import_joi41.default.object({
42353
- _id: import_joi41.default.string().hex().optional().allow("", null),
42354
42350
  school: import_joi41.default.string().hex().required(),
42355
42351
  schoolName: import_joi41.default.string().optional().allow("", null),
42356
42352
  firstName: import_joi41.default.string().required(),
@@ -42360,11 +42356,7 @@ var schemaPersonnel = import_joi41.default.object({
42360
42356
  title: import_joi41.default.string().optional().allow("", null),
42361
42357
  classification: import_joi41.default.string().required(),
42362
42358
  specializations: import_joi41.default.array().items(import_joi41.default.string()).optional(),
42363
- gradeLevels: import_joi41.default.array().items(import_joi41.default.string()).optional(),
42364
- status: import_joi41.default.string().optional().allow("", null),
42365
- createdAt: import_joi41.default.date().optional().allow("", null),
42366
- updatedAt: import_joi41.default.date().optional().allow("", null),
42367
- deletedAt: import_joi41.default.date().optional().allow("", null)
42359
+ gradeLevels: import_joi41.default.array().items(import_joi41.default.string()).optional()
42368
42360
  });
42369
42361
  function MPersonnel(value) {
42370
42362
  const { error } = schemaPersonnel.validate(value);
@@ -43022,22 +43014,22 @@ function useSectionService() {
43022
43014
  if (existingSection) {
43023
43015
  sectionId = existingSection._id?.toString() || "";
43024
43016
  sectionsSkipped++;
43025
- continue;
43017
+ } else {
43018
+ sectionId = await createSection(
43019
+ {
43020
+ school: value.school,
43021
+ schoolYear: value.schoolYear,
43022
+ gradeLevel: value.gradeLevel,
43023
+ name: sectionName,
43024
+ students: size
43025
+ },
43026
+ session
43027
+ );
43028
+ sectionsGenerated++;
43026
43029
  }
43027
- sectionId = await createSection(
43028
- {
43029
- school: value.school,
43030
- schoolYear: value.schoolYear,
43031
- gradeLevel: value.gradeLevel,
43032
- name: sectionName,
43033
- students: size
43034
- },
43035
- session
43036
- );
43037
43030
  if (!sectionId) {
43038
43031
  throw new import_nodejs_utils69.InternalServerError("Required section ID is missing.");
43039
43032
  }
43040
- sectionsGenerated++;
43041
43033
  const skip = totalStudentsProcessed;
43042
43034
  const learners = await getLeanerByGradeLevel(
43043
43035
  {
@@ -43067,24 +43059,24 @@ function useSectionService() {
43067
43059
  });
43068
43060
  if (existingStudent) {
43069
43061
  studentSkipped++;
43070
- continue;
43062
+ } else {
43063
+ await assignStudent(
43064
+ {
43065
+ section: sectionId,
43066
+ lrn: student.learnerInfo.lrn,
43067
+ student: student._id?.toString(),
43068
+ studentName: `${student.learnerInfo.firstName} ${student.learnerInfo.lastName}`,
43069
+ school: value.school,
43070
+ schoolName: schoolData.name,
43071
+ gradeLevel: value.gradeLevel,
43072
+ educationLevel: gradeLevelData.educationLevel,
43073
+ schoolYear: value.schoolYear,
43074
+ status: "active"
43075
+ },
43076
+ session
43077
+ );
43078
+ studentCreated++;
43071
43079
  }
43072
- await assignStudent(
43073
- {
43074
- section: sectionId,
43075
- lrn: student.learnerInfo.lrn,
43076
- student: student._id?.toString(),
43077
- studentName: `${student.learnerInfo.firstName} ${student.learnerInfo.lastName}`,
43078
- school: value.school,
43079
- schoolName: schoolData.name,
43080
- gradeLevel: value.gradeLevel,
43081
- educationLevel: gradeLevelData.educationLevel,
43082
- schoolYear: value.schoolYear,
43083
- status: "active"
43084
- },
43085
- session
43086
- );
43087
- studentCreated++;
43088
43080
  }
43089
43081
  if (value.gradeLevel !== "kindergarten") {
43090
43082
  const curriculumSubjects = await getAllCurriculumSubjects({
@@ -43098,35 +43090,34 @@ function useSectionService() {
43098
43090
  subjectCode: curriculumSubject.subjectCode,
43099
43091
  schoolYear: value.schoolYear
43100
43092
  });
43101
- if (existingSectionSubject) {
43093
+ if (existingSectionSubject && existingSectionSubject.length) {
43102
43094
  subjectsSkipped++;
43103
- continue;
43095
+ } else {
43096
+ await addSectionSubject(
43097
+ {
43098
+ curriculum: curriculumSubject.curriculum.toString(),
43099
+ school: value.school,
43100
+ schoolName: schoolData.name,
43101
+ gradeLevel: value.gradeLevel,
43102
+ schoolYear: value.schoolYear,
43103
+ section: sectionId,
43104
+ sectionName,
43105
+ subjectCode: curriculumSubject.subjectCode,
43106
+ subjectName: curriculumSubject.subjectName,
43107
+ teacher: "",
43108
+ teacherName: "",
43109
+ schedule: "",
43110
+ daysOfWeek: [],
43111
+ classroom: "",
43112
+ classroomName: "",
43113
+ sessionDuration: curriculumSubject.sessionDuration,
43114
+ sessionFrequency: curriculumSubject.sessionFrequency,
43115
+ status: "draft"
43116
+ },
43117
+ session
43118
+ );
43119
+ subjectsAssigned++;
43104
43120
  }
43105
- await addSectionSubject(
43106
- {
43107
- curriculum: curriculumSubject.curriculum.toString(),
43108
- school: value.school,
43109
- schoolName: schoolData.name,
43110
- gradeLevel: value.gradeLevel,
43111
- educationLevel: gradeLevelData.educationLevel,
43112
- schoolYear: value.schoolYear,
43113
- section: sectionId,
43114
- sectionName,
43115
- subjectCode: curriculumSubject.subjectCode,
43116
- subjectName: curriculumSubject.subjectName,
43117
- teacher: "",
43118
- teacherName: "",
43119
- schedule: "",
43120
- daysOfWeek: [],
43121
- classroom: "",
43122
- classroomName: "",
43123
- sessionDuration: curriculumSubject.sessionDuration,
43124
- sessionFrequency: curriculumSubject.sessionFrequency,
43125
- status: "draft"
43126
- },
43127
- session
43128
- );
43129
- subjectsAssigned++;
43130
43121
  }
43131
43122
  }
43132
43123
  }
@@ -43159,7 +43150,7 @@ function useSectionService() {
43159
43150
  school: value.school,
43160
43151
  schoolYear: value.schoolYear
43161
43152
  });
43162
- if (existingLoad) {
43153
+ if (existingLoad && existingLoad.length) {
43163
43154
  teachingLoadsSkipped++;
43164
43155
  continue;
43165
43156
  }
@@ -46047,6 +46038,1120 @@ function useKindergartenDomainController() {
46047
46038
  };
46048
46039
  }
46049
46040
 
46041
+ // src/resources/track/track.model.ts
46042
+ var import_nodejs_utils86 = require("@eeplatform/nodejs-utils");
46043
+ var import_joi52 = __toESM(require("joi"));
46044
+ var import_mongodb48 = require("mongodb");
46045
+ var schemaTrack = import_joi52.default.object({
46046
+ name: import_joi52.default.string().max(100).required(),
46047
+ school: import_joi52.default.string().hex().required()
46048
+ });
46049
+ function modelTrack(value) {
46050
+ const { error } = schemaTrack.validate(value);
46051
+ if (error) {
46052
+ throw new import_nodejs_utils86.BadRequestError(`Invalid track data: ${error.message}`);
46053
+ }
46054
+ if (value._id && typeof value._id === "string") {
46055
+ try {
46056
+ value._id = new import_mongodb48.ObjectId(value._id);
46057
+ } catch (error2) {
46058
+ throw new Error("Invalid _id.");
46059
+ }
46060
+ }
46061
+ if (value.school && typeof value.school === "string") {
46062
+ try {
46063
+ value.school = new import_mongodb48.ObjectId(value.school);
46064
+ } catch (error2) {
46065
+ throw new Error("Invalid school.");
46066
+ }
46067
+ }
46068
+ return {
46069
+ _id: value._id,
46070
+ name: value.name,
46071
+ school: value.school,
46072
+ status: value.status ?? "active",
46073
+ createdAt: value.createdAt ?? /* @__PURE__ */ new Date(),
46074
+ updatedAt: value.updatedAt ?? "",
46075
+ deletedAt: value.deletedAt ?? ""
46076
+ };
46077
+ }
46078
+
46079
+ // src/resources/track/track.repository.ts
46080
+ var import_nodejs_utils87 = require("@eeplatform/nodejs-utils");
46081
+ var import_mongodb49 = require("mongodb");
46082
+ function useTrackRepo() {
46083
+ const db = import_nodejs_utils87.useAtlas.getDb();
46084
+ if (!db) {
46085
+ throw new Error("Unable to connect to server.");
46086
+ }
46087
+ const namespace_collection = "deped.school.tracks";
46088
+ const collection = db.collection(namespace_collection);
46089
+ const { getCache, setCache, delNamespace } = (0, import_nodejs_utils87.useCache)(namespace_collection);
46090
+ async function createIndexes() {
46091
+ try {
46092
+ await collection.createIndexes([
46093
+ { key: { school: 1 } },
46094
+ { key: { name: "text" } },
46095
+ {
46096
+ key: { name: 1, school: 1, status: 1 },
46097
+ unique: true,
46098
+ name: "unique_track"
46099
+ }
46100
+ ]);
46101
+ } catch (error) {
46102
+ throw new Error("Failed to create index on tracks.");
46103
+ }
46104
+ }
46105
+ function delCachedData() {
46106
+ delNamespace().then(() => {
46107
+ import_nodejs_utils87.logger.log({
46108
+ level: "info",
46109
+ message: `Cache namespace cleared for ${namespace_collection}`
46110
+ });
46111
+ }).catch((err) => {
46112
+ import_nodejs_utils87.logger.log({
46113
+ level: "error",
46114
+ message: `Failed to clear cache namespace for ${namespace_collection}: ${err.message}`
46115
+ });
46116
+ });
46117
+ }
46118
+ async function add(value, session) {
46119
+ try {
46120
+ value = modelTrack(value);
46121
+ const res = await collection.insertOne(value, { session });
46122
+ delCachedData();
46123
+ return res.insertedId;
46124
+ } catch (error) {
46125
+ import_nodejs_utils87.logger.log({
46126
+ level: "error",
46127
+ message: error.message
46128
+ });
46129
+ if (error instanceof import_nodejs_utils87.AppError) {
46130
+ throw error;
46131
+ } else {
46132
+ const isDuplicated = error.message.includes("duplicate");
46133
+ if (isDuplicated) {
46134
+ throw new import_nodejs_utils87.BadRequestError("track already exists.");
46135
+ }
46136
+ throw new Error("Failed to create track.");
46137
+ }
46138
+ }
46139
+ }
46140
+ async function getAll({
46141
+ search = "",
46142
+ page = 1,
46143
+ limit = 10,
46144
+ sort = {},
46145
+ status = "active",
46146
+ school = ""
46147
+ } = {}) {
46148
+ page = page > 0 ? page - 1 : 0;
46149
+ const query = {
46150
+ deletedAt: { $in: ["", null] },
46151
+ status
46152
+ };
46153
+ sort = Object.keys(sort).length > 0 ? sort : { _id: 1 };
46154
+ const cacheKeyOptions = {
46155
+ status,
46156
+ page,
46157
+ limit,
46158
+ sort: JSON.stringify(sort)
46159
+ };
46160
+ if (search) {
46161
+ query.$text = { $search: search };
46162
+ cacheKeyOptions.search = search;
46163
+ }
46164
+ if (school) {
46165
+ try {
46166
+ query.school = new import_mongodb49.ObjectId(school);
46167
+ } catch (error) {
46168
+ throw new import_nodejs_utils87.BadRequestError("Invalid school ID.");
46169
+ }
46170
+ cacheKeyOptions.school = school;
46171
+ }
46172
+ const cacheKey = (0, import_nodejs_utils87.makeCacheKey)(namespace_collection, cacheKeyOptions);
46173
+ import_nodejs_utils87.logger.log({
46174
+ level: "info",
46175
+ message: `Cache key for getAll tracks: ${cacheKey}`
46176
+ });
46177
+ try {
46178
+ const cached = await getCache(cacheKey);
46179
+ if (cached) {
46180
+ import_nodejs_utils87.logger.log({
46181
+ level: "info",
46182
+ message: `Cache hit for getAll tracks: ${cacheKey}`
46183
+ });
46184
+ return cached;
46185
+ }
46186
+ const items = await collection.aggregate([
46187
+ { $match: query },
46188
+ { $sort: sort },
46189
+ { $skip: page * limit },
46190
+ { $limit: limit }
46191
+ ]).toArray();
46192
+ const total = await collection.countDocuments(query);
46193
+ const result = (0, import_nodejs_utils87.paginate)(items, total, page, limit);
46194
+ setCache(cacheKey, result, 300).then(() => {
46195
+ import_nodejs_utils87.logger.log({
46196
+ level: "info",
46197
+ message: `Cache set for getAll tracks: ${cacheKey}`
46198
+ });
46199
+ }).catch((err) => {
46200
+ import_nodejs_utils87.logger.log({
46201
+ level: "error",
46202
+ message: `Failed to set cache for getAll tracks: ${err.message}`
46203
+ });
46204
+ });
46205
+ return result;
46206
+ } catch (error) {
46207
+ if (error instanceof import_nodejs_utils87.AppError) {
46208
+ throw error;
46209
+ } else {
46210
+ throw new import_nodejs_utils87.InternalServerError("Failed to get tracks.");
46211
+ }
46212
+ }
46213
+ }
46214
+ async function getById(_id) {
46215
+ try {
46216
+ _id = new import_mongodb49.ObjectId(_id);
46217
+ } catch (error) {
46218
+ throw new import_nodejs_utils87.BadRequestError(namespace_collection + " Invalid ID.");
46219
+ }
46220
+ const cacheKey = (0, import_nodejs_utils87.makeCacheKey)(namespace_collection, {
46221
+ _id: _id.toString()
46222
+ });
46223
+ import_nodejs_utils87.logger.log({
46224
+ level: "info",
46225
+ message: `Cache key for getById track: ${cacheKey}`
46226
+ });
46227
+ try {
46228
+ const cached = await getCache(cacheKey);
46229
+ if (cached) {
46230
+ import_nodejs_utils87.logger.log({
46231
+ level: "info",
46232
+ message: `Cache hit for getById track: ${cacheKey}`
46233
+ });
46234
+ return cached;
46235
+ }
46236
+ const result = await collection.findOne({
46237
+ _id,
46238
+ deletedAt: { $in: ["", null] }
46239
+ });
46240
+ if (!result) {
46241
+ throw new import_nodejs_utils87.BadRequestError("track not found.");
46242
+ }
46243
+ setCache(cacheKey, result, 300).then(() => {
46244
+ import_nodejs_utils87.logger.log({
46245
+ level: "info",
46246
+ message: `Cache set for getById track: ${cacheKey}`
46247
+ });
46248
+ }).catch((err) => {
46249
+ import_nodejs_utils87.logger.log({
46250
+ level: "error",
46251
+ message: `Failed to set cache for getById track: ${err.message}`
46252
+ });
46253
+ });
46254
+ return result;
46255
+ } catch (error) {
46256
+ if (error instanceof import_nodejs_utils87.AppError) {
46257
+ throw error;
46258
+ } else {
46259
+ throw new import_nodejs_utils87.InternalServerError("Failed to get track.");
46260
+ }
46261
+ }
46262
+ }
46263
+ async function getBySchool(school) {
46264
+ try {
46265
+ school = new import_mongodb49.ObjectId(school);
46266
+ } catch (error) {
46267
+ throw new import_nodejs_utils87.BadRequestError("Invalid school ID.");
46268
+ }
46269
+ const cacheKey = (0, import_nodejs_utils87.makeCacheKey)(namespace_collection, {
46270
+ school: school.toString()
46271
+ });
46272
+ import_nodejs_utils87.logger.log({
46273
+ level: "info",
46274
+ message: `Cache key for track by school: ${cacheKey}`
46275
+ });
46276
+ try {
46277
+ const cached = await getCache(cacheKey);
46278
+ if (cached) {
46279
+ import_nodejs_utils87.logger.log({
46280
+ level: "info",
46281
+ message: `Cache hit for track by school: ${cacheKey}`
46282
+ });
46283
+ return cached;
46284
+ }
46285
+ const result = await collection.find({
46286
+ school,
46287
+ deletedAt: { $in: ["", null] }
46288
+ }).toArray();
46289
+ setCache(cacheKey, result, 300).then(() => {
46290
+ import_nodejs_utils87.logger.log({
46291
+ level: "info",
46292
+ message: `Cache set for track by school: ${cacheKey}`
46293
+ });
46294
+ }).catch((err) => {
46295
+ import_nodejs_utils87.logger.log({
46296
+ level: "error",
46297
+ message: `Failed to set cache for track by school: ${err.message}`
46298
+ });
46299
+ });
46300
+ return result;
46301
+ } catch (error) {
46302
+ if (error instanceof import_nodejs_utils87.AppError) {
46303
+ throw error;
46304
+ } else {
46305
+ throw new import_nodejs_utils87.InternalServerError("Failed to get track.");
46306
+ }
46307
+ }
46308
+ }
46309
+ async function updateFieldById({ _id, field, value } = {}, session) {
46310
+ const allowedFields = ["title", "status"];
46311
+ if (!allowedFields.includes(field)) {
46312
+ throw new import_nodejs_utils87.BadRequestError(
46313
+ `Field "${field}" is not allowed to be updated.`
46314
+ );
46315
+ }
46316
+ try {
46317
+ _id = new import_mongodb49.ObjectId(_id);
46318
+ } catch (error) {
46319
+ throw new import_nodejs_utils87.BadRequestError(namespace_collection + " Invalid ID.");
46320
+ }
46321
+ try {
46322
+ await collection.updateOne(
46323
+ { _id, deletedAt: { $in: ["", null] } },
46324
+ { $set: { [field]: value, updatedAt: (/* @__PURE__ */ new Date()).toISOString() } },
46325
+ { session }
46326
+ );
46327
+ delCachedData();
46328
+ return `Successfully updated track ${field}.`;
46329
+ } catch (error) {
46330
+ throw new import_nodejs_utils87.InternalServerError(`Failed to update track ${field}.`);
46331
+ }
46332
+ }
46333
+ async function updateById(_id, value, session) {
46334
+ const { error } = schemaTrack.validate(value);
46335
+ if (error) {
46336
+ throw new import_nodejs_utils87.BadRequestError(`Invalid track data: ${error.message}`);
46337
+ }
46338
+ try {
46339
+ _id = new import_mongodb49.ObjectId(_id);
46340
+ } catch (error2) {
46341
+ throw new import_nodejs_utils87.BadRequestError(namespace_collection + " Invalid ID.");
46342
+ }
46343
+ try {
46344
+ await collection.updateOne(
46345
+ { _id },
46346
+ { $set: { ...value, updatedAt: (/* @__PURE__ */ new Date()).toISOString() } },
46347
+ { session }
46348
+ );
46349
+ delCachedData();
46350
+ return `Successfully updated track.`;
46351
+ } catch (error2) {
46352
+ throw new import_nodejs_utils87.InternalServerError("Failed to update track.");
46353
+ }
46354
+ }
46355
+ async function deleteById(_id, session) {
46356
+ try {
46357
+ _id = new import_mongodb49.ObjectId(_id);
46358
+ } catch (error) {
46359
+ throw new import_nodejs_utils87.BadRequestError(namespace_collection + " Invalid ID.");
46360
+ }
46361
+ try {
46362
+ await collection.updateOne(
46363
+ { _id },
46364
+ { $set: { status: "deleted", deletedAt: /* @__PURE__ */ new Date() } },
46365
+ { session }
46366
+ );
46367
+ delCachedData();
46368
+ return "Successfully deleted track.";
46369
+ } catch (error) {
46370
+ throw new import_nodejs_utils87.InternalServerError("Failed to delete track.");
46371
+ }
46372
+ }
46373
+ return {
46374
+ createIndexes,
46375
+ add,
46376
+ getAll,
46377
+ getById,
46378
+ getBySchool,
46379
+ updateFieldById,
46380
+ updateById,
46381
+ deleteById
46382
+ };
46383
+ }
46384
+
46385
+ // src/resources/track/track.service.ts
46386
+ var import_nodejs_utils90 = require("@eeplatform/nodejs-utils");
46387
+
46388
+ // src/resources/strand/strand.repository.ts
46389
+ var import_nodejs_utils89 = require("@eeplatform/nodejs-utils");
46390
+
46391
+ // src/resources/strand/strand.model.ts
46392
+ var import_nodejs_utils88 = require("@eeplatform/nodejs-utils");
46393
+ var import_joi53 = __toESM(require("joi"));
46394
+ var import_mongodb50 = require("mongodb");
46395
+ var schemaStrand = import_joi53.default.object({
46396
+ track: import_joi53.default.string().hex().required(),
46397
+ trackName: import_joi53.default.string().max(100).optional().allow(null, ""),
46398
+ name: import_joi53.default.string().max(100).required(),
46399
+ school: import_joi53.default.string().hex().required()
46400
+ });
46401
+ function modelStrand(value) {
46402
+ const { error } = schemaStrand.validate(value);
46403
+ if (error) {
46404
+ throw new import_nodejs_utils88.BadRequestError(`Invalid strand data: ${error.message}`);
46405
+ }
46406
+ if (value._id && typeof value._id === "string") {
46407
+ try {
46408
+ value._id = new import_mongodb50.ObjectId(value._id);
46409
+ } catch (error2) {
46410
+ throw new Error("Invalid _id.");
46411
+ }
46412
+ }
46413
+ if (value.school && typeof value.school === "string") {
46414
+ try {
46415
+ value.school = new import_mongodb50.ObjectId(value.school);
46416
+ } catch (error2) {
46417
+ throw new Error("Invalid school.");
46418
+ }
46419
+ }
46420
+ if (value.track && typeof value.track === "string") {
46421
+ try {
46422
+ value.track = new import_mongodb50.ObjectId(value.track);
46423
+ } catch (error2) {
46424
+ throw new Error("Invalid track.");
46425
+ }
46426
+ }
46427
+ return {
46428
+ _id: value._id,
46429
+ track: value.track,
46430
+ trackName: value.trackName ?? "",
46431
+ name: value.name,
46432
+ school: value.school,
46433
+ status: value.status ?? "active",
46434
+ createdAt: value.createdAt ?? /* @__PURE__ */ new Date(),
46435
+ updatedAt: value.updatedAt ?? "",
46436
+ deletedAt: value.deletedAt ?? ""
46437
+ };
46438
+ }
46439
+
46440
+ // src/resources/strand/strand.repository.ts
46441
+ var import_mongodb51 = require("mongodb");
46442
+ function useStrandRepo() {
46443
+ const db = import_nodejs_utils89.useAtlas.getDb();
46444
+ if (!db) {
46445
+ throw new Error("Unable to connect to server.");
46446
+ }
46447
+ const namespace_collection = "deped.school.strands";
46448
+ const collection = db.collection(namespace_collection);
46449
+ const { getCache, setCache, delNamespace } = (0, import_nodejs_utils89.useCache)(namespace_collection);
46450
+ async function createIndexes() {
46451
+ try {
46452
+ await collection.createIndexes([
46453
+ { key: { school: 1 } },
46454
+ { key: { strand: 1 } },
46455
+ { key: { name: "text", strand: "text" } },
46456
+ {
46457
+ key: { name: 1, strand: 1, school: 1, status: 1 },
46458
+ unique: true,
46459
+ name: "unique_strand"
46460
+ }
46461
+ ]);
46462
+ } catch (error) {
46463
+ throw new Error("Failed to create index on strands.");
46464
+ }
46465
+ }
46466
+ function delCachedData() {
46467
+ delNamespace().then(() => {
46468
+ import_nodejs_utils89.logger.log({
46469
+ level: "info",
46470
+ message: `Cache namespace cleared for ${namespace_collection}`
46471
+ });
46472
+ }).catch((err) => {
46473
+ import_nodejs_utils89.logger.log({
46474
+ level: "error",
46475
+ message: `Failed to clear cache namespace for ${namespace_collection}: ${err.message}`
46476
+ });
46477
+ });
46478
+ }
46479
+ async function add(value, session) {
46480
+ try {
46481
+ value = modelStrand(value);
46482
+ const res = await collection.insertOne(value, { session });
46483
+ delCachedData();
46484
+ return res.insertedId;
46485
+ } catch (error) {
46486
+ import_nodejs_utils89.logger.log({
46487
+ level: "error",
46488
+ message: error.message
46489
+ });
46490
+ if (error instanceof import_nodejs_utils89.AppError) {
46491
+ throw error;
46492
+ } else {
46493
+ const isDuplicated = error.message.includes("duplicate");
46494
+ if (isDuplicated) {
46495
+ throw new import_nodejs_utils89.BadRequestError("Strand already exists.");
46496
+ }
46497
+ throw new Error("Failed to create strand.");
46498
+ }
46499
+ }
46500
+ }
46501
+ async function getAll({
46502
+ search = "",
46503
+ page = 1,
46504
+ limit = 10,
46505
+ sort = {},
46506
+ status = "active",
46507
+ school = ""
46508
+ } = {}) {
46509
+ page = page > 0 ? page - 1 : 0;
46510
+ const query = {
46511
+ deletedAt: { $in: ["", null] },
46512
+ status
46513
+ };
46514
+ sort = Object.keys(sort).length > 0 ? sort : { _id: 1 };
46515
+ const cacheKeyOptions = {
46516
+ status,
46517
+ page,
46518
+ limit,
46519
+ sort: JSON.stringify(sort)
46520
+ };
46521
+ if (search) {
46522
+ query.$text = { $search: search };
46523
+ cacheKeyOptions.search = search;
46524
+ }
46525
+ if (school) {
46526
+ try {
46527
+ query.school = new import_mongodb51.ObjectId(school);
46528
+ } catch (error) {
46529
+ throw new import_nodejs_utils89.BadRequestError("Invalid school ID.");
46530
+ }
46531
+ cacheKeyOptions.school = school;
46532
+ }
46533
+ const cacheKey = (0, import_nodejs_utils89.makeCacheKey)(namespace_collection, cacheKeyOptions);
46534
+ import_nodejs_utils89.logger.log({
46535
+ level: "info",
46536
+ message: `Cache key for getAll strands: ${cacheKey}`
46537
+ });
46538
+ try {
46539
+ const cached = await getCache(cacheKey);
46540
+ if (cached) {
46541
+ import_nodejs_utils89.logger.log({
46542
+ level: "info",
46543
+ message: `Cache hit for getAll strands: ${cacheKey}`
46544
+ });
46545
+ return cached;
46546
+ }
46547
+ const items = await collection.aggregate([
46548
+ { $match: query },
46549
+ { $sort: sort },
46550
+ { $skip: page * limit },
46551
+ { $limit: limit }
46552
+ ]).toArray();
46553
+ const total = await collection.countDocuments(query);
46554
+ const result = (0, import_nodejs_utils89.paginate)(items, total, page, limit);
46555
+ setCache(cacheKey, result, 300).then(() => {
46556
+ import_nodejs_utils89.logger.log({
46557
+ level: "info",
46558
+ message: `Cache set for getAll strands: ${cacheKey}`
46559
+ });
46560
+ }).catch((err) => {
46561
+ import_nodejs_utils89.logger.log({
46562
+ level: "error",
46563
+ message: `Failed to set cache for getAll strands: ${err.message}`
46564
+ });
46565
+ });
46566
+ return result;
46567
+ } catch (error) {
46568
+ if (error instanceof import_nodejs_utils89.AppError) {
46569
+ throw error;
46570
+ } else {
46571
+ throw new import_nodejs_utils89.InternalServerError("Failed to get strands.");
46572
+ }
46573
+ }
46574
+ }
46575
+ async function getById(_id) {
46576
+ try {
46577
+ _id = new import_mongodb51.ObjectId(_id);
46578
+ } catch (error) {
46579
+ throw new import_nodejs_utils89.BadRequestError(namespace_collection + " Invalid ID.");
46580
+ }
46581
+ const cacheKey = (0, import_nodejs_utils89.makeCacheKey)(namespace_collection, {
46582
+ _id: _id.toString()
46583
+ });
46584
+ import_nodejs_utils89.logger.log({
46585
+ level: "info",
46586
+ message: `Cache key for getById strand: ${cacheKey}`
46587
+ });
46588
+ try {
46589
+ const cached = await getCache(cacheKey);
46590
+ if (cached) {
46591
+ import_nodejs_utils89.logger.log({
46592
+ level: "info",
46593
+ message: `Cache hit for getById strand: ${cacheKey}`
46594
+ });
46595
+ return cached;
46596
+ }
46597
+ const result = await collection.findOne({
46598
+ _id,
46599
+ deletedAt: { $in: ["", null] }
46600
+ });
46601
+ if (!result) {
46602
+ throw new import_nodejs_utils89.BadRequestError("strand not found.");
46603
+ }
46604
+ setCache(cacheKey, result, 300).then(() => {
46605
+ import_nodejs_utils89.logger.log({
46606
+ level: "info",
46607
+ message: `Cache set for getById strand: ${cacheKey}`
46608
+ });
46609
+ }).catch((err) => {
46610
+ import_nodejs_utils89.logger.log({
46611
+ level: "error",
46612
+ message: `Failed to set cache for getById strand: ${err.message}`
46613
+ });
46614
+ });
46615
+ return result;
46616
+ } catch (error) {
46617
+ if (error instanceof import_nodejs_utils89.AppError) {
46618
+ throw error;
46619
+ } else {
46620
+ throw new import_nodejs_utils89.InternalServerError("Failed to get strand.");
46621
+ }
46622
+ }
46623
+ }
46624
+ async function getBySchool(school) {
46625
+ try {
46626
+ school = new import_mongodb51.ObjectId(school);
46627
+ } catch (error) {
46628
+ throw new import_nodejs_utils89.BadRequestError("Invalid school ID.");
46629
+ }
46630
+ const cacheKey = (0, import_nodejs_utils89.makeCacheKey)(namespace_collection, {
46631
+ school: school.toString()
46632
+ });
46633
+ import_nodejs_utils89.logger.log({
46634
+ level: "info",
46635
+ message: `Cache key for strand by school: ${cacheKey}`
46636
+ });
46637
+ try {
46638
+ const cached = await getCache(cacheKey);
46639
+ if (cached) {
46640
+ import_nodejs_utils89.logger.log({
46641
+ level: "info",
46642
+ message: `Cache hit for strand by school: ${cacheKey}`
46643
+ });
46644
+ return cached;
46645
+ }
46646
+ const result = await collection.find({
46647
+ school,
46648
+ deletedAt: { $in: ["", null] }
46649
+ }).toArray();
46650
+ setCache(cacheKey, result, 300).then(() => {
46651
+ import_nodejs_utils89.logger.log({
46652
+ level: "info",
46653
+ message: `Cache set for strand by school: ${cacheKey}`
46654
+ });
46655
+ }).catch((err) => {
46656
+ import_nodejs_utils89.logger.log({
46657
+ level: "error",
46658
+ message: `Failed to set cache for strand by school: ${err.message}`
46659
+ });
46660
+ });
46661
+ return result;
46662
+ } catch (error) {
46663
+ if (error instanceof import_nodejs_utils89.AppError) {
46664
+ throw error;
46665
+ } else {
46666
+ throw new import_nodejs_utils89.InternalServerError("Failed to get strand.");
46667
+ }
46668
+ }
46669
+ }
46670
+ async function updateFieldById({ _id, field, value } = {}, session) {
46671
+ const allowedFields = ["title", "status"];
46672
+ if (!allowedFields.includes(field)) {
46673
+ throw new import_nodejs_utils89.BadRequestError(
46674
+ `Field "${field}" is not allowed to be updated.`
46675
+ );
46676
+ }
46677
+ try {
46678
+ _id = new import_mongodb51.ObjectId(_id);
46679
+ } catch (error) {
46680
+ throw new import_nodejs_utils89.BadRequestError(namespace_collection + " Invalid ID.");
46681
+ }
46682
+ try {
46683
+ await collection.updateOne(
46684
+ { _id, deletedAt: { $in: ["", null] } },
46685
+ { $set: { [field]: value, updatedAt: (/* @__PURE__ */ new Date()).toISOString() } },
46686
+ { session }
46687
+ );
46688
+ delCachedData();
46689
+ return `Successfully updated strand ${field}.`;
46690
+ } catch (error) {
46691
+ throw new import_nodejs_utils89.InternalServerError(`Failed to update strand ${field}.`);
46692
+ }
46693
+ }
46694
+ async function updateById(_id, value, session) {
46695
+ const { error } = schemaStrand.validate(value);
46696
+ if (error) {
46697
+ throw new import_nodejs_utils89.BadRequestError(`Invalid strand data: ${error.message}`);
46698
+ }
46699
+ try {
46700
+ _id = new import_mongodb51.ObjectId(_id);
46701
+ } catch (error2) {
46702
+ throw new import_nodejs_utils89.BadRequestError(namespace_collection + " Invalid ID.");
46703
+ }
46704
+ try {
46705
+ await collection.updateOne(
46706
+ { _id },
46707
+ { $set: { ...value, updatedAt: (/* @__PURE__ */ new Date()).toISOString() } },
46708
+ { session }
46709
+ );
46710
+ delCachedData();
46711
+ return `Successfully updated strand.`;
46712
+ } catch (error2) {
46713
+ throw new import_nodejs_utils89.InternalServerError("Failed to update strand.");
46714
+ }
46715
+ }
46716
+ async function deleteById(_id, session) {
46717
+ try {
46718
+ _id = new import_mongodb51.ObjectId(_id);
46719
+ } catch (error) {
46720
+ throw new import_nodejs_utils89.BadRequestError(namespace_collection + " Invalid ID.");
46721
+ }
46722
+ try {
46723
+ await collection.updateOne(
46724
+ { _id },
46725
+ { $set: { status: "deleted", deletedAt: (/* @__PURE__ */ new Date()).toISOString() } },
46726
+ { session }
46727
+ );
46728
+ delCachedData();
46729
+ return "Successfully deleted strand.";
46730
+ } catch (error) {
46731
+ throw new import_nodejs_utils89.InternalServerError("Failed to delete strand.");
46732
+ }
46733
+ }
46734
+ async function countByTrack(track) {
46735
+ const query = { status: { $ne: "deleted" } };
46736
+ const cacheKeyOptions = { tag: "countByTrack" };
46737
+ try {
46738
+ query.track = new import_mongodb51.ObjectId(track);
46739
+ cacheKeyOptions.track = track;
46740
+ } catch (error) {
46741
+ throw new import_nodejs_utils89.BadRequestError("Invalid track ID.");
46742
+ }
46743
+ const cacheKey = (0, import_nodejs_utils89.makeCacheKey)(namespace_collection, cacheKeyOptions);
46744
+ try {
46745
+ const cached = await getCache(cacheKey);
46746
+ if (cached) {
46747
+ import_nodejs_utils89.logger.log({
46748
+ level: "info",
46749
+ message: `Cache hit for getById strand: ${cacheKey}`
46750
+ });
46751
+ return cached;
46752
+ }
46753
+ const result = await collection.countDocuments(query);
46754
+ setCache(cacheKey, result, 300).then(() => {
46755
+ import_nodejs_utils89.logger.log({
46756
+ level: "info",
46757
+ message: `Cache set for strand by id: ${cacheKey}`
46758
+ });
46759
+ }).catch((err) => {
46760
+ import_nodejs_utils89.logger.log({
46761
+ level: "error",
46762
+ message: `Failed to set cache for strand by id: ${err.message}`
46763
+ });
46764
+ });
46765
+ return result;
46766
+ } catch (error) {
46767
+ if (error instanceof import_nodejs_utils89.AppError) {
46768
+ throw error;
46769
+ } else {
46770
+ throw new import_nodejs_utils89.InternalServerError("Failed to get strand.");
46771
+ }
46772
+ }
46773
+ }
46774
+ return {
46775
+ createIndexes,
46776
+ add,
46777
+ getAll,
46778
+ getById,
46779
+ getBySchool,
46780
+ updateFieldById,
46781
+ updateById,
46782
+ deleteById,
46783
+ countByTrack
46784
+ };
46785
+ }
46786
+
46787
+ // src/resources/track/track.service.ts
46788
+ function useTrackService() {
46789
+ const { add: _add, deleteById: _deleteById, getById } = useTrackRepo();
46790
+ const { countByTrack } = useStrandRepo();
46791
+ async function deleteById(id) {
46792
+ const session = import_nodejs_utils90.useAtlas.getClient()?.startSession();
46793
+ if (!session) {
46794
+ throw new Error("Failed to start database session.");
46795
+ }
46796
+ try {
46797
+ session.startTransaction();
46798
+ const track = await getById(id);
46799
+ if (!track) {
46800
+ throw new import_nodejs_utils90.BadRequestError("track not found.");
46801
+ }
46802
+ const usageCount = await countByTrack(id);
46803
+ if (usageCount > 0) {
46804
+ throw new import_nodejs_utils90.BadRequestError(
46805
+ "Cannot delete track as it is currently in use."
46806
+ );
46807
+ }
46808
+ const message = await _deleteById(id, session);
46809
+ await session.commitTransaction();
46810
+ return message;
46811
+ } catch (error) {
46812
+ await session.abortTransaction();
46813
+ if (error instanceof import_nodejs_utils90.AppError) {
46814
+ throw error;
46815
+ } else {
46816
+ throw new import_nodejs_utils90.AppError("Failed to delete track.", 500);
46817
+ }
46818
+ } finally {
46819
+ await session.endSession();
46820
+ }
46821
+ }
46822
+ return {
46823
+ deleteById
46824
+ };
46825
+ }
46826
+
46827
+ // src/resources/track/track.controller.ts
46828
+ var import_nodejs_utils91 = require("@eeplatform/nodejs-utils");
46829
+ var import_joi54 = __toESM(require("joi"));
46830
+ function useTrackController() {
46831
+ const {
46832
+ add: _add,
46833
+ getAll: _getAll,
46834
+ getById: _getById,
46835
+ getBySchool: _getBySchool,
46836
+ updateFieldById: _updateFieldById
46837
+ } = useTrackRepo();
46838
+ async function add(req, res, next) {
46839
+ const value = req.body;
46840
+ const { error } = schemaTrack.validate(value);
46841
+ if (error) {
46842
+ next(new import_nodejs_utils91.BadRequestError(error.message));
46843
+ return;
46844
+ }
46845
+ try {
46846
+ const data = await _add(value);
46847
+ res.json({
46848
+ message: "Successfully created track.",
46849
+ data
46850
+ });
46851
+ return;
46852
+ } catch (error2) {
46853
+ next(error2);
46854
+ }
46855
+ }
46856
+ async function getAll(req, res, next) {
46857
+ const query = req.query;
46858
+ const validation = import_joi54.default.object({
46859
+ page: import_joi54.default.number().min(1).optional().allow("", null),
46860
+ limit: import_joi54.default.number().min(1).optional().allow("", null),
46861
+ search: import_joi54.default.string().optional().allow("", null),
46862
+ status: import_joi54.default.string().optional().allow("", null),
46863
+ school: import_joi54.default.string().hex().optional().allow("", null)
46864
+ });
46865
+ const { error } = validation.validate(query);
46866
+ const page = typeof req.query.page === "string" ? Number(req.query.page) : 1;
46867
+ const limit = typeof req.query.limit === "string" ? Number(req.query.limit) : 10;
46868
+ const search = req.query.search ?? "";
46869
+ const status = req.query.status ?? "active";
46870
+ const school = req.query.school ?? "";
46871
+ const isPageNumber = isFinite(page);
46872
+ if (!isPageNumber) {
46873
+ next(new import_nodejs_utils91.BadRequestError("Invalid page number."));
46874
+ return;
46875
+ }
46876
+ const isLimitNumber = isFinite(limit);
46877
+ if (!isLimitNumber) {
46878
+ next(new import_nodejs_utils91.BadRequestError("Invalid limit number."));
46879
+ return;
46880
+ }
46881
+ if (error) {
46882
+ next(new import_nodejs_utils91.BadRequestError(error.message));
46883
+ return;
46884
+ }
46885
+ try {
46886
+ const data = await _getAll({
46887
+ page,
46888
+ limit,
46889
+ search,
46890
+ status,
46891
+ school
46892
+ });
46893
+ res.json(data);
46894
+ return;
46895
+ } catch (error2) {
46896
+ next(error2);
46897
+ }
46898
+ }
46899
+ async function getById(req, res, next) {
46900
+ const id = req.params.id;
46901
+ const validation = import_joi54.default.object({
46902
+ id: import_joi54.default.string().hex().required()
46903
+ });
46904
+ const { error } = validation.validate({ id });
46905
+ if (error) {
46906
+ next(new import_nodejs_utils91.BadRequestError(error.message));
46907
+ return;
46908
+ }
46909
+ try {
46910
+ const data = await _getById(id);
46911
+ res.json({
46912
+ message: "Successfully retrieved kindergarten domain.",
46913
+ data
46914
+ });
46915
+ return;
46916
+ } catch (error2) {
46917
+ next(error2);
46918
+ }
46919
+ }
46920
+ async function getBySchool(req, res, next) {
46921
+ const school = req.params.school;
46922
+ const validation = import_joi54.default.object({
46923
+ school: import_joi54.default.string().hex().required()
46924
+ });
46925
+ const { error } = validation.validate({ school });
46926
+ if (error) {
46927
+ next(new import_nodejs_utils91.BadRequestError(error.message));
46928
+ return;
46929
+ }
46930
+ try {
46931
+ const data = await _getBySchool(school);
46932
+ res.json({
46933
+ message: "Successfully retrieved kindergarten domains.",
46934
+ data
46935
+ });
46936
+ return;
46937
+ } catch (error2) {
46938
+ next(error2);
46939
+ }
46940
+ }
46941
+ async function updateField(req, res, next) {
46942
+ const _id = req.params.id;
46943
+ const { field, value } = req.body;
46944
+ const validation = import_joi54.default.object({
46945
+ _id: import_joi54.default.string().hex().required(),
46946
+ field: import_joi54.default.string().valid("name").required(),
46947
+ value: import_joi54.default.alternatives().try(import_joi54.default.string(), import_joi54.default.array(), import_joi54.default.object()).required()
46948
+ });
46949
+ const { error } = validation.validate({ _id, field, value });
46950
+ if (error) {
46951
+ next(new import_nodejs_utils91.BadRequestError(error.message));
46952
+ return;
46953
+ }
46954
+ try {
46955
+ const message = await _updateFieldById({ _id, field, value });
46956
+ res.json({ message });
46957
+ return;
46958
+ } catch (error2) {
46959
+ next(error2);
46960
+ }
46961
+ }
46962
+ const { deleteById: _deleteById } = useTrackService();
46963
+ async function deleteById(req, res, next) {
46964
+ const id = req.params.id;
46965
+ const validation = import_joi54.default.object({
46966
+ id: import_joi54.default.string().hex().required()
46967
+ });
46968
+ const { error } = validation.validate({ id });
46969
+ if (error) {
46970
+ next(new import_nodejs_utils91.BadRequestError(error.message));
46971
+ return;
46972
+ }
46973
+ try {
46974
+ const message = await _deleteById(id);
46975
+ res.json({ message });
46976
+ return;
46977
+ } catch (error2) {
46978
+ next(error2);
46979
+ }
46980
+ }
46981
+ return {
46982
+ add,
46983
+ getAll,
46984
+ getById,
46985
+ getBySchool,
46986
+ updateField,
46987
+ deleteById
46988
+ };
46989
+ }
46990
+
46991
+ // src/resources/strand/strand.controller.ts
46992
+ var import_nodejs_utils92 = require("@eeplatform/nodejs-utils");
46993
+ var import_joi55 = __toESM(require("joi"));
46994
+ function useStrandController() {
46995
+ const {
46996
+ add: _add,
46997
+ getAll: _getAll,
46998
+ getById: _getById,
46999
+ getBySchool: _getBySchool,
47000
+ updateFieldById: _updateFieldById,
47001
+ deleteById: _deleteById
47002
+ } = useStrandRepo();
47003
+ async function add(req, res, next) {
47004
+ const value = req.body;
47005
+ const { error } = schemaStrand.validate(value);
47006
+ if (error) {
47007
+ next(new import_nodejs_utils92.BadRequestError(error.message));
47008
+ return;
47009
+ }
47010
+ try {
47011
+ const data = await _add(value);
47012
+ res.json({
47013
+ message: "Successfully created kindergarten domain.",
47014
+ data
47015
+ });
47016
+ return;
47017
+ } catch (error2) {
47018
+ next(error2);
47019
+ }
47020
+ }
47021
+ async function getAll(req, res, next) {
47022
+ const query = req.query;
47023
+ const validation = import_joi55.default.object({
47024
+ page: import_joi55.default.number().min(1).optional().allow("", null),
47025
+ limit: import_joi55.default.number().min(1).optional().allow("", null),
47026
+ search: import_joi55.default.string().optional().allow("", null),
47027
+ status: import_joi55.default.string().optional().allow("", null),
47028
+ school: import_joi55.default.string().hex().optional().allow("", null)
47029
+ });
47030
+ const { error } = validation.validate(query);
47031
+ const page = typeof req.query.page === "string" ? Number(req.query.page) : 1;
47032
+ const limit = typeof req.query.limit === "string" ? Number(req.query.limit) : 10;
47033
+ const search = req.query.search ?? "";
47034
+ const status = req.query.status ?? "active";
47035
+ const school = req.query.school ?? "";
47036
+ const isPageNumber = isFinite(page);
47037
+ if (!isPageNumber) {
47038
+ next(new import_nodejs_utils92.BadRequestError("Invalid page number."));
47039
+ return;
47040
+ }
47041
+ const isLimitNumber = isFinite(limit);
47042
+ if (!isLimitNumber) {
47043
+ next(new import_nodejs_utils92.BadRequestError("Invalid limit number."));
47044
+ return;
47045
+ }
47046
+ if (error) {
47047
+ next(new import_nodejs_utils92.BadRequestError(error.message));
47048
+ return;
47049
+ }
47050
+ try {
47051
+ const data = await _getAll({
47052
+ page,
47053
+ limit,
47054
+ search,
47055
+ status,
47056
+ school
47057
+ });
47058
+ res.json(data);
47059
+ return;
47060
+ } catch (error2) {
47061
+ next(error2);
47062
+ }
47063
+ }
47064
+ async function getById(req, res, next) {
47065
+ const id = req.params.id;
47066
+ const validation = import_joi55.default.object({
47067
+ id: import_joi55.default.string().hex().required()
47068
+ });
47069
+ const { error } = validation.validate({ id });
47070
+ if (error) {
47071
+ next(new import_nodejs_utils92.BadRequestError(error.message));
47072
+ return;
47073
+ }
47074
+ try {
47075
+ const data = await _getById(id);
47076
+ res.json({
47077
+ message: "Successfully retrieved kindergarten domain.",
47078
+ data
47079
+ });
47080
+ return;
47081
+ } catch (error2) {
47082
+ next(error2);
47083
+ }
47084
+ }
47085
+ async function getBySchool(req, res, next) {
47086
+ const school = req.params.school;
47087
+ const validation = import_joi55.default.object({
47088
+ school: import_joi55.default.string().hex().required()
47089
+ });
47090
+ const { error } = validation.validate({ school });
47091
+ if (error) {
47092
+ next(new import_nodejs_utils92.BadRequestError(error.message));
47093
+ return;
47094
+ }
47095
+ try {
47096
+ const data = await _getBySchool(school);
47097
+ res.json({
47098
+ message: "Successfully retrieved strand.",
47099
+ data
47100
+ });
47101
+ return;
47102
+ } catch (error2) {
47103
+ next(error2);
47104
+ }
47105
+ }
47106
+ async function updateField(req, res, next) {
47107
+ const _id = req.params.id;
47108
+ const { field, value } = req.body;
47109
+ const validation = import_joi55.default.object({
47110
+ _id: import_joi55.default.string().hex().required(),
47111
+ field: import_joi55.default.string().valid("title", "status").required(),
47112
+ value: import_joi55.default.alternatives().try(import_joi55.default.string(), import_joi55.default.array(), import_joi55.default.object()).required()
47113
+ });
47114
+ const { error } = validation.validate({ _id, field, value });
47115
+ if (error) {
47116
+ next(new import_nodejs_utils92.BadRequestError(error.message));
47117
+ return;
47118
+ }
47119
+ try {
47120
+ const message = await _updateFieldById({ _id, field, value });
47121
+ res.json({ message });
47122
+ return;
47123
+ } catch (error2) {
47124
+ next(error2);
47125
+ }
47126
+ }
47127
+ async function deleteById(req, res, next) {
47128
+ const _id = req.params.id;
47129
+ const validation = import_joi55.default.object({
47130
+ _id: import_joi55.default.string().hex().required()
47131
+ });
47132
+ const { error } = validation.validate({ _id });
47133
+ if (error) {
47134
+ next(new import_nodejs_utils92.BadRequestError(error.message));
47135
+ return;
47136
+ }
47137
+ try {
47138
+ const message = await _deleteById(_id);
47139
+ res.json({ message });
47140
+ return;
47141
+ } catch (error2) {
47142
+ next(error2);
47143
+ }
47144
+ }
47145
+ return {
47146
+ add,
47147
+ getAll,
47148
+ getById,
47149
+ getBySchool,
47150
+ updateField,
47151
+ deleteById
47152
+ };
47153
+ }
47154
+
46050
47155
  // src/config.ts
46051
47156
  var dotenv = __toESM(require("dotenv"));
46052
47157
  dotenv.config();
@@ -46074,9 +47179,11 @@ dotenv.config();
46074
47179
  modelSectionPreset,
46075
47180
  modelSectionStudent,
46076
47181
  modelSectionSubject,
47182
+ modelStrand,
46077
47183
  modelSubject,
46078
47184
  modelTeachingLoad,
46079
47185
  modelTeachingLoadSlot,
47186
+ modelTrack,
46080
47187
  schemaAsset,
46081
47188
  schemaAssetUpdateOption,
46082
47189
  schemaBasicEduCount,
@@ -46106,10 +47213,12 @@ dotenv.config();
46106
47213
  schemaSectionSubject,
46107
47214
  schemaSectionSubjectSetup,
46108
47215
  schemaStockCard,
47216
+ schemaStrand,
46109
47217
  schemaSubject,
46110
47218
  schemaSubjectAdd,
46111
47219
  schemaTeachingLoad,
46112
47220
  schemaTeachingLoadSlot,
47221
+ schemaTrack,
46113
47222
  schemaUpdateOptions,
46114
47223
  schemaUpdateStatus,
46115
47224
  statusesProgramScreening,
@@ -46165,13 +47274,18 @@ dotenv.config();
46165
47274
  useStockCardController,
46166
47275
  useStockCardRepository,
46167
47276
  useStockCardService,
47277
+ useStrandController,
47278
+ useStrandRepo,
46168
47279
  useSubjectController,
46169
47280
  useSubjectRepo,
46170
47281
  useSubjectService,
46171
47282
  useTeachingLoadController,
46172
47283
  useTeachingLoadRepo,
46173
47284
  useTeachingLoadSlotController,
46174
- useTeachingLoadSlotRepo
47285
+ useTeachingLoadSlotRepo,
47286
+ useTrackController,
47287
+ useTrackRepo,
47288
+ useTrackService
46175
47289
  });
46176
47290
  /*! Bundled license information:
46177
47291