@eeplatform/basic-edu 1.9.3 → 1.10.0

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
@@ -1355,6 +1355,8 @@ __export(src_exports, {
1355
1355
  allowedSectionStudentStatuses: () => allowedSectionStudentStatuses,
1356
1356
  modelBasicEduCount: () => modelBasicEduCount,
1357
1357
  modelDivision: () => modelDivision,
1358
+ modelKindergartenDomain: () => modelKindergartenDomain,
1359
+ modelKindergartenRoutine: () => modelKindergartenRoutine,
1358
1360
  modelProgram: () => modelProgram,
1359
1361
  modelProgramScreening: () => modelProgramScreening,
1360
1362
  modelRegion: () => modelRegion,
@@ -1377,6 +1379,9 @@ __export(src_exports, {
1377
1379
  schemaEnrollment: () => schemaEnrollment,
1378
1380
  schemaGenerateSections: () => schemaGenerateSections,
1379
1381
  schemaGradeLevel: () => schemaGradeLevel,
1382
+ schemaKindergartenDomain: () => schemaKindergartenDomain,
1383
+ schemaKindergartenRoutine: () => schemaKindergartenRoutine,
1384
+ schemaKindergartenRoutineUpdate: () => schemaKindergartenRoutineUpdate,
1380
1385
  schemaPersonnel: () => schemaPersonnel,
1381
1386
  schemaPlantilla: () => schemaPlantilla,
1382
1387
  schemaProgram: () => schemaProgram,
@@ -1418,6 +1423,11 @@ __export(src_exports, {
1418
1423
  useEnrollmentService: () => useEnrollmentService,
1419
1424
  useGradeLevelController: () => useGradeLevelController,
1420
1425
  useGradeLevelRepo: () => useGradeLevelRepo,
1426
+ useKindergartenDomainController: () => useKindergartenDomainController,
1427
+ useKindergartenDomainRepo: () => useKindergartenDomainRepo,
1428
+ useKindergartenDomainService: () => useKindergartenDomainService,
1429
+ useKindergartenRoutineController: () => useKindergartenRoutineController,
1430
+ useKindergartenRoutineRepo: () => useKindergartenRoutineRepo,
1421
1431
  useLearnerController: () => useLearnerController,
1422
1432
  useLearnerRepo: () => useLearnerRepo,
1423
1433
  usePersonnelController: () => usePersonnelController,
@@ -39772,11 +39782,11 @@ function useSectionRepo() {
39772
39782
  }
39773
39783
 
39774
39784
  // src/resources/section/section.controller.ts
39775
- var import_nodejs_utils70 = require("@eeplatform/nodejs-utils");
39776
- var import_joi43 = __toESM(require("joi"));
39785
+ var import_nodejs_utils73 = require("@eeplatform/nodejs-utils");
39786
+ var import_joi45 = __toESM(require("joi"));
39777
39787
 
39778
39788
  // src/resources/section/section.service.ts
39779
- var import_nodejs_utils69 = require("@eeplatform/nodejs-utils");
39789
+ var import_nodejs_utils72 = require("@eeplatform/nodejs-utils");
39780
39790
 
39781
39791
  // src/resources/section-student/section.student.repository.ts
39782
39792
  var import_nodejs_utils54 = require("@eeplatform/nodejs-utils");
@@ -41483,9 +41493,11 @@ var schemaTeachingLoadSlot = import_joi39.default.object({
41483
41493
  gradeLevel: import_joi39.default.string().required(),
41484
41494
  startTime: import_joi39.default.string().required(),
41485
41495
  endTime: import_joi39.default.string().required(),
41486
- subject: import_joi39.default.string().hex().required(),
41496
+ subject: import_joi39.default.string().hex().optional().allow("", null),
41487
41497
  subjectName: import_joi39.default.string().optional().allow("", null),
41488
41498
  subjectCode: import_joi39.default.string().optional().allow("", null),
41499
+ routine: import_joi39.default.string().hex().optional().allow("", null),
41500
+ routineName: import_joi39.default.string().optional().allow("", null),
41489
41501
  section: import_joi39.default.string().hex().required(),
41490
41502
  sectionName: import_joi39.default.string().optional().allow("", null),
41491
41503
  duration: import_joi39.default.number().min(0).required(),
@@ -41521,6 +41533,13 @@ function modelTeachingLoadSlot(value) {
41521
41533
  throw new import_nodejs_utils62.BadRequestError("Invalid subject format");
41522
41534
  }
41523
41535
  }
41536
+ if (value.routine && typeof value.routine === "string") {
41537
+ try {
41538
+ value.routine = new import_mongodb37.ObjectId(value.routine);
41539
+ } catch (error2) {
41540
+ throw new import_nodejs_utils62.BadRequestError("Invalid routine format");
41541
+ }
41542
+ }
41524
41543
  if (value.section && typeof value.section === "string") {
41525
41544
  try {
41526
41545
  value.section = new import_mongodb37.ObjectId(value.section);
@@ -41538,9 +41557,11 @@ function modelTeachingLoadSlot(value) {
41538
41557
  gradeLevel: value.gradeLevel ?? "",
41539
41558
  startTime: value.startTime ?? "",
41540
41559
  endTime: value.endTime ?? "",
41541
- subject: value.subject,
41560
+ subject: value.subject ?? "",
41542
41561
  subjectName: value.subjectName ?? "",
41543
41562
  subjectCode: value.subjectCode ?? "",
41563
+ routine: value.routine ?? "",
41564
+ routineName: value.routineName ?? "",
41544
41565
  section: value.section,
41545
41566
  sectionName: value.sectionName ?? "",
41546
41567
  duration: value.duration ?? 0,
@@ -42694,6 +42715,678 @@ function usePersonnelController() {
42694
42715
  };
42695
42716
  }
42696
42717
 
42718
+ // src/resources/kindergarten-routine/kindergarten.routine.model.ts
42719
+ var import_nodejs_utils69 = require("@eeplatform/nodejs-utils");
42720
+ var import_joi43 = __toESM(require("joi"));
42721
+ var import_mongodb41 = require("mongodb");
42722
+ var schemaKindergartenRoutine = import_joi43.default.object({
42723
+ _id: import_joi43.default.string().hex().optional().allow(null, ""),
42724
+ title: import_joi43.default.string().max(100).required(),
42725
+ section: import_joi43.default.string().hex().optional().allow(null, ""),
42726
+ sectionName: import_joi43.default.string().max(100).optional().allow(null, ""),
42727
+ classroom: import_joi43.default.string().hex().optional().allow(null, ""),
42728
+ classroomName: import_joi43.default.string().max(100).optional().allow(null, ""),
42729
+ schedule: import_joi43.default.array().items(import_joi43.default.string()).required(),
42730
+ blockTimes: import_joi43.default.array().items(
42731
+ import_joi43.default.object({
42732
+ title: import_joi43.default.string().required(),
42733
+ startTime: import_joi43.default.string().required(),
42734
+ endTime: import_joi43.default.string().required(),
42735
+ durationMinutes: import_joi43.default.number().required(),
42736
+ domains: import_joi43.default.array().items(import_joi43.default.string()).optional()
42737
+ })
42738
+ ).required(),
42739
+ type: import_joi43.default.string().required(),
42740
+ durationMinutes: import_joi43.default.number().optional().allow(null, 0),
42741
+ school: import_joi43.default.string().hex().required(),
42742
+ createdAt: import_joi43.default.string().isoDate().optional().allow(null, ""),
42743
+ updatedAt: import_joi43.default.string().isoDate().optional().allow(null, ""),
42744
+ deletedAt: import_joi43.default.string().isoDate().optional().allow(null, "")
42745
+ });
42746
+ var schemaKindergartenRoutineUpdate = import_joi43.default.object({
42747
+ title: import_joi43.default.string().max(100).optional().allow(null, ""),
42748
+ section: import_joi43.default.string().hex().optional().allow(null, ""),
42749
+ sectionName: import_joi43.default.string().max(100).optional().allow(null, ""),
42750
+ classroom: import_joi43.default.string().hex().optional().allow(null, ""),
42751
+ classroomName: import_joi43.default.string().max(100).optional().allow(null, ""),
42752
+ schedule: import_joi43.default.array().items(import_joi43.default.string()).optional().allow(null, ""),
42753
+ blockTimes: import_joi43.default.array().items(
42754
+ import_joi43.default.object({
42755
+ title: import_joi43.default.string().required(),
42756
+ startTime: import_joi43.default.string().required(),
42757
+ endTime: import_joi43.default.string().required(),
42758
+ durationMinutes: import_joi43.default.number().required(),
42759
+ domains: import_joi43.default.array().items(import_joi43.default.string()).optional()
42760
+ })
42761
+ ).optional(),
42762
+ durationMinutes: import_joi43.default.number().optional().allow(null, 0)
42763
+ });
42764
+ function modelKindergartenRoutine(value) {
42765
+ const { error } = schemaKindergartenRoutine.validate(value);
42766
+ if (error) {
42767
+ throw new import_nodejs_utils69.BadRequestError(`Invalid kinder schedule data: ${error.message}`);
42768
+ }
42769
+ if (value._id && typeof value._id === "string") {
42770
+ try {
42771
+ value._id = new import_mongodb41.ObjectId(value._id);
42772
+ } catch (error2) {
42773
+ throw new Error("Invalid _id.");
42774
+ }
42775
+ }
42776
+ if (value.school && typeof value.school === "string") {
42777
+ try {
42778
+ value.school = new import_mongodb41.ObjectId(value.school);
42779
+ } catch (error2) {
42780
+ throw new Error("Invalid school.");
42781
+ }
42782
+ }
42783
+ if (value.section && typeof value.section === "string") {
42784
+ try {
42785
+ value.section = new import_mongodb41.ObjectId(value.section);
42786
+ } catch (error2) {
42787
+ throw new Error("Invalid section.");
42788
+ }
42789
+ }
42790
+ if (value.classroom && typeof value.classroom === "string") {
42791
+ try {
42792
+ value.classroom = new import_mongodb41.ObjectId(value.classroom);
42793
+ } catch (error2) {
42794
+ throw new Error("Invalid classroom.");
42795
+ }
42796
+ }
42797
+ return {
42798
+ _id: value._id,
42799
+ title: value.title,
42800
+ section: value.section,
42801
+ sectionName: value.sectionName ?? "",
42802
+ classroom: value.classroom,
42803
+ classroomName: value.classroomName ?? "",
42804
+ schedule: value.schedule,
42805
+ blockTimes: value.blockTimes,
42806
+ type: value.type,
42807
+ durationMinutes: value.durationMinutes ?? 0,
42808
+ status: value.status ?? "active",
42809
+ school: value.school,
42810
+ createdAt: value.createdAt ?? (/* @__PURE__ */ new Date()).toISOString(),
42811
+ updatedAt: value.updatedAt ?? "",
42812
+ deletedAt: value.deletedAt ?? ""
42813
+ };
42814
+ }
42815
+
42816
+ // src/resources/kindergarten-routine/kindergarten.routine.repository.ts
42817
+ var import_nodejs_utils70 = require("@eeplatform/nodejs-utils");
42818
+ var import_mongodb42 = require("mongodb");
42819
+ function useKindergartenRoutineRepo() {
42820
+ const db = import_nodejs_utils70.useAtlas.getDb();
42821
+ if (!db) {
42822
+ throw new Error("Unable to connect to server.");
42823
+ }
42824
+ const namespace_collection = "deped.kindergarten.routines";
42825
+ const collection = db.collection(namespace_collection);
42826
+ const { getCache, setCache, delNamespace } = (0, import_nodejs_utils70.useCache)(namespace_collection);
42827
+ async function createIndexes() {
42828
+ try {
42829
+ await collection.createIndexes([
42830
+ { key: { section: 1 } },
42831
+ { key: { classroom: 1 } },
42832
+ { key: { schedule: 1 } },
42833
+ { key: { type: 1 } },
42834
+ { key: { createdAt: 1 } },
42835
+ { key: { createdBy: 1 } },
42836
+ { key: { sectionName: "text", classroomName: "text" } },
42837
+ {
42838
+ key: { title: 1, school: 1, type: 1, status: 1 },
42839
+ unique: true,
42840
+ name: "unique_kindergarten_routine"
42841
+ }
42842
+ ]);
42843
+ } catch (error) {
42844
+ throw new Error("Failed to create index on kindergarten routines.");
42845
+ }
42846
+ }
42847
+ function delCachedData() {
42848
+ delNamespace().then(() => {
42849
+ import_nodejs_utils70.logger.log({
42850
+ level: "info",
42851
+ message: `Cache namespace cleared for ${namespace_collection}`
42852
+ });
42853
+ }).catch((err) => {
42854
+ import_nodejs_utils70.logger.log({
42855
+ level: "error",
42856
+ message: `Failed to clear cache namespace for ${namespace_collection}: ${err.message}`
42857
+ });
42858
+ });
42859
+ }
42860
+ async function add(value, session) {
42861
+ try {
42862
+ value = modelKindergartenRoutine(value);
42863
+ const res = await collection.insertOne(value, { session });
42864
+ delCachedData();
42865
+ return res.insertedId;
42866
+ } catch (error) {
42867
+ import_nodejs_utils70.logger.log({
42868
+ level: "error",
42869
+ message: error.message
42870
+ });
42871
+ if (error instanceof import_nodejs_utils70.AppError) {
42872
+ throw error;
42873
+ } else {
42874
+ const isDuplicated = error.message.includes("duplicate");
42875
+ if (isDuplicated) {
42876
+ throw new import_nodejs_utils70.BadRequestError("Kinder schedule already exists.");
42877
+ }
42878
+ throw new Error("Failed to create kindergarten routine.");
42879
+ }
42880
+ }
42881
+ }
42882
+ async function getAll({
42883
+ search = "",
42884
+ page = 1,
42885
+ limit = 10,
42886
+ sort = {},
42887
+ status = "active",
42888
+ createdBy,
42889
+ school = "",
42890
+ section = "",
42891
+ classroom = "",
42892
+ type = ""
42893
+ } = {}) {
42894
+ page = page > 0 ? page - 1 : 0;
42895
+ const query = {
42896
+ deletedAt: { $in: ["", null] },
42897
+ status
42898
+ };
42899
+ sort = Object.keys(sort).length > 0 ? sort : { _id: 1 };
42900
+ const cacheKeyOptions = {
42901
+ status,
42902
+ page,
42903
+ limit,
42904
+ sort: JSON.stringify(sort)
42905
+ };
42906
+ if (createdBy) {
42907
+ try {
42908
+ query.createdBy = new import_mongodb42.ObjectId(createdBy);
42909
+ } catch (error) {
42910
+ throw new import_nodejs_utils70.BadRequestError("Invalid createdBy ID.");
42911
+ }
42912
+ cacheKeyOptions.createdBy = createdBy;
42913
+ }
42914
+ if (search) {
42915
+ query.$text = { $search: search };
42916
+ cacheKeyOptions.search = search;
42917
+ }
42918
+ if (school) {
42919
+ try {
42920
+ query.school = new import_mongodb42.ObjectId(school);
42921
+ } catch (error) {
42922
+ throw new import_nodejs_utils70.BadRequestError("Invalid school ID.");
42923
+ }
42924
+ cacheKeyOptions.school = school;
42925
+ }
42926
+ if (section) {
42927
+ try {
42928
+ query.section = new import_mongodb42.ObjectId(section);
42929
+ } catch (error) {
42930
+ throw new import_nodejs_utils70.BadRequestError("Invalid section ID.");
42931
+ }
42932
+ cacheKeyOptions.section = section;
42933
+ }
42934
+ if (classroom) {
42935
+ try {
42936
+ query.classroom = new import_mongodb42.ObjectId(classroom);
42937
+ } catch (error) {
42938
+ throw new import_nodejs_utils70.BadRequestError("Invalid classroom ID.");
42939
+ }
42940
+ cacheKeyOptions.classroom = classroom;
42941
+ }
42942
+ if (type) {
42943
+ query.type = type;
42944
+ cacheKeyOptions.type = type;
42945
+ }
42946
+ const cacheKey = (0, import_nodejs_utils70.makeCacheKey)(namespace_collection, cacheKeyOptions);
42947
+ import_nodejs_utils70.logger.log({
42948
+ level: "info",
42949
+ message: `Cache key for getAll kindergarten routines: ${cacheKey}`
42950
+ });
42951
+ try {
42952
+ const cached = await getCache(cacheKey);
42953
+ if (cached) {
42954
+ import_nodejs_utils70.logger.log({
42955
+ level: "info",
42956
+ message: `Cache hit for getAll kindergarten routines: ${cacheKey}`
42957
+ });
42958
+ return cached;
42959
+ }
42960
+ const items = await collection.aggregate([
42961
+ { $match: query },
42962
+ { $sort: sort },
42963
+ { $skip: page * limit },
42964
+ { $limit: limit }
42965
+ ]).toArray();
42966
+ const length = await collection.countDocuments(query);
42967
+ const data = (0, import_nodejs_utils70.paginate)(items, page, limit, length);
42968
+ setCache(cacheKey, data, 600).then(() => {
42969
+ import_nodejs_utils70.logger.log({
42970
+ level: "info",
42971
+ message: `Cache set for getAll kindergarten routines: ${cacheKey}`
42972
+ });
42973
+ }).catch((err) => {
42974
+ import_nodejs_utils70.logger.log({
42975
+ level: "error",
42976
+ message: `Failed to set cache for getAll kindergarten routines: ${err.message}`
42977
+ });
42978
+ });
42979
+ return data;
42980
+ } catch (error) {
42981
+ import_nodejs_utils70.logger.log({ level: "error", message: `${error}` });
42982
+ throw error;
42983
+ }
42984
+ }
42985
+ async function getById(_id) {
42986
+ try {
42987
+ _id = new import_mongodb42.ObjectId(_id);
42988
+ } catch (error) {
42989
+ throw new import_nodejs_utils70.BadRequestError(namespace_collection + " Invalid ID.");
42990
+ }
42991
+ const cacheKey = (0, import_nodejs_utils70.makeCacheKey)(namespace_collection, { _id: String(_id) });
42992
+ try {
42993
+ const cached = await getCache(cacheKey);
42994
+ if (cached) {
42995
+ import_nodejs_utils70.logger.log({
42996
+ level: "info",
42997
+ message: `Cache hit for getById kindergarten routine: ${cacheKey}`
42998
+ });
42999
+ return cached;
43000
+ }
43001
+ const result = await collection.findOne({
43002
+ _id,
43003
+ deletedAt: { $in: ["", null] }
43004
+ });
43005
+ setCache(cacheKey, result, 300).then(() => {
43006
+ import_nodejs_utils70.logger.log({
43007
+ level: "info",
43008
+ message: `Cache set for kindergarten routine by id: ${cacheKey}`
43009
+ });
43010
+ }).catch((err) => {
43011
+ import_nodejs_utils70.logger.log({
43012
+ level: "error",
43013
+ message: `Failed to set cache for kindergarten routine by id: ${err.message}`
43014
+ });
43015
+ });
43016
+ return result;
43017
+ } catch (error) {
43018
+ if (error instanceof import_nodejs_utils70.AppError) {
43019
+ throw error;
43020
+ } else {
43021
+ throw new import_nodejs_utils70.InternalServerError("Failed to get kindergarten routine.");
43022
+ }
43023
+ }
43024
+ }
43025
+ async function countByDomain(domain) {
43026
+ const cacheKey = (0, import_nodejs_utils70.makeCacheKey)(namespace_collection, {
43027
+ domain,
43028
+ tag: "getByDomain"
43029
+ });
43030
+ try {
43031
+ const cached = await getCache(cacheKey);
43032
+ if (cached) {
43033
+ import_nodejs_utils70.logger.log({
43034
+ level: "info",
43035
+ message: `Cache hit for getById kindergarten routine: ${cacheKey}`
43036
+ });
43037
+ return cached;
43038
+ }
43039
+ const result = await collection.countDocuments({
43040
+ domain,
43041
+ status: "active"
43042
+ });
43043
+ setCache(cacheKey, result, 300).then(() => {
43044
+ import_nodejs_utils70.logger.log({
43045
+ level: "info",
43046
+ message: `Cache set for kindergarten routine by id: ${cacheKey}`
43047
+ });
43048
+ }).catch((err) => {
43049
+ import_nodejs_utils70.logger.log({
43050
+ level: "error",
43051
+ message: `Failed to set cache for kindergarten routine by id: ${err.message}`
43052
+ });
43053
+ });
43054
+ return result;
43055
+ } catch (error) {
43056
+ if (error instanceof import_nodejs_utils70.AppError) {
43057
+ throw error;
43058
+ } else {
43059
+ throw new import_nodejs_utils70.InternalServerError("Failed to get kindergarten routine.");
43060
+ }
43061
+ }
43062
+ }
43063
+ async function getBySection(section) {
43064
+ try {
43065
+ section = new import_mongodb42.ObjectId(section);
43066
+ } catch (error) {
43067
+ throw new import_nodejs_utils70.BadRequestError("Invalid section ID.");
43068
+ }
43069
+ const cacheKey = (0, import_nodejs_utils70.makeCacheKey)(namespace_collection, {
43070
+ section: String(section)
43071
+ });
43072
+ try {
43073
+ const cached = await getCache(cacheKey);
43074
+ if (cached) {
43075
+ import_nodejs_utils70.logger.log({
43076
+ level: "info",
43077
+ message: `Cache hit for getBySection kindergarten routine: ${cacheKey}`
43078
+ });
43079
+ return cached;
43080
+ }
43081
+ const result = await collection.find({
43082
+ section,
43083
+ deletedAt: { $in: ["", null] }
43084
+ }).toArray();
43085
+ setCache(cacheKey, result, 300).then(() => {
43086
+ import_nodejs_utils70.logger.log({
43087
+ level: "info",
43088
+ message: `Cache set for kindergarten routine by section: ${cacheKey}`
43089
+ });
43090
+ }).catch((err) => {
43091
+ import_nodejs_utils70.logger.log({
43092
+ level: "error",
43093
+ message: `Failed to set cache for kindergarten routine by section: ${err.message}`
43094
+ });
43095
+ });
43096
+ return result;
43097
+ } catch (error) {
43098
+ if (error instanceof import_nodejs_utils70.AppError) {
43099
+ throw error;
43100
+ } else {
43101
+ throw new import_nodejs_utils70.InternalServerError("Failed to get kindergarten routine.");
43102
+ }
43103
+ }
43104
+ }
43105
+ async function updateFieldById({ _id, field, value } = {}, session) {
43106
+ const allowedFields = [
43107
+ "sectionName",
43108
+ "classroomName",
43109
+ "schedule",
43110
+ "blockTimes",
43111
+ "type"
43112
+ ];
43113
+ if (!allowedFields.includes(field)) {
43114
+ throw new import_nodejs_utils70.BadRequestError(
43115
+ `Field "${field}" is not allowed to be updated.`
43116
+ );
43117
+ }
43118
+ try {
43119
+ _id = new import_mongodb42.ObjectId(_id);
43120
+ } catch (error) {
43121
+ throw new import_nodejs_utils70.BadRequestError(namespace_collection + " Invalid ID.");
43122
+ }
43123
+ try {
43124
+ await collection.updateOne(
43125
+ { _id, deletedAt: { $in: ["", null] } },
43126
+ { $set: { [field]: value, updatedAt: (/* @__PURE__ */ new Date()).toISOString() } },
43127
+ { session }
43128
+ );
43129
+ delCachedData();
43130
+ return `Successfully updated kindergarten routine ${field}.`;
43131
+ } catch (error) {
43132
+ throw new import_nodejs_utils70.InternalServerError(
43133
+ `Failed to update kindergarten routine ${field}.`
43134
+ );
43135
+ }
43136
+ }
43137
+ async function updateById(_id, value, session) {
43138
+ const { error } = schemaKindergartenRoutineUpdate.validate(value);
43139
+ if (error) {
43140
+ throw new import_nodejs_utils70.BadRequestError(
43141
+ `Invalid kindergarten routine data: ${error.message}`
43142
+ );
43143
+ }
43144
+ try {
43145
+ _id = new import_mongodb42.ObjectId(_id);
43146
+ } catch (error2) {
43147
+ throw new import_nodejs_utils70.BadRequestError(namespace_collection + " Invalid ID.");
43148
+ }
43149
+ try {
43150
+ await collection.updateOne(
43151
+ { _id },
43152
+ { $set: { ...value, updatedAt: (/* @__PURE__ */ new Date()).toISOString() } },
43153
+ { session }
43154
+ );
43155
+ delCachedData();
43156
+ return `Successfully updated kindergarten routine.`;
43157
+ } catch (error2) {
43158
+ throw new import_nodejs_utils70.InternalServerError("Failed to update kindergarten routine.");
43159
+ }
43160
+ }
43161
+ async function deleteById(_id) {
43162
+ try {
43163
+ _id = new import_mongodb42.ObjectId(_id);
43164
+ } catch (error) {
43165
+ throw new import_nodejs_utils70.BadRequestError(namespace_collection + " Invalid ID.");
43166
+ }
43167
+ try {
43168
+ await collection.updateOne(
43169
+ { _id },
43170
+ { $set: { status: "deleted", deletedAt: (/* @__PURE__ */ new Date()).toISOString() } }
43171
+ );
43172
+ delCachedData();
43173
+ return "Successfully deleted kindergarten routine.";
43174
+ } catch (error) {
43175
+ throw new import_nodejs_utils70.InternalServerError("Failed to delete kindergarten routine.");
43176
+ }
43177
+ }
43178
+ return {
43179
+ createIndexes,
43180
+ add,
43181
+ getAll,
43182
+ getById,
43183
+ countByDomain,
43184
+ getBySection,
43185
+ updateFieldById,
43186
+ updateById,
43187
+ deleteById
43188
+ };
43189
+ }
43190
+
43191
+ // src/resources/kindergarten-routine/kindergarten.routine.controller.ts
43192
+ var import_nodejs_utils71 = require("@eeplatform/nodejs-utils");
43193
+ var import_joi44 = __toESM(require("joi"));
43194
+ function useKindergartenRoutineController() {
43195
+ const {
43196
+ add: _add,
43197
+ getAll: _getAll,
43198
+ getById: _getById,
43199
+ getBySection: _getBySection,
43200
+ updateFieldById: _updateFieldById,
43201
+ deleteById: _deleteById,
43202
+ updateById: _updateById
43203
+ } = useKindergartenRoutineRepo();
43204
+ async function add(req, res, next) {
43205
+ const value = req.body;
43206
+ const { error } = schemaKindergartenRoutine.validate(value);
43207
+ if (error) {
43208
+ next(new import_nodejs_utils71.BadRequestError(error.message));
43209
+ return;
43210
+ }
43211
+ try {
43212
+ const data = await _add(value);
43213
+ res.json({
43214
+ message: "Successfully created kinder schedule.",
43215
+ data
43216
+ });
43217
+ return;
43218
+ } catch (error2) {
43219
+ next(error2);
43220
+ }
43221
+ }
43222
+ async function getAll(req, res, next) {
43223
+ const query = req.query;
43224
+ const validation = import_joi44.default.object({
43225
+ page: import_joi44.default.number().min(1).optional().allow("", null),
43226
+ limit: import_joi44.default.number().min(1).optional().allow("", null),
43227
+ search: import_joi44.default.string().optional().allow("", null),
43228
+ status: import_joi44.default.string().optional().allow("", null),
43229
+ school: import_joi44.default.string().hex().optional().allow("", null),
43230
+ section: import_joi44.default.string().hex().optional().allow("", null),
43231
+ classroom: import_joi44.default.string().hex().optional().allow("", null),
43232
+ type: import_joi44.default.string().optional().allow("", null),
43233
+ createdBy: import_joi44.default.string().hex().optional().allow("", null)
43234
+ });
43235
+ const { error } = validation.validate(query);
43236
+ const page = typeof req.query.page === "string" ? Number(req.query.page) : 1;
43237
+ const limit = typeof req.query.limit === "string" ? Number(req.query.limit) : 10;
43238
+ const search = req.query.search ?? "";
43239
+ const status = req.query.status ?? "active";
43240
+ const school = req.query.school ?? "";
43241
+ const section = req.query.section ?? "";
43242
+ const classroom = req.query.classroom ?? "";
43243
+ const type = req.query.type ?? "";
43244
+ const createdBy = req.query.createdBy ?? "";
43245
+ const isPageNumber = isFinite(page);
43246
+ if (!isPageNumber) {
43247
+ next(new import_nodejs_utils71.BadRequestError("Invalid page number."));
43248
+ return;
43249
+ }
43250
+ const isLimitNumber = isFinite(limit);
43251
+ if (!isLimitNumber) {
43252
+ next(new import_nodejs_utils71.BadRequestError("Invalid limit number."));
43253
+ return;
43254
+ }
43255
+ if (error) {
43256
+ next(new import_nodejs_utils71.BadRequestError(error.message));
43257
+ return;
43258
+ }
43259
+ try {
43260
+ const data = await _getAll({
43261
+ page,
43262
+ limit,
43263
+ search,
43264
+ status,
43265
+ school,
43266
+ section,
43267
+ classroom,
43268
+ type,
43269
+ createdBy: createdBy || void 0
43270
+ });
43271
+ res.json(data);
43272
+ return;
43273
+ } catch (error2) {
43274
+ next(error2);
43275
+ }
43276
+ }
43277
+ async function getById(req, res, next) {
43278
+ const id = req.params.id;
43279
+ const validation = import_joi44.default.object({
43280
+ id: import_joi44.default.string().hex().required()
43281
+ });
43282
+ const { error } = validation.validate({ id });
43283
+ if (error) {
43284
+ next(new import_nodejs_utils71.BadRequestError(error.message));
43285
+ return;
43286
+ }
43287
+ try {
43288
+ const data = await _getById(id);
43289
+ res.json({
43290
+ message: "Successfully retrieved kinder schedule.",
43291
+ data
43292
+ });
43293
+ return;
43294
+ } catch (error2) {
43295
+ next(error2);
43296
+ }
43297
+ }
43298
+ async function getBySection(req, res, next) {
43299
+ const section = req.params.section;
43300
+ const validation = import_joi44.default.object({
43301
+ section: import_joi44.default.string().hex().required()
43302
+ });
43303
+ const { error } = validation.validate({ section });
43304
+ if (error) {
43305
+ next(new import_nodejs_utils71.BadRequestError(error.message));
43306
+ return;
43307
+ }
43308
+ try {
43309
+ const data = await _getBySection(section);
43310
+ res.json({
43311
+ message: "Successfully retrieved kinder schedules.",
43312
+ data
43313
+ });
43314
+ return;
43315
+ } catch (error2) {
43316
+ next(error2);
43317
+ }
43318
+ }
43319
+ async function updateField(req, res, next) {
43320
+ const _id = req.params.id;
43321
+ const { field, value } = req.body;
43322
+ const validation = import_joi44.default.object({
43323
+ _id: import_joi44.default.string().hex().required(),
43324
+ field: import_joi44.default.string().valid("sectionName", "classroomName", "schedule", "blockTimes", "type").required(),
43325
+ value: import_joi44.default.alternatives().try(import_joi44.default.string(), import_joi44.default.array(), import_joi44.default.object()).required()
43326
+ });
43327
+ const { error } = validation.validate({ _id, field, value });
43328
+ if (error) {
43329
+ next(new import_nodejs_utils71.BadRequestError(error.message));
43330
+ return;
43331
+ }
43332
+ try {
43333
+ const message = await _updateFieldById({ _id, field, value });
43334
+ res.json({ message });
43335
+ return;
43336
+ } catch (error2) {
43337
+ next(error2);
43338
+ }
43339
+ }
43340
+ async function updateById(req, res, next) {
43341
+ const _id = req.params.id;
43342
+ const payload = req.body;
43343
+ const { error: errorId } = import_joi44.default.string().hex().required().validate(_id);
43344
+ if (errorId) {
43345
+ next(new import_nodejs_utils71.BadRequestError(errorId.message));
43346
+ return;
43347
+ }
43348
+ const { error } = schemaKindergartenRoutineUpdate.validate(payload);
43349
+ if (error) {
43350
+ next(new import_nodejs_utils71.BadRequestError(error.message));
43351
+ return;
43352
+ }
43353
+ try {
43354
+ const message = await _updateById(_id, payload);
43355
+ res.json({ message });
43356
+ return;
43357
+ } catch (error2) {
43358
+ next(error2);
43359
+ }
43360
+ }
43361
+ async function deleteById(req, res, next) {
43362
+ const _id = req.params.id;
43363
+ const validation = import_joi44.default.object({
43364
+ _id: import_joi44.default.string().hex().required()
43365
+ });
43366
+ const { error } = validation.validate({ _id });
43367
+ if (error) {
43368
+ next(new import_nodejs_utils71.BadRequestError(error.message));
43369
+ return;
43370
+ }
43371
+ try {
43372
+ const message = await _deleteById(_id);
43373
+ res.json({ message });
43374
+ return;
43375
+ } catch (error2) {
43376
+ next(error2);
43377
+ }
43378
+ }
43379
+ return {
43380
+ add,
43381
+ getAll,
43382
+ getById,
43383
+ getBySection,
43384
+ updateField,
43385
+ updateById,
43386
+ deleteById
43387
+ };
43388
+ }
43389
+
42697
43390
  // src/resources/section/section.service.ts
42698
43391
  function useSectionService() {
42699
43392
  const { getCountByGradeLevel, getByGradeLevel: getLeanerByGradeLevel } = useLearnerRepo();
@@ -42705,13 +43398,14 @@ function useSectionService() {
42705
43398
  const { getById: getSchoolById } = useSchoolRepo();
42706
43399
  const { getAll: getAllPersonnel } = usePersonnelRepo();
42707
43400
  const { add: addTeachingLoad } = useTeachingLoadRepo();
43401
+ const { getById: getKindergartenRoutineById, add: addKindergartenRoutine } = useKindergartenRoutineRepo();
42708
43402
  function distributeStudents(total, minPer, maxPer) {
42709
43403
  if (total <= 0)
42710
43404
  return [];
42711
43405
  if (minPer <= 0 || maxPer <= 0)
42712
43406
  return [];
42713
43407
  if (minPer > maxPer) {
42714
- throw new import_nodejs_utils69.BadRequestError(
43408
+ throw new import_nodejs_utils72.BadRequestError(
42715
43409
  "Minimum students per section cannot be greater than maximum."
42716
43410
  );
42717
43411
  }
@@ -42731,7 +43425,7 @@ function useSectionService() {
42731
43425
  }
42732
43426
  for (const size of sizes) {
42733
43427
  if (size > maxPer) {
42734
- throw new import_nodejs_utils69.BadRequestError(
43428
+ throw new import_nodejs_utils72.BadRequestError(
42735
43429
  `Generated section exceeds max limit of ${maxPer}.`
42736
43430
  );
42737
43431
  }
@@ -42741,16 +43435,26 @@ function useSectionService() {
42741
43435
  async function generateSections(value) {
42742
43436
  const { error } = schemaGenerateSections.validate(value);
42743
43437
  if (error) {
42744
- throw new import_nodejs_utils69.BadRequestError(
43438
+ throw new import_nodejs_utils72.BadRequestError(
42745
43439
  `Invalid section generation data: ${error.message}`
42746
43440
  );
42747
43441
  }
42748
- const session = import_nodejs_utils69.useAtlas.getClient()?.startSession();
43442
+ const session = import_nodejs_utils72.useAtlas.getClient()?.startSession();
42749
43443
  if (!session) {
42750
43444
  throw new Error("Unable to start database session.");
42751
43445
  }
42752
43446
  try {
42753
43447
  await session.startTransaction();
43448
+ const isKindergarten = value.gradeLevel.toLowerCase() === "kindergarten";
43449
+ let kindergartenRoutine = null;
43450
+ if (isKindergarten) {
43451
+ kindergartenRoutine = await getKindergartenRoutineById(
43452
+ value.routine ?? ""
43453
+ );
43454
+ if (!kindergartenRoutine) {
43455
+ throw new import_nodejs_utils72.BadRequestError("Kindergarten routine not found.");
43456
+ }
43457
+ }
42754
43458
  const studentCount = await getCountByGradeLevel(
42755
43459
  {
42756
43460
  school: value.school,
@@ -42761,7 +43465,7 @@ function useSectionService() {
42761
43465
  session
42762
43466
  );
42763
43467
  if (studentCount === 0) {
42764
- throw new import_nodejs_utils69.BadRequestError("No learners found for this grade level.");
43468
+ throw new import_nodejs_utils72.BadRequestError("No learners found for this grade level.");
42765
43469
  }
42766
43470
  const gradeLevelData = await getByGradeLevel(
42767
43471
  {
@@ -42771,13 +43475,13 @@ function useSectionService() {
42771
43475
  session
42772
43476
  );
42773
43477
  if (!gradeLevelData) {
42774
- throw new import_nodejs_utils69.BadRequestError("Grade level not found.");
43478
+ throw new import_nodejs_utils72.BadRequestError("Grade level not found.");
42775
43479
  }
42776
43480
  const minPerSection = value.minStudents ?? gradeLevelData.minNumberOfLearners;
42777
43481
  const maxPerSection = value.maxStudents ?? gradeLevelData.maxNumberOfLearners;
42778
43482
  const sectionsNeeded = Math.ceil(studentCount / minPerSection);
42779
43483
  if (sectionsNeeded > value.set.length) {
42780
- throw new import_nodejs_utils69.BadRequestError(
43484
+ throw new import_nodejs_utils72.BadRequestError(
42781
43485
  "Insufficient number of section names in set[]."
42782
43486
  );
42783
43487
  }
@@ -42787,11 +43491,11 @@ function useSectionService() {
42787
43491
  maxPerSection
42788
43492
  );
42789
43493
  if (sectionSizes.length === 0) {
42790
- throw new import_nodejs_utils69.BadRequestError("Unable to compute section sizes.");
43494
+ throw new import_nodejs_utils72.BadRequestError("Unable to compute section sizes.");
42791
43495
  }
42792
43496
  const schoolData = await getSchoolById(value.school);
42793
43497
  if (!schoolData) {
42794
- throw new import_nodejs_utils69.BadRequestError("School not found.");
43498
+ throw new import_nodejs_utils72.BadRequestError("School not found.");
42795
43499
  }
42796
43500
  let totalStudentsProcessed = 0;
42797
43501
  for (let i = 0; i < sectionSizes.length; i++) {
@@ -42818,15 +43522,15 @@ function useSectionService() {
42818
43522
  session
42819
43523
  );
42820
43524
  if (!learners.length) {
42821
- throw new import_nodejs_utils69.BadRequestError(`No learners found for section #${i + 1}.`);
43525
+ throw new import_nodejs_utils72.BadRequestError(`No learners found for section #${i + 1}.`);
42822
43526
  }
42823
43527
  totalStudentsProcessed += learners.length;
42824
43528
  for (const student of learners) {
42825
43529
  if (!student._id) {
42826
- throw new import_nodejs_utils69.BadRequestError("Learner ID is missing.");
43530
+ throw new import_nodejs_utils72.BadRequestError("Learner ID is missing.");
42827
43531
  }
42828
43532
  if (!student.learnerInfo.lrn) {
42829
- throw new import_nodejs_utils69.BadRequestError("Learner LRN is missing.");
43533
+ throw new import_nodejs_utils72.BadRequestError("Learner LRN is missing.");
42830
43534
  }
42831
43535
  await assignStudent(
42832
43536
  {
@@ -42875,6 +43579,12 @@ function useSectionService() {
42875
43579
  session
42876
43580
  );
42877
43581
  }
43582
+ if (isKindergarten && kindergartenRoutine) {
43583
+ kindergartenRoutine.section = section;
43584
+ kindergartenRoutine.sectionName = sectionName;
43585
+ kindergartenRoutine.type = "actual";
43586
+ await addKindergartenRoutine(kindergartenRoutine, session);
43587
+ }
42878
43588
  }
42879
43589
  let pageTeacher = 1;
42880
43590
  let pagesTeachers = 1;
@@ -42888,11 +43598,16 @@ function useSectionService() {
42888
43598
  teachers.push(...teachersData.items);
42889
43599
  pageTeacher++;
42890
43600
  } while (pageTeacher < pagesTeachers);
43601
+ if (!teachers.length) {
43602
+ throw new import_nodejs_utils72.BadRequestError(
43603
+ "Could not proceed, no teaching personnel found."
43604
+ );
43605
+ }
42891
43606
  if (teachers.length) {
42892
43607
  for (let index = 0; index < teachers.length; index++) {
42893
43608
  const teacher = teachers[index];
42894
43609
  if (!teacher._id) {
42895
- throw new import_nodejs_utils69.BadRequestError("Teacher ID is missing.");
43610
+ throw new import_nodejs_utils72.BadRequestError("Teacher ID is missing.");
42896
43611
  }
42897
43612
  await addTeachingLoad(
42898
43613
  {
@@ -42911,10 +43626,10 @@ function useSectionService() {
42911
43626
  return "Sections generated successfully.";
42912
43627
  } catch (error2) {
42913
43628
  await session.abortTransaction();
42914
- if (error2 instanceof import_nodejs_utils69.AppError) {
43629
+ if (error2 instanceof import_nodejs_utils72.AppError) {
42915
43630
  throw error2;
42916
43631
  } else {
42917
- throw new import_nodejs_utils69.InternalServerError("Failed to generate sections.");
43632
+ throw new import_nodejs_utils72.InternalServerError("Failed to generate sections.");
42918
43633
  }
42919
43634
  } finally {
42920
43635
  await session?.endSession();
@@ -42923,7 +43638,7 @@ function useSectionService() {
42923
43638
  async function generateSectionPreview(value) {
42924
43639
  const { error } = schemaGenerateSections.validate(value);
42925
43640
  if (error) {
42926
- throw new import_nodejs_utils69.BadRequestError(
43641
+ throw new import_nodejs_utils72.BadRequestError(
42927
43642
  `Invalid section generation data: ${error.message}`
42928
43643
  );
42929
43644
  }
@@ -42935,20 +43650,20 @@ function useSectionService() {
42935
43650
  specialProgram: value.specialProgram
42936
43651
  });
42937
43652
  if (studentCount === 0) {
42938
- throw new import_nodejs_utils69.BadRequestError("No learners found for this grade level.");
43653
+ throw new import_nodejs_utils72.BadRequestError("No learners found for this grade level.");
42939
43654
  }
42940
43655
  const gradeLevelData = await getByGradeLevel({
42941
43656
  school: value.school,
42942
43657
  gradeLevel: value.gradeLevel
42943
43658
  });
42944
43659
  if (!gradeLevelData) {
42945
- throw new import_nodejs_utils69.BadRequestError("Grade level not found.");
43660
+ throw new import_nodejs_utils72.BadRequestError("Grade level not found.");
42946
43661
  }
42947
43662
  const minPerSection = value.minStudents ?? gradeLevelData.minNumberOfLearners;
42948
43663
  const maxPerSection = value.maxStudents ?? gradeLevelData.maxNumberOfLearners;
42949
43664
  const sectionsNeeded = Math.ceil(studentCount / minPerSection);
42950
43665
  if (sectionsNeeded > value.set.length) {
42951
- throw new import_nodejs_utils69.BadRequestError(
43666
+ throw new import_nodejs_utils72.BadRequestError(
42952
43667
  "Insufficient number of section names in set[]."
42953
43668
  );
42954
43669
  }
@@ -42958,7 +43673,7 @@ function useSectionService() {
42958
43673
  maxPerSection
42959
43674
  );
42960
43675
  if (sectionSizes.length === 0) {
42961
- throw new import_nodejs_utils69.BadRequestError("Unable to compute section sizes.");
43676
+ throw new import_nodejs_utils72.BadRequestError("Unable to compute section sizes.");
42962
43677
  }
42963
43678
  const sections = sectionSizes.map((size, index) => ({
42964
43679
  name: value.set[index],
@@ -42970,10 +43685,10 @@ function useSectionService() {
42970
43685
  sections
42971
43686
  };
42972
43687
  } catch (error2) {
42973
- if (error2 instanceof import_nodejs_utils69.AppError) {
43688
+ if (error2 instanceof import_nodejs_utils72.AppError) {
42974
43689
  throw error2;
42975
43690
  } else {
42976
- throw new import_nodejs_utils69.InternalServerError("Failed to generate section preview.");
43691
+ throw new import_nodejs_utils72.InternalServerError("Failed to generate section preview.");
42977
43692
  }
42978
43693
  }
42979
43694
  }
@@ -43001,7 +43716,7 @@ function useSectionController() {
43001
43716
  const value = req.body;
43002
43717
  const { error } = schemaSection.validate(value);
43003
43718
  if (error) {
43004
- next(new import_nodejs_utils70.BadRequestError(error.message));
43719
+ next(new import_nodejs_utils73.BadRequestError(error.message));
43005
43720
  return;
43006
43721
  }
43007
43722
  try {
@@ -43019,7 +43734,7 @@ function useSectionController() {
43019
43734
  const value = req.body;
43020
43735
  const { error } = schemaGenerateSections.validate(value);
43021
43736
  if (error) {
43022
- next(new import_nodejs_utils70.BadRequestError(error.message));
43737
+ next(new import_nodejs_utils73.BadRequestError(error.message));
43023
43738
  return;
43024
43739
  }
43025
43740
  try {
@@ -43037,7 +43752,7 @@ function useSectionController() {
43037
43752
  const value = req.body;
43038
43753
  const { error } = schemaGenerateSections.validate(value);
43039
43754
  if (error) {
43040
- next(new import_nodejs_utils70.BadRequestError(error.message));
43755
+ next(new import_nodejs_utils73.BadRequestError(error.message));
43041
43756
  return;
43042
43757
  }
43043
43758
  try {
@@ -43050,14 +43765,14 @@ function useSectionController() {
43050
43765
  }
43051
43766
  async function getAll(req, res, next) {
43052
43767
  const query = req.query;
43053
- const validation = import_joi43.default.object({
43054
- page: import_joi43.default.number().min(1).optional().allow("", null),
43055
- limit: import_joi43.default.number().min(1).optional().allow("", null),
43056
- search: import_joi43.default.string().optional().allow("", null),
43057
- status: import_joi43.default.string().optional().allow("", null),
43058
- school: import_joi43.default.string().hex().optional().allow("", null),
43059
- schoolYear: import_joi43.default.string().optional().allow("", null),
43060
- gradeLevel: import_joi43.default.string().optional().allow("", null)
43768
+ const validation = import_joi45.default.object({
43769
+ page: import_joi45.default.number().min(1).optional().allow("", null),
43770
+ limit: import_joi45.default.number().min(1).optional().allow("", null),
43771
+ search: import_joi45.default.string().optional().allow("", null),
43772
+ status: import_joi45.default.string().optional().allow("", null),
43773
+ school: import_joi45.default.string().hex().optional().allow("", null),
43774
+ schoolYear: import_joi45.default.string().optional().allow("", null),
43775
+ gradeLevel: import_joi45.default.string().optional().allow("", null)
43061
43776
  });
43062
43777
  const { error } = validation.validate(query);
43063
43778
  const page = typeof req.query.page === "string" ? Number(req.query.page) : 1;
@@ -43069,16 +43784,16 @@ function useSectionController() {
43069
43784
  const gradeLevel = req.query.gradeLevel ?? "";
43070
43785
  const isPageNumber = isFinite(page);
43071
43786
  if (!isPageNumber) {
43072
- next(new import_nodejs_utils70.BadRequestError("Invalid page number."));
43787
+ next(new import_nodejs_utils73.BadRequestError("Invalid page number."));
43073
43788
  return;
43074
43789
  }
43075
43790
  const isLimitNumber = isFinite(limit);
43076
43791
  if (!isLimitNumber) {
43077
- next(new import_nodejs_utils70.BadRequestError("Invalid limit number."));
43792
+ next(new import_nodejs_utils73.BadRequestError("Invalid limit number."));
43078
43793
  return;
43079
43794
  }
43080
43795
  if (error) {
43081
- next(new import_nodejs_utils70.BadRequestError(error.message));
43796
+ next(new import_nodejs_utils73.BadRequestError(error.message));
43082
43797
  return;
43083
43798
  }
43084
43799
  try {
@@ -43099,12 +43814,12 @@ function useSectionController() {
43099
43814
  }
43100
43815
  async function getById(req, res, next) {
43101
43816
  const id = req.params.id;
43102
- const validation = import_joi43.default.object({
43103
- id: import_joi43.default.string().hex().required()
43817
+ const validation = import_joi45.default.object({
43818
+ id: import_joi45.default.string().hex().required()
43104
43819
  });
43105
43820
  const { error } = validation.validate({ id });
43106
43821
  if (error) {
43107
- next(new import_nodejs_utils70.BadRequestError(error.message));
43822
+ next(new import_nodejs_utils73.BadRequestError(error.message));
43108
43823
  return;
43109
43824
  }
43110
43825
  try {
@@ -43117,12 +43832,12 @@ function useSectionController() {
43117
43832
  }
43118
43833
  async function getByName(req, res, next) {
43119
43834
  const name = req.params.name;
43120
- const validation = import_joi43.default.object({
43121
- name: import_joi43.default.string().required()
43835
+ const validation = import_joi45.default.object({
43836
+ name: import_joi45.default.string().required()
43122
43837
  });
43123
43838
  const { error } = validation.validate({ name });
43124
43839
  if (error) {
43125
- next(new import_nodejs_utils70.BadRequestError(error.message));
43840
+ next(new import_nodejs_utils73.BadRequestError(error.message));
43126
43841
  return;
43127
43842
  }
43128
43843
  try {
@@ -43138,12 +43853,12 @@ function useSectionController() {
43138
43853
  }
43139
43854
  async function getBySchool(req, res, next) {
43140
43855
  const school = req.params.school;
43141
- const validation = import_joi43.default.object({
43142
- school: import_joi43.default.string().hex().required()
43856
+ const validation = import_joi45.default.object({
43857
+ school: import_joi45.default.string().hex().required()
43143
43858
  });
43144
43859
  const { error } = validation.validate({ school });
43145
43860
  if (error) {
43146
- next(new import_nodejs_utils70.BadRequestError(error.message));
43861
+ next(new import_nodejs_utils73.BadRequestError(error.message));
43147
43862
  return;
43148
43863
  }
43149
43864
  try {
@@ -43160,14 +43875,14 @@ function useSectionController() {
43160
43875
  async function updateField(req, res, next) {
43161
43876
  const _id = req.params.id;
43162
43877
  const { field, value } = req.body;
43163
- const validation = import_joi43.default.object({
43164
- _id: import_joi43.default.string().hex().required(),
43165
- field: import_joi43.default.string().valid("name", "schoolYear", "gradeLevel", "adviser", "adviserName").required(),
43166
- value: import_joi43.default.string().required()
43878
+ const validation = import_joi45.default.object({
43879
+ _id: import_joi45.default.string().hex().required(),
43880
+ field: import_joi45.default.string().valid("name", "schoolYear", "gradeLevel", "adviser", "adviserName").required(),
43881
+ value: import_joi45.default.string().required()
43167
43882
  });
43168
43883
  const { error } = validation.validate({ _id, field, value });
43169
43884
  if (error) {
43170
- next(new import_nodejs_utils70.BadRequestError(error.message));
43885
+ next(new import_nodejs_utils73.BadRequestError(error.message));
43171
43886
  return;
43172
43887
  }
43173
43888
  try {
@@ -43181,13 +43896,13 @@ function useSectionController() {
43181
43896
  async function addStudent(req, res, next) {
43182
43897
  const _id = req.params.id;
43183
43898
  const { studentId } = req.body;
43184
- const validation = import_joi43.default.object({
43185
- _id: import_joi43.default.string().hex().required(),
43186
- studentId: import_joi43.default.string().required()
43899
+ const validation = import_joi45.default.object({
43900
+ _id: import_joi45.default.string().hex().required(),
43901
+ studentId: import_joi45.default.string().required()
43187
43902
  });
43188
43903
  const { error } = validation.validate({ _id, studentId });
43189
43904
  if (error) {
43190
- next(new import_nodejs_utils70.BadRequestError(error.message));
43905
+ next(new import_nodejs_utils73.BadRequestError(error.message));
43191
43906
  return;
43192
43907
  }
43193
43908
  try {
@@ -43201,13 +43916,13 @@ function useSectionController() {
43201
43916
  async function removeStudent(req, res, next) {
43202
43917
  const _id = req.params.id;
43203
43918
  const { studentId } = req.body;
43204
- const validation = import_joi43.default.object({
43205
- _id: import_joi43.default.string().hex().required(),
43206
- studentId: import_joi43.default.string().required()
43919
+ const validation = import_joi45.default.object({
43920
+ _id: import_joi45.default.string().hex().required(),
43921
+ studentId: import_joi45.default.string().required()
43207
43922
  });
43208
43923
  const { error } = validation.validate({ _id, studentId });
43209
43924
  if (error) {
43210
- next(new import_nodejs_utils70.BadRequestError(error.message));
43925
+ next(new import_nodejs_utils73.BadRequestError(error.message));
43211
43926
  return;
43212
43927
  }
43213
43928
  try {
@@ -43220,12 +43935,12 @@ function useSectionController() {
43220
43935
  }
43221
43936
  async function deleteById(req, res, next) {
43222
43937
  const _id = req.params.id;
43223
- const validation = import_joi43.default.object({
43224
- _id: import_joi43.default.string().hex().required()
43938
+ const validation = import_joi45.default.object({
43939
+ _id: import_joi45.default.string().hex().required()
43225
43940
  });
43226
43941
  const { error } = validation.validate({ _id });
43227
43942
  if (error) {
43228
- next(new import_nodejs_utils70.BadRequestError(error.message));
43943
+ next(new import_nodejs_utils73.BadRequestError(error.message));
43229
43944
  return;
43230
43945
  }
43231
43946
  try {
@@ -43252,15 +43967,15 @@ function useSectionController() {
43252
43967
  }
43253
43968
 
43254
43969
  // src/resources/section-student/section.student.controller.ts
43255
- var import_nodejs_utils71 = require("@eeplatform/nodejs-utils");
43256
- var import_joi44 = __toESM(require("joi"));
43970
+ var import_nodejs_utils74 = require("@eeplatform/nodejs-utils");
43971
+ var import_joi46 = __toESM(require("joi"));
43257
43972
  function useSectionStudentController() {
43258
43973
  const { add: _add, getAll: _getAll } = useSectionStudentRepo();
43259
43974
  async function add(req, res, next) {
43260
43975
  const value = req.body;
43261
43976
  const { error } = schemaSectionStudent.validate(value);
43262
43977
  if (error) {
43263
- next(new import_nodejs_utils71.BadRequestError(error.message));
43978
+ next(new import_nodejs_utils74.BadRequestError(error.message));
43264
43979
  return;
43265
43980
  }
43266
43981
  try {
@@ -43276,15 +43991,15 @@ function useSectionStudentController() {
43276
43991
  }
43277
43992
  async function getAll(req, res, next) {
43278
43993
  const query = req.query;
43279
- const validation = import_joi44.default.object({
43280
- page: import_joi44.default.number().min(1).optional().allow("", null),
43281
- limit: import_joi44.default.number().min(1).optional().allow("", null),
43282
- search: import_joi44.default.string().optional().allow("", null),
43283
- status: import_joi44.default.string().optional().allow("", null),
43284
- school: import_joi44.default.string().optional().allow("", null),
43285
- gradeLevel: import_joi44.default.string().optional().allow("", null),
43286
- section: import_joi44.default.string().optional().allow("", null),
43287
- schoolYear: import_joi44.default.string().optional().allow("", null)
43994
+ const validation = import_joi46.default.object({
43995
+ page: import_joi46.default.number().min(1).optional().allow("", null),
43996
+ limit: import_joi46.default.number().min(1).optional().allow("", null),
43997
+ search: import_joi46.default.string().optional().allow("", null),
43998
+ status: import_joi46.default.string().optional().allow("", null),
43999
+ school: import_joi46.default.string().optional().allow("", null),
44000
+ gradeLevel: import_joi46.default.string().optional().allow("", null),
44001
+ section: import_joi46.default.string().optional().allow("", null),
44002
+ schoolYear: import_joi46.default.string().optional().allow("", null)
43288
44003
  });
43289
44004
  const { error } = validation.validate(query);
43290
44005
  const page = typeof req.query.page === "string" ? Number(req.query.page) : 1;
@@ -43297,16 +44012,16 @@ function useSectionStudentController() {
43297
44012
  const schoolYear = req.query.schoolYear ?? "";
43298
44013
  const isPageNumber = isFinite(page);
43299
44014
  if (!isPageNumber) {
43300
- next(new import_nodejs_utils71.BadRequestError("Invalid page number."));
44015
+ next(new import_nodejs_utils74.BadRequestError("Invalid page number."));
43301
44016
  return;
43302
44017
  }
43303
44018
  const isLimitNumber = isFinite(limit);
43304
44019
  if (!isLimitNumber) {
43305
- next(new import_nodejs_utils71.BadRequestError("Invalid limit number."));
44020
+ next(new import_nodejs_utils74.BadRequestError("Invalid limit number."));
43306
44021
  return;
43307
44022
  }
43308
44023
  if (error) {
43309
- next(new import_nodejs_utils71.BadRequestError(error.message));
44024
+ next(new import_nodejs_utils74.BadRequestError(error.message));
43310
44025
  return;
43311
44026
  }
43312
44027
  try {
@@ -43333,64 +44048,64 @@ function useSectionStudentController() {
43333
44048
  }
43334
44049
 
43335
44050
  // src/resources/building/building.model.ts
43336
- var import_nodejs_utils72 = require("@eeplatform/nodejs-utils");
43337
- var import_joi45 = __toESM(require("joi"));
43338
- var import_mongodb41 = require("mongodb");
43339
- var schemaBuilding = import_joi45.default.object({
43340
- _id: import_joi45.default.string().hex().optional(),
43341
- school: import_joi45.default.string().hex().required(),
43342
- serial: import_joi45.default.string().optional().allow("", null),
43343
- name: import_joi45.default.string().required(),
43344
- levels: import_joi45.default.number().integer().min(1).required(),
43345
- createdAt: import_joi45.default.date().optional().allow("", null),
43346
- updatedAt: import_joi45.default.date().optional().allow("", null),
43347
- deletedAt: import_joi45.default.date().optional().allow("", null),
43348
- status: import_joi45.default.string().optional().allow("", null)
44051
+ var import_nodejs_utils75 = require("@eeplatform/nodejs-utils");
44052
+ var import_joi47 = __toESM(require("joi"));
44053
+ var import_mongodb43 = require("mongodb");
44054
+ var schemaBuilding = import_joi47.default.object({
44055
+ _id: import_joi47.default.string().hex().optional(),
44056
+ school: import_joi47.default.string().hex().required(),
44057
+ serial: import_joi47.default.string().optional().allow("", null),
44058
+ name: import_joi47.default.string().required(),
44059
+ levels: import_joi47.default.number().integer().min(1).required(),
44060
+ createdAt: import_joi47.default.date().optional().allow("", null),
44061
+ updatedAt: import_joi47.default.date().optional().allow("", null),
44062
+ deletedAt: import_joi47.default.date().optional().allow("", null),
44063
+ status: import_joi47.default.string().optional().allow("", null)
43349
44064
  });
43350
- var schemaBuildingUnit = import_joi45.default.object({
43351
- _id: import_joi45.default.string().hex().optional(),
43352
- school: import_joi45.default.string().hex().required(),
43353
- name: import_joi45.default.string().optional().allow("", null),
43354
- building: import_joi45.default.string().hex().required(),
43355
- buildingName: import_joi45.default.string().optional().allow("", null),
43356
- level: import_joi45.default.number().integer().min(1).required(),
43357
- category: import_joi45.default.string().required(),
43358
- type: import_joi45.default.string().required(),
43359
- seating_capacity: import_joi45.default.number().integer().min(0).required(),
43360
- standing_capacity: import_joi45.default.number().integer().min(0).required(),
43361
- description: import_joi45.default.string().optional().allow("", null),
43362
- unit_of_measurement: import_joi45.default.string().valid("sqm").required(),
43363
- area: import_joi45.default.number().positive().required(),
43364
- status: import_joi45.default.string().optional().allow("", null)
44065
+ var schemaBuildingUnit = import_joi47.default.object({
44066
+ _id: import_joi47.default.string().hex().optional(),
44067
+ school: import_joi47.default.string().hex().required(),
44068
+ name: import_joi47.default.string().optional().allow("", null),
44069
+ building: import_joi47.default.string().hex().required(),
44070
+ buildingName: import_joi47.default.string().optional().allow("", null),
44071
+ level: import_joi47.default.number().integer().min(1).required(),
44072
+ category: import_joi47.default.string().required(),
44073
+ type: import_joi47.default.string().required(),
44074
+ seating_capacity: import_joi47.default.number().integer().min(0).required(),
44075
+ standing_capacity: import_joi47.default.number().integer().min(0).required(),
44076
+ description: import_joi47.default.string().optional().allow("", null),
44077
+ unit_of_measurement: import_joi47.default.string().valid("sqm").required(),
44078
+ area: import_joi47.default.number().positive().required(),
44079
+ status: import_joi47.default.string().optional().allow("", null)
43365
44080
  });
43366
- var schemaUpdateOptions = import_joi45.default.object({
43367
- name: import_joi45.default.string().optional().allow("", null),
43368
- building: import_joi45.default.string().hex().optional().allow("", null),
43369
- buildingName: import_joi45.default.string().optional().allow("", null),
43370
- level: import_joi45.default.number().integer().min(1).optional().allow("", null),
43371
- category: import_joi45.default.string().optional().allow("", null),
43372
- type: import_joi45.default.string().optional().allow("", null),
43373
- seating_capacity: import_joi45.default.number().integer().min(0).optional().allow("", null),
43374
- standing_capacity: import_joi45.default.number().integer().min(0).optional().allow("", null),
43375
- area: import_joi45.default.number().positive().optional().allow("", null)
44081
+ var schemaUpdateOptions = import_joi47.default.object({
44082
+ name: import_joi47.default.string().optional().allow("", null),
44083
+ building: import_joi47.default.string().hex().optional().allow("", null),
44084
+ buildingName: import_joi47.default.string().optional().allow("", null),
44085
+ level: import_joi47.default.number().integer().min(1).optional().allow("", null),
44086
+ category: import_joi47.default.string().optional().allow("", null),
44087
+ type: import_joi47.default.string().optional().allow("", null),
44088
+ seating_capacity: import_joi47.default.number().integer().min(0).optional().allow("", null),
44089
+ standing_capacity: import_joi47.default.number().integer().min(0).optional().allow("", null),
44090
+ area: import_joi47.default.number().positive().optional().allow("", null)
43376
44091
  });
43377
44092
  function MBuilding(value) {
43378
44093
  const { error } = schemaBuilding.validate(value);
43379
44094
  if (error) {
43380
- import_nodejs_utils72.logger.info(`Building Model: ${error.message}`);
43381
- throw new import_nodejs_utils72.BadRequestError(error.message);
44095
+ import_nodejs_utils75.logger.info(`Building Model: ${error.message}`);
44096
+ throw new import_nodejs_utils75.BadRequestError(error.message);
43382
44097
  }
43383
44098
  if (value._id && typeof value._id === "string") {
43384
44099
  try {
43385
- value._id = new import_mongodb41.ObjectId(value._id);
44100
+ value._id = new import_mongodb43.ObjectId(value._id);
43386
44101
  } catch (error2) {
43387
- throw new import_nodejs_utils72.BadRequestError("Invalid _id format");
44102
+ throw new import_nodejs_utils75.BadRequestError("Invalid _id format");
43388
44103
  }
43389
44104
  }
43390
44105
  try {
43391
- value.school = new import_mongodb41.ObjectId(value.school);
44106
+ value.school = new import_mongodb43.ObjectId(value.school);
43392
44107
  } catch (error2) {
43393
- throw new import_nodejs_utils72.BadRequestError("Invalid school format");
44108
+ throw new import_nodejs_utils75.BadRequestError("Invalid school format");
43394
44109
  }
43395
44110
  return {
43396
44111
  _id: value._id ?? void 0,
@@ -43407,25 +44122,25 @@ function MBuilding(value) {
43407
44122
  function MBuildingUnit(value) {
43408
44123
  const { error } = schemaBuildingUnit.validate(value);
43409
44124
  if (error) {
43410
- import_nodejs_utils72.logger.info(`Building Unit Model: ${error.message}`);
43411
- throw new import_nodejs_utils72.BadRequestError(error.message);
44125
+ import_nodejs_utils75.logger.info(`Building Unit Model: ${error.message}`);
44126
+ throw new import_nodejs_utils75.BadRequestError(error.message);
43412
44127
  }
43413
44128
  if (value._id && typeof value._id === "string") {
43414
44129
  try {
43415
- value._id = new import_mongodb41.ObjectId(value._id);
44130
+ value._id = new import_mongodb43.ObjectId(value._id);
43416
44131
  } catch (error2) {
43417
- throw new import_nodejs_utils72.BadRequestError("Invalid ID");
44132
+ throw new import_nodejs_utils75.BadRequestError("Invalid ID");
43418
44133
  }
43419
44134
  }
43420
44135
  try {
43421
- value.school = new import_mongodb41.ObjectId(value.school);
44136
+ value.school = new import_mongodb43.ObjectId(value.school);
43422
44137
  } catch (error2) {
43423
- throw new import_nodejs_utils72.BadRequestError("Invalid school ID");
44138
+ throw new import_nodejs_utils75.BadRequestError("Invalid school ID");
43424
44139
  }
43425
44140
  try {
43426
- value.building = new import_mongodb41.ObjectId(value.building);
44141
+ value.building = new import_mongodb43.ObjectId(value.building);
43427
44142
  } catch (error2) {
43428
- throw new import_nodejs_utils72.BadRequestError("Invalid building ID");
44143
+ throw new import_nodejs_utils75.BadRequestError("Invalid building ID");
43429
44144
  }
43430
44145
  return {
43431
44146
  _id: value._id ?? void 0,
@@ -43449,16 +44164,16 @@ function MBuildingUnit(value) {
43449
44164
  }
43450
44165
 
43451
44166
  // src/resources/building/building.repository.ts
43452
- var import_nodejs_utils73 = require("@eeplatform/nodejs-utils");
43453
- var import_mongodb42 = require("mongodb");
44167
+ var import_nodejs_utils76 = require("@eeplatform/nodejs-utils");
44168
+ var import_mongodb44 = require("mongodb");
43454
44169
  function useBuildingRepo() {
43455
- const db = import_nodejs_utils73.useAtlas.getDb();
44170
+ const db = import_nodejs_utils76.useAtlas.getDb();
43456
44171
  if (!db) {
43457
44172
  throw new Error("Unable to connect to server.");
43458
44173
  }
43459
44174
  const namespace_collection = "deped.buildings";
43460
44175
  const collection = db.collection(namespace_collection);
43461
- const { getCache, setCache, delNamespace } = (0, import_nodejs_utils73.useCache)(namespace_collection);
44176
+ const { getCache, setCache, delNamespace } = (0, import_nodejs_utils76.useCache)(namespace_collection);
43462
44177
  async function createIndexes() {
43463
44178
  try {
43464
44179
  await collection.createIndexes([
@@ -43477,16 +44192,16 @@ function useBuildingRepo() {
43477
44192
  delCachedData();
43478
44193
  return res.insertedId;
43479
44194
  } catch (error) {
43480
- import_nodejs_utils73.logger.log({
44195
+ import_nodejs_utils76.logger.log({
43481
44196
  level: "error",
43482
44197
  message: error.message
43483
44198
  });
43484
- if (error instanceof import_nodejs_utils73.AppError) {
44199
+ if (error instanceof import_nodejs_utils76.AppError) {
43485
44200
  throw error;
43486
44201
  } else {
43487
44202
  const isDuplicated = error.message.includes("duplicate");
43488
44203
  if (isDuplicated) {
43489
- throw new import_nodejs_utils73.BadRequestError("Building already exists.");
44204
+ throw new import_nodejs_utils76.BadRequestError("Building already exists.");
43490
44205
  }
43491
44206
  throw new Error("Failed to create building.");
43492
44207
  }
@@ -43494,9 +44209,9 @@ function useBuildingRepo() {
43494
44209
  }
43495
44210
  async function updateById(_id, value, session) {
43496
44211
  try {
43497
- _id = new import_mongodb42.ObjectId(_id);
44212
+ _id = new import_mongodb44.ObjectId(_id);
43498
44213
  } catch (error) {
43499
- throw new import_nodejs_utils73.BadRequestError(namespace_collection + " Invalid ID.");
44214
+ throw new import_nodejs_utils76.BadRequestError(namespace_collection + " Invalid ID.");
43500
44215
  }
43501
44216
  try {
43502
44217
  const res = await collection.updateOne(
@@ -43507,11 +44222,11 @@ function useBuildingRepo() {
43507
44222
  delCachedData();
43508
44223
  return res;
43509
44224
  } catch (error) {
43510
- import_nodejs_utils73.logger.log({
44225
+ import_nodejs_utils76.logger.log({
43511
44226
  level: "error",
43512
44227
  message: error.message
43513
44228
  });
43514
- if (error instanceof import_nodejs_utils73.AppError) {
44229
+ if (error instanceof import_nodejs_utils76.AppError) {
43515
44230
  throw error;
43516
44231
  } else {
43517
44232
  throw new Error("Failed to update building.");
@@ -43536,9 +44251,9 @@ function useBuildingRepo() {
43536
44251
  }
43537
44252
  if (school) {
43538
44253
  try {
43539
- query.school = new import_mongodb42.ObjectId(school);
44254
+ query.school = new import_mongodb44.ObjectId(school);
43540
44255
  } catch (error) {
43541
- throw new import_nodejs_utils73.BadRequestError("Invalid school ID.");
44256
+ throw new import_nodejs_utils76.BadRequestError("Invalid school ID.");
43542
44257
  }
43543
44258
  }
43544
44259
  const cacheParams = {
@@ -43552,15 +44267,15 @@ function useBuildingRepo() {
43552
44267
  cacheParams.school = school;
43553
44268
  if (status !== "active")
43554
44269
  cacheParams.status = status;
43555
- const cacheKey = (0, import_nodejs_utils73.makeCacheKey)(namespace_collection, cacheParams);
43556
- import_nodejs_utils73.logger.log({
44270
+ const cacheKey = (0, import_nodejs_utils76.makeCacheKey)(namespace_collection, cacheParams);
44271
+ import_nodejs_utils76.logger.log({
43557
44272
  level: "info",
43558
44273
  message: `Cache key for getAll buildings: ${cacheKey}`
43559
44274
  });
43560
44275
  try {
43561
44276
  const cached = await getCache(cacheKey);
43562
44277
  if (cached) {
43563
- import_nodejs_utils73.logger.log({
44278
+ import_nodejs_utils76.logger.log({
43564
44279
  level: "info",
43565
44280
  message: `Cache hit for getAll buildings: ${cacheKey}`
43566
44281
  });
@@ -43573,35 +44288,35 @@ function useBuildingRepo() {
43573
44288
  { $limit: limit }
43574
44289
  ]).toArray();
43575
44290
  const length = await collection.countDocuments(query);
43576
- const data = (0, import_nodejs_utils73.paginate)(items, page, limit, length);
44291
+ const data = (0, import_nodejs_utils76.paginate)(items, page, limit, length);
43577
44292
  setCache(cacheKey, data, 600).then(() => {
43578
- import_nodejs_utils73.logger.log({
44293
+ import_nodejs_utils76.logger.log({
43579
44294
  level: "info",
43580
44295
  message: `Cache set for getAll buildings: ${cacheKey}`
43581
44296
  });
43582
44297
  }).catch((err) => {
43583
- import_nodejs_utils73.logger.log({
44298
+ import_nodejs_utils76.logger.log({
43584
44299
  level: "error",
43585
44300
  message: `Failed to set cache for getAll buildings: ${err.message}`
43586
44301
  });
43587
44302
  });
43588
44303
  return data;
43589
44304
  } catch (error) {
43590
- import_nodejs_utils73.logger.log({ level: "error", message: `${error}` });
44305
+ import_nodejs_utils76.logger.log({ level: "error", message: `${error}` });
43591
44306
  throw error;
43592
44307
  }
43593
44308
  }
43594
44309
  async function getById(_id) {
43595
44310
  try {
43596
- _id = new import_mongodb42.ObjectId(_id);
44311
+ _id = new import_mongodb44.ObjectId(_id);
43597
44312
  } catch (error) {
43598
- throw new import_nodejs_utils73.BadRequestError(namespace_collection + " Invalid ID.");
44313
+ throw new import_nodejs_utils76.BadRequestError(namespace_collection + " Invalid ID.");
43599
44314
  }
43600
- const cacheKey = (0, import_nodejs_utils73.makeCacheKey)(namespace_collection, { _id: String(_id) });
44315
+ const cacheKey = (0, import_nodejs_utils76.makeCacheKey)(namespace_collection, { _id: String(_id) });
43601
44316
  try {
43602
44317
  const cached = await getCache(cacheKey);
43603
44318
  if (cached) {
43604
- import_nodejs_utils73.logger.log({
44319
+ import_nodejs_utils76.logger.log({
43605
44320
  level: "info",
43606
44321
  message: `Cache hit for getById building: ${cacheKey}`
43607
44322
  });
@@ -43611,30 +44326,30 @@ function useBuildingRepo() {
43611
44326
  _id
43612
44327
  });
43613
44328
  setCache(cacheKey, result, 300).then(() => {
43614
- import_nodejs_utils73.logger.log({
44329
+ import_nodejs_utils76.logger.log({
43615
44330
  level: "info",
43616
44331
  message: `Cache set for building by id: ${cacheKey}`
43617
44332
  });
43618
44333
  }).catch((err) => {
43619
- import_nodejs_utils73.logger.log({
44334
+ import_nodejs_utils76.logger.log({
43620
44335
  level: "error",
43621
44336
  message: `Failed to set cache for building by id: ${err.message}`
43622
44337
  });
43623
44338
  });
43624
44339
  return result;
43625
44340
  } catch (error) {
43626
- if (error instanceof import_nodejs_utils73.AppError) {
44341
+ if (error instanceof import_nodejs_utils76.AppError) {
43627
44342
  throw error;
43628
44343
  } else {
43629
- throw new import_nodejs_utils73.InternalServerError("Failed to get building.");
44344
+ throw new import_nodejs_utils76.InternalServerError("Failed to get building.");
43630
44345
  }
43631
44346
  }
43632
44347
  }
43633
44348
  async function deleteById(_id, session) {
43634
44349
  try {
43635
- _id = new import_mongodb42.ObjectId(_id);
44350
+ _id = new import_mongodb44.ObjectId(_id);
43636
44351
  } catch (error) {
43637
- throw new import_nodejs_utils73.BadRequestError(namespace_collection + " Invalid ID.");
44352
+ throw new import_nodejs_utils76.BadRequestError(namespace_collection + " Invalid ID.");
43638
44353
  }
43639
44354
  try {
43640
44355
  const res = await collection.updateOne(
@@ -43644,25 +44359,25 @@ function useBuildingRepo() {
43644
44359
  delCachedData();
43645
44360
  return res;
43646
44361
  } catch (error) {
43647
- import_nodejs_utils73.logger.log({
44362
+ import_nodejs_utils76.logger.log({
43648
44363
  level: "error",
43649
44364
  message: error.message
43650
44365
  });
43651
- if (error instanceof import_nodejs_utils73.AppError) {
44366
+ if (error instanceof import_nodejs_utils76.AppError) {
43652
44367
  throw error;
43653
44368
  } else {
43654
- throw new import_nodejs_utils73.InternalServerError("Failed to delete building.");
44369
+ throw new import_nodejs_utils76.InternalServerError("Failed to delete building.");
43655
44370
  }
43656
44371
  }
43657
44372
  }
43658
44373
  function delCachedData() {
43659
44374
  delNamespace().then(() => {
43660
- import_nodejs_utils73.logger.log({
44375
+ import_nodejs_utils76.logger.log({
43661
44376
  level: "info",
43662
44377
  message: `Cache namespace cleared for ${namespace_collection}`
43663
44378
  });
43664
44379
  }).catch((err) => {
43665
- import_nodejs_utils73.logger.log({
44380
+ import_nodejs_utils76.logger.log({
43666
44381
  level: "error",
43667
44382
  message: `Failed to clear cache namespace for ${namespace_collection}: ${err.message}`
43668
44383
  });
@@ -43679,19 +44394,19 @@ function useBuildingRepo() {
43679
44394
  }
43680
44395
 
43681
44396
  // src/resources/building/building.service.ts
43682
- var import_nodejs_utils75 = require("@eeplatform/nodejs-utils");
44397
+ var import_nodejs_utils78 = require("@eeplatform/nodejs-utils");
43683
44398
 
43684
44399
  // src/resources/building/building-unit.repository.ts
43685
- var import_nodejs_utils74 = require("@eeplatform/nodejs-utils");
43686
- var import_mongodb43 = require("mongodb");
44400
+ var import_nodejs_utils77 = require("@eeplatform/nodejs-utils");
44401
+ var import_mongodb45 = require("mongodb");
43687
44402
  function useBuildingUnitRepo() {
43688
- const db = import_nodejs_utils74.useAtlas.getDb();
44403
+ const db = import_nodejs_utils77.useAtlas.getDb();
43689
44404
  if (!db) {
43690
44405
  throw new Error("Unable to connect to server.");
43691
44406
  }
43692
44407
  const namespace_collection = "deped.building.units";
43693
44408
  const collection = db.collection(namespace_collection);
43694
- const { getCache, setCache, delNamespace } = (0, import_nodejs_utils74.useCache)(namespace_collection);
44409
+ const { getCache, setCache, delNamespace } = (0, import_nodejs_utils77.useCache)(namespace_collection);
43695
44410
  async function createIndexes() {
43696
44411
  try {
43697
44412
  await collection.createIndexes([
@@ -43719,12 +44434,12 @@ function useBuildingUnitRepo() {
43719
44434
  }
43720
44435
  function delCachedData() {
43721
44436
  delNamespace().then(() => {
43722
- import_nodejs_utils74.logger.log({
44437
+ import_nodejs_utils77.logger.log({
43723
44438
  level: "info",
43724
44439
  message: `Cache namespace cleared for ${namespace_collection}`
43725
44440
  });
43726
44441
  }).catch((err) => {
43727
- import_nodejs_utils74.logger.log({
44442
+ import_nodejs_utils77.logger.log({
43728
44443
  level: "error",
43729
44444
  message: `Failed to clear cache namespace for ${namespace_collection}: ${err.message}`
43730
44445
  });
@@ -43737,11 +44452,11 @@ function useBuildingUnitRepo() {
43737
44452
  delCachedData();
43738
44453
  return res.insertedId;
43739
44454
  } catch (error) {
43740
- import_nodejs_utils74.logger.log({
44455
+ import_nodejs_utils77.logger.log({
43741
44456
  level: "error",
43742
44457
  message: error.message
43743
44458
  });
43744
- if (error instanceof import_nodejs_utils74.AppError) {
44459
+ if (error instanceof import_nodejs_utils77.AppError) {
43745
44460
  throw error;
43746
44461
  } else {
43747
44462
  throw new Error("Failed to create building unit.");
@@ -43751,12 +44466,12 @@ function useBuildingUnitRepo() {
43751
44466
  async function updateById(_id, value, session) {
43752
44467
  const { error } = schemaUpdateOptions.validate(value);
43753
44468
  if (error) {
43754
- throw new import_nodejs_utils74.BadRequestError(error.message);
44469
+ throw new import_nodejs_utils77.BadRequestError(error.message);
43755
44470
  }
43756
44471
  try {
43757
- _id = new import_mongodb43.ObjectId(_id);
44472
+ _id = new import_mongodb45.ObjectId(_id);
43758
44473
  } catch (error2) {
43759
- throw new import_nodejs_utils74.BadRequestError(namespace_collection + " Invalid ID.");
44474
+ throw new import_nodejs_utils77.BadRequestError(namespace_collection + " Invalid ID.");
43760
44475
  }
43761
44476
  try {
43762
44477
  const res = await collection.updateOne(
@@ -43767,11 +44482,11 @@ function useBuildingUnitRepo() {
43767
44482
  delCachedData();
43768
44483
  return res;
43769
44484
  } catch (error2) {
43770
- import_nodejs_utils74.logger.log({
44485
+ import_nodejs_utils77.logger.log({
43771
44486
  level: "error",
43772
44487
  message: error2.message
43773
44488
  });
43774
- if (error2 instanceof import_nodejs_utils74.AppError) {
44489
+ if (error2 instanceof import_nodejs_utils77.AppError) {
43775
44490
  throw error2;
43776
44491
  } else {
43777
44492
  throw new Error("Failed to create building unit.");
@@ -43781,12 +44496,12 @@ function useBuildingUnitRepo() {
43781
44496
  async function updateByBuildingId(building, value, session) {
43782
44497
  const { error } = schemaUpdateOptions.validate(value);
43783
44498
  if (error) {
43784
- throw new import_nodejs_utils74.BadRequestError(error.message);
44499
+ throw new import_nodejs_utils77.BadRequestError(error.message);
43785
44500
  }
43786
44501
  try {
43787
- building = new import_mongodb43.ObjectId(building);
44502
+ building = new import_mongodb45.ObjectId(building);
43788
44503
  } catch (error2) {
43789
- throw new import_nodejs_utils74.BadRequestError("Invalid building ID.");
44504
+ throw new import_nodejs_utils77.BadRequestError("Invalid building ID.");
43790
44505
  }
43791
44506
  try {
43792
44507
  const res = await collection.updateMany(
@@ -43797,11 +44512,11 @@ function useBuildingUnitRepo() {
43797
44512
  delCachedData();
43798
44513
  return res;
43799
44514
  } catch (error2) {
43800
- import_nodejs_utils74.logger.log({
44515
+ import_nodejs_utils77.logger.log({
43801
44516
  level: "error",
43802
44517
  message: error2.message
43803
44518
  });
43804
- if (error2 instanceof import_nodejs_utils74.AppError) {
44519
+ if (error2 instanceof import_nodejs_utils77.AppError) {
43805
44520
  throw error2;
43806
44521
  } else {
43807
44522
  throw new Error("Failed to update building unit.");
@@ -43835,17 +44550,17 @@ function useBuildingUnitRepo() {
43835
44550
  }
43836
44551
  if (school) {
43837
44552
  try {
43838
- query.school = new import_mongodb43.ObjectId(school);
44553
+ query.school = new import_mongodb45.ObjectId(school);
43839
44554
  } catch (error) {
43840
- throw new import_nodejs_utils74.BadRequestError("Invalid school ID.");
44555
+ throw new import_nodejs_utils77.BadRequestError("Invalid school ID.");
43841
44556
  }
43842
44557
  cacheParams.school = school;
43843
44558
  }
43844
44559
  if (building) {
43845
44560
  try {
43846
- query.building = new import_mongodb43.ObjectId(building);
44561
+ query.building = new import_mongodb45.ObjectId(building);
43847
44562
  } catch (error) {
43848
- throw new import_nodejs_utils74.BadRequestError("Invalid building ID.");
44563
+ throw new import_nodejs_utils77.BadRequestError("Invalid building ID.");
43849
44564
  }
43850
44565
  cacheParams.building = building;
43851
44566
  }
@@ -43853,15 +44568,15 @@ function useBuildingUnitRepo() {
43853
44568
  query.type = type;
43854
44569
  cacheParams.type = type;
43855
44570
  }
43856
- const cacheKey = (0, import_nodejs_utils74.makeCacheKey)(namespace_collection, cacheParams);
43857
- import_nodejs_utils74.logger.log({
44571
+ const cacheKey = (0, import_nodejs_utils77.makeCacheKey)(namespace_collection, cacheParams);
44572
+ import_nodejs_utils77.logger.log({
43858
44573
  level: "info",
43859
44574
  message: `Cache key for getAll building units: ${cacheKey}`
43860
44575
  });
43861
44576
  try {
43862
44577
  const cached = await getCache(cacheKey);
43863
44578
  if (cached) {
43864
- import_nodejs_utils74.logger.log({
44579
+ import_nodejs_utils77.logger.log({
43865
44580
  level: "info",
43866
44581
  message: `Cache hit for getAll building units: ${cacheKey}`
43867
44582
  });
@@ -43874,21 +44589,21 @@ function useBuildingUnitRepo() {
43874
44589
  { $limit: limit }
43875
44590
  ]).toArray();
43876
44591
  const length = await collection.countDocuments(query);
43877
- const data = (0, import_nodejs_utils74.paginate)(items, page, limit, length);
44592
+ const data = (0, import_nodejs_utils77.paginate)(items, page, limit, length);
43878
44593
  setCache(cacheKey, data, 600).then(() => {
43879
- import_nodejs_utils74.logger.log({
44594
+ import_nodejs_utils77.logger.log({
43880
44595
  level: "info",
43881
44596
  message: `Cache set for getAll building units: ${cacheKey}`
43882
44597
  });
43883
44598
  }).catch((err) => {
43884
- import_nodejs_utils74.logger.log({
44599
+ import_nodejs_utils77.logger.log({
43885
44600
  level: "error",
43886
44601
  message: `Failed to set cache for getAll building units: ${err.message}`
43887
44602
  });
43888
44603
  });
43889
44604
  return data;
43890
44605
  } catch (error) {
43891
- import_nodejs_utils74.logger.log({ level: "error", message: `${error}` });
44606
+ import_nodejs_utils77.logger.log({ level: "error", message: `${error}` });
43892
44607
  throw error;
43893
44608
  }
43894
44609
  }
@@ -43901,10 +44616,10 @@ function useBuildingUnitRepo() {
43901
44616
  tag: "countByBuilding"
43902
44617
  };
43903
44618
  try {
43904
- query.building = new import_mongodb43.ObjectId(building);
44619
+ query.building = new import_mongodb45.ObjectId(building);
43905
44620
  cacheKeyOptions.building = String(building);
43906
44621
  } catch (error) {
43907
- throw new import_nodejs_utils74.BadRequestError("Invalid building ID.");
44622
+ throw new import_nodejs_utils77.BadRequestError("Invalid building ID.");
43908
44623
  }
43909
44624
  if (level) {
43910
44625
  query.level = level;
@@ -43913,21 +44628,21 @@ function useBuildingUnitRepo() {
43913
44628
  try {
43914
44629
  return await collection.countDocuments(query);
43915
44630
  } catch (error) {
43916
- import_nodejs_utils74.logger.log({ level: "error", message: `${error}` });
43917
- throw new import_nodejs_utils74.InternalServerError("Failed to count building units.");
44631
+ import_nodejs_utils77.logger.log({ level: "error", message: `${error}` });
44632
+ throw new import_nodejs_utils77.InternalServerError("Failed to count building units.");
43918
44633
  }
43919
44634
  }
43920
44635
  async function getById(_id) {
43921
44636
  try {
43922
- _id = new import_mongodb43.ObjectId(_id);
44637
+ _id = new import_mongodb45.ObjectId(_id);
43923
44638
  } catch (error) {
43924
- throw new import_nodejs_utils74.BadRequestError(namespace_collection + " Invalid ID.");
44639
+ throw new import_nodejs_utils77.BadRequestError(namespace_collection + " Invalid ID.");
43925
44640
  }
43926
- const cacheKey = (0, import_nodejs_utils74.makeCacheKey)(namespace_collection, { _id: String(_id) });
44641
+ const cacheKey = (0, import_nodejs_utils77.makeCacheKey)(namespace_collection, { _id: String(_id) });
43927
44642
  try {
43928
44643
  const cached = await getCache(cacheKey);
43929
44644
  if (cached) {
43930
- import_nodejs_utils74.logger.log({
44645
+ import_nodejs_utils77.logger.log({
43931
44646
  level: "info",
43932
44647
  message: `Cache hit for getById building unit: ${cacheKey}`
43933
44648
  });
@@ -43938,42 +44653,42 @@ function useBuildingUnitRepo() {
43938
44653
  deletedAt: { $in: ["", null] }
43939
44654
  });
43940
44655
  if (!result) {
43941
- throw new import_nodejs_utils74.BadRequestError("Building unit not found.");
44656
+ throw new import_nodejs_utils77.BadRequestError("Building unit not found.");
43942
44657
  }
43943
44658
  setCache(cacheKey, result, 300).then(() => {
43944
- import_nodejs_utils74.logger.log({
44659
+ import_nodejs_utils77.logger.log({
43945
44660
  level: "info",
43946
44661
  message: `Cache set for building unit by id: ${cacheKey}`
43947
44662
  });
43948
44663
  }).catch((err) => {
43949
- import_nodejs_utils74.logger.log({
44664
+ import_nodejs_utils77.logger.log({
43950
44665
  level: "error",
43951
44666
  message: `Failed to set cache for building unit by id: ${err.message}`
43952
44667
  });
43953
44668
  });
43954
44669
  return result;
43955
44670
  } catch (error) {
43956
- if (error instanceof import_nodejs_utils74.AppError) {
44671
+ if (error instanceof import_nodejs_utils77.AppError) {
43957
44672
  throw error;
43958
44673
  } else {
43959
- throw new import_nodejs_utils74.InternalServerError("Failed to get building unit.");
44674
+ throw new import_nodejs_utils77.InternalServerError("Failed to get building unit.");
43960
44675
  }
43961
44676
  }
43962
44677
  }
43963
44678
  async function getByBuildingLevel(building, level) {
43964
44679
  try {
43965
- building = new import_mongodb43.ObjectId(building);
44680
+ building = new import_mongodb45.ObjectId(building);
43966
44681
  } catch (error) {
43967
- throw new import_nodejs_utils74.BadRequestError("Invalid building ID.");
44682
+ throw new import_nodejs_utils77.BadRequestError("Invalid building ID.");
43968
44683
  }
43969
- const cacheKey = (0, import_nodejs_utils74.makeCacheKey)(namespace_collection, {
44684
+ const cacheKey = (0, import_nodejs_utils77.makeCacheKey)(namespace_collection, {
43970
44685
  building: String(building),
43971
44686
  level
43972
44687
  });
43973
44688
  try {
43974
44689
  const cached = await getCache(cacheKey);
43975
44690
  if (cached) {
43976
- import_nodejs_utils74.logger.log({
44691
+ import_nodejs_utils77.logger.log({
43977
44692
  level: "info",
43978
44693
  message: `Cache hit for getById building unit: ${cacheKey}`
43979
44694
  });
@@ -43985,38 +44700,38 @@ function useBuildingUnitRepo() {
43985
44700
  status: "active"
43986
44701
  });
43987
44702
  setCache(cacheKey, result, 300).then(() => {
43988
- import_nodejs_utils74.logger.log({
44703
+ import_nodejs_utils77.logger.log({
43989
44704
  level: "info",
43990
44705
  message: `Cache set for building unit by id: ${cacheKey}`
43991
44706
  });
43992
44707
  }).catch((err) => {
43993
- import_nodejs_utils74.logger.log({
44708
+ import_nodejs_utils77.logger.log({
43994
44709
  level: "error",
43995
44710
  message: `Failed to set cache for building unit by id: ${err.message}`
43996
44711
  });
43997
44712
  });
43998
44713
  return result;
43999
44714
  } catch (error) {
44000
- if (error instanceof import_nodejs_utils74.AppError) {
44715
+ if (error instanceof import_nodejs_utils77.AppError) {
44001
44716
  throw error;
44002
44717
  } else {
44003
- throw new import_nodejs_utils74.InternalServerError("Failed to get building unit.");
44718
+ throw new import_nodejs_utils77.InternalServerError("Failed to get building unit.");
44004
44719
  }
44005
44720
  }
44006
44721
  }
44007
44722
  async function getByBuilding(building) {
44008
44723
  try {
44009
- building = new import_mongodb43.ObjectId(building);
44724
+ building = new import_mongodb45.ObjectId(building);
44010
44725
  } catch (error) {
44011
- throw new import_nodejs_utils74.BadRequestError("Invalid building ID.");
44726
+ throw new import_nodejs_utils77.BadRequestError("Invalid building ID.");
44012
44727
  }
44013
- const cacheKey = (0, import_nodejs_utils74.makeCacheKey)(namespace_collection, {
44728
+ const cacheKey = (0, import_nodejs_utils77.makeCacheKey)(namespace_collection, {
44014
44729
  building: String(building)
44015
44730
  });
44016
44731
  try {
44017
44732
  const cached = await getCache(cacheKey);
44018
44733
  if (cached) {
44019
- import_nodejs_utils74.logger.log({
44734
+ import_nodejs_utils77.logger.log({
44020
44735
  level: "info",
44021
44736
  message: `Cache hit for getById building unit: ${cacheKey}`
44022
44737
  });
@@ -44027,30 +44742,30 @@ function useBuildingUnitRepo() {
44027
44742
  status: "active"
44028
44743
  });
44029
44744
  setCache(cacheKey, result, 300).then(() => {
44030
- import_nodejs_utils74.logger.log({
44745
+ import_nodejs_utils77.logger.log({
44031
44746
  level: "info",
44032
44747
  message: `Cache set for building unit by id: ${cacheKey}`
44033
44748
  });
44034
44749
  }).catch((err) => {
44035
- import_nodejs_utils74.logger.log({
44750
+ import_nodejs_utils77.logger.log({
44036
44751
  level: "error",
44037
44752
  message: `Failed to set cache for building unit by id: ${err.message}`
44038
44753
  });
44039
44754
  });
44040
44755
  return result;
44041
44756
  } catch (error) {
44042
- if (error instanceof import_nodejs_utils74.AppError) {
44757
+ if (error instanceof import_nodejs_utils77.AppError) {
44043
44758
  throw error;
44044
44759
  } else {
44045
- throw new import_nodejs_utils74.InternalServerError("Failed to get building unit.");
44760
+ throw new import_nodejs_utils77.InternalServerError("Failed to get building unit.");
44046
44761
  }
44047
44762
  }
44048
44763
  }
44049
44764
  async function deleteById(_id, session) {
44050
44765
  try {
44051
- _id = new import_mongodb43.ObjectId(_id);
44766
+ _id = new import_mongodb45.ObjectId(_id);
44052
44767
  } catch (error) {
44053
- throw new import_nodejs_utils74.BadRequestError(namespace_collection + " Invalid ID.");
44768
+ throw new import_nodejs_utils77.BadRequestError(namespace_collection + " Invalid ID.");
44054
44769
  }
44055
44770
  try {
44056
44771
  const res = await collection.updateOne(
@@ -44061,11 +44776,11 @@ function useBuildingUnitRepo() {
44061
44776
  delCachedData();
44062
44777
  return "Room/Facility deleted successfully.";
44063
44778
  } catch (error) {
44064
- import_nodejs_utils74.logger.log({
44779
+ import_nodejs_utils77.logger.log({
44065
44780
  level: "error",
44066
44781
  message: error.message
44067
44782
  });
44068
- if (error instanceof import_nodejs_utils74.AppError) {
44783
+ if (error instanceof import_nodejs_utils77.AppError) {
44069
44784
  throw error;
44070
44785
  } else {
44071
44786
  throw new Error("Failed to deleted room/facility.");
@@ -44096,16 +44811,16 @@ function useBuildingService() {
44096
44811
  const { getByBuildingLevel, getByBuilding, updateByBuildingId } = useBuildingUnitRepo();
44097
44812
  async function updateById(id, data) {
44098
44813
  data.levels = Number(data.levels);
44099
- const session = import_nodejs_utils75.useAtlas.getClient()?.startSession();
44814
+ const session = import_nodejs_utils78.useAtlas.getClient()?.startSession();
44100
44815
  try {
44101
44816
  const building = await _getById(id);
44102
44817
  if (!building) {
44103
- throw new import_nodejs_utils75.NotFoundError("Building not found.");
44818
+ throw new import_nodejs_utils78.NotFoundError("Building not found.");
44104
44819
  }
44105
44820
  if (data.levels < building.levels) {
44106
44821
  const unit = await getByBuildingLevel(id, building.levels);
44107
44822
  if (unit) {
44108
- throw new import_nodejs_utils75.BadRequestError(
44823
+ throw new import_nodejs_utils78.BadRequestError(
44109
44824
  "Cannot reduce floors, there are existing building units at higher floors."
44110
44825
  );
44111
44826
  }
@@ -44127,7 +44842,7 @@ function useBuildingService() {
44127
44842
  async function deleteById(id) {
44128
44843
  const building = await getByBuilding(id);
44129
44844
  if (building) {
44130
- throw new import_nodejs_utils75.BadRequestError(
44845
+ throw new import_nodejs_utils78.BadRequestError(
44131
44846
  "Cannot delete building with existing room/facility. Please delete room/facility first."
44132
44847
  );
44133
44848
  }
@@ -44145,24 +44860,24 @@ function useBuildingService() {
44145
44860
  }
44146
44861
 
44147
44862
  // src/resources/building/building.controller.ts
44148
- var import_nodejs_utils76 = require("@eeplatform/nodejs-utils");
44149
- var import_joi46 = __toESM(require("joi"));
44863
+ var import_nodejs_utils79 = require("@eeplatform/nodejs-utils");
44864
+ var import_joi48 = __toESM(require("joi"));
44150
44865
  function useBuildingController() {
44151
44866
  const { getAll: _getAll, getById: _getById, add: _add } = useBuildingRepo();
44152
44867
  const { updateById: _updateById, deleteById: _deleteById } = useBuildingService();
44153
44868
  async function createBuilding(req, res, next) {
44154
44869
  const value = req.body;
44155
- const validation = import_joi46.default.object({
44156
- name: import_joi46.default.string().required(),
44157
- school: import_joi46.default.string().hex().required(),
44158
- levels: import_joi46.default.number().integer().min(1).required(),
44159
- serial: import_joi46.default.string().optional().allow("", null),
44160
- status: import_joi46.default.string().optional().allow("", null)
44870
+ const validation = import_joi48.default.object({
44871
+ name: import_joi48.default.string().required(),
44872
+ school: import_joi48.default.string().hex().required(),
44873
+ levels: import_joi48.default.number().integer().min(1).required(),
44874
+ serial: import_joi48.default.string().optional().allow("", null),
44875
+ status: import_joi48.default.string().optional().allow("", null)
44161
44876
  });
44162
44877
  const { error } = validation.validate(value);
44163
44878
  if (error) {
44164
- next(new import_nodejs_utils76.BadRequestError(error.message));
44165
- import_nodejs_utils76.logger.info(`Controller: ${error.message}`);
44879
+ next(new import_nodejs_utils79.BadRequestError(error.message));
44880
+ import_nodejs_utils79.logger.info(`Controller: ${error.message}`);
44166
44881
  return;
44167
44882
  }
44168
44883
  try {
@@ -44176,18 +44891,18 @@ function useBuildingController() {
44176
44891
  async function updateById(req, res, next) {
44177
44892
  const value = req.body;
44178
44893
  const id = req.params.id ?? "";
44179
- const validation = import_joi46.default.object({
44180
- id: import_joi46.default.string().hex().required(),
44181
- value: import_joi46.default.object({
44182
- name: import_joi46.default.string().required(),
44183
- serial: import_joi46.default.string().optional().allow("", null),
44184
- levels: import_joi46.default.number().integer().min(1).required()
44894
+ const validation = import_joi48.default.object({
44895
+ id: import_joi48.default.string().hex().required(),
44896
+ value: import_joi48.default.object({
44897
+ name: import_joi48.default.string().required(),
44898
+ serial: import_joi48.default.string().optional().allow("", null),
44899
+ levels: import_joi48.default.number().integer().min(1).required()
44185
44900
  })
44186
44901
  });
44187
44902
  const { error } = validation.validate({ id, value });
44188
44903
  if (error) {
44189
- next(new import_nodejs_utils76.BadRequestError(error.message));
44190
- import_nodejs_utils76.logger.info(`Controller: ${error.message}`);
44904
+ next(new import_nodejs_utils79.BadRequestError(error.message));
44905
+ import_nodejs_utils79.logger.info(`Controller: ${error.message}`);
44191
44906
  return;
44192
44907
  }
44193
44908
  try {
@@ -44200,16 +44915,16 @@ function useBuildingController() {
44200
44915
  }
44201
44916
  async function getAll(req, res, next) {
44202
44917
  const query = req.query;
44203
- const validation = import_joi46.default.object({
44204
- page: import_joi46.default.number().min(1).optional().allow("", null),
44205
- limit: import_joi46.default.number().min(1).optional().allow("", null),
44206
- search: import_joi46.default.string().optional().allow("", null),
44207
- school: import_joi46.default.string().hex().optional().allow("", null),
44208
- status: import_joi46.default.string().optional().allow("", null)
44918
+ const validation = import_joi48.default.object({
44919
+ page: import_joi48.default.number().min(1).optional().allow("", null),
44920
+ limit: import_joi48.default.number().min(1).optional().allow("", null),
44921
+ search: import_joi48.default.string().optional().allow("", null),
44922
+ school: import_joi48.default.string().hex().optional().allow("", null),
44923
+ status: import_joi48.default.string().optional().allow("", null)
44209
44924
  });
44210
44925
  const { error } = validation.validate(query);
44211
44926
  if (error) {
44212
- next(new import_nodejs_utils76.BadRequestError(error.message));
44927
+ next(new import_nodejs_utils79.BadRequestError(error.message));
44213
44928
  return;
44214
44929
  }
44215
44930
  const page = parseInt(req.query.page) ?? 1;
@@ -44243,12 +44958,12 @@ function useBuildingController() {
44243
44958
  }
44244
44959
  async function getById(req, res, next) {
44245
44960
  const id = req.params.id;
44246
- const validation = import_joi46.default.object({
44247
- id: import_joi46.default.string().hex().required()
44961
+ const validation = import_joi48.default.object({
44962
+ id: import_joi48.default.string().hex().required()
44248
44963
  });
44249
44964
  const { error } = validation.validate({ id });
44250
44965
  if (error) {
44251
- next(new import_nodejs_utils76.BadRequestError(error.message));
44966
+ next(new import_nodejs_utils79.BadRequestError(error.message));
44252
44967
  return;
44253
44968
  }
44254
44969
  try {
@@ -44264,12 +44979,12 @@ function useBuildingController() {
44264
44979
  }
44265
44980
  async function deleteById(req, res, next) {
44266
44981
  const id = req.params.id;
44267
- const validation = import_joi46.default.object({
44268
- id: import_joi46.default.string().hex().required()
44982
+ const validation = import_joi48.default.object({
44983
+ id: import_joi48.default.string().hex().required()
44269
44984
  });
44270
44985
  const { error } = validation.validate({ id });
44271
44986
  if (error) {
44272
- next(new import_nodejs_utils76.BadRequestError(error.message));
44987
+ next(new import_nodejs_utils79.BadRequestError(error.message));
44273
44988
  return;
44274
44989
  }
44275
44990
  try {
@@ -44290,7 +45005,7 @@ function useBuildingController() {
44290
45005
  }
44291
45006
 
44292
45007
  // src/resources/building/building-unit.service.ts
44293
- var import_nodejs_utils77 = require("@eeplatform/nodejs-utils");
45008
+ var import_nodejs_utils80 = require("@eeplatform/nodejs-utils");
44294
45009
  function useBuildingUnitService() {
44295
45010
  const {
44296
45011
  add: _add,
@@ -44298,7 +45013,7 @@ function useBuildingUnitService() {
44298
45013
  deleteById: _deleteById
44299
45014
  } = useBuildingUnitRepo();
44300
45015
  async function add(value) {
44301
- const session = import_nodejs_utils77.useAtlas.getClient()?.startSession();
45016
+ const session = import_nodejs_utils80.useAtlas.getClient()?.startSession();
44302
45017
  if (!session) {
44303
45018
  throw new Error("Unable to start session for building unit service.");
44304
45019
  }
@@ -44349,8 +45064,8 @@ function useBuildingUnitService() {
44349
45064
  }
44350
45065
 
44351
45066
  // src/resources/building/building-unit.controller.ts
44352
- var import_nodejs_utils78 = require("@eeplatform/nodejs-utils");
44353
- var import_joi47 = __toESM(require("joi"));
45067
+ var import_nodejs_utils81 = require("@eeplatform/nodejs-utils");
45068
+ var import_joi49 = __toESM(require("joi"));
44354
45069
  function useBuildingUnitController() {
44355
45070
  const {
44356
45071
  getAll: _getAll,
@@ -44360,27 +45075,27 @@ function useBuildingUnitController() {
44360
45075
  const { add: _add, deleteById: _deleteById } = useBuildingUnitService();
44361
45076
  async function add(req, res, next) {
44362
45077
  const data = req.body;
44363
- const validation = import_joi47.default.object({
44364
- building: import_joi47.default.object({
44365
- school: import_joi47.default.string().hex().required(),
44366
- name: import_joi47.default.string().optional().allow("", null),
44367
- building: import_joi47.default.string().hex().required(),
44368
- buildingName: import_joi47.default.string().optional().allow("", null),
44369
- level: import_joi47.default.number().integer().min(1).required(),
44370
- category: import_joi47.default.string().required(),
44371
- type: import_joi47.default.string().required(),
44372
- seating_capacity: import_joi47.default.number().integer().min(0).required(),
44373
- standing_capacity: import_joi47.default.number().integer().min(0).required(),
44374
- description: import_joi47.default.string().optional().allow("", null),
44375
- unit_of_measurement: import_joi47.default.string().valid("sqm").required(),
44376
- area: import_joi47.default.number().positive().required(),
44377
- status: import_joi47.default.string().optional().allow("", null)
45078
+ const validation = import_joi49.default.object({
45079
+ building: import_joi49.default.object({
45080
+ school: import_joi49.default.string().hex().required(),
45081
+ name: import_joi49.default.string().optional().allow("", null),
45082
+ building: import_joi49.default.string().hex().required(),
45083
+ buildingName: import_joi49.default.string().optional().allow("", null),
45084
+ level: import_joi49.default.number().integer().min(1).required(),
45085
+ category: import_joi49.default.string().required(),
45086
+ type: import_joi49.default.string().required(),
45087
+ seating_capacity: import_joi49.default.number().integer().min(0).required(),
45088
+ standing_capacity: import_joi49.default.number().integer().min(0).required(),
45089
+ description: import_joi49.default.string().optional().allow("", null),
45090
+ unit_of_measurement: import_joi49.default.string().valid("sqm").required(),
45091
+ area: import_joi49.default.number().positive().required(),
45092
+ status: import_joi49.default.string().optional().allow("", null)
44378
45093
  }),
44379
- qty: import_joi47.default.number().integer().min(1).max(20).optional().default(1)
45094
+ qty: import_joi49.default.number().integer().min(1).max(20).optional().default(1)
44380
45095
  });
44381
45096
  const { error } = validation.validate(data);
44382
45097
  if (error) {
44383
- next(new import_nodejs_utils78.BadRequestError(error.message));
45098
+ next(new import_nodejs_utils81.BadRequestError(error.message));
44384
45099
  return;
44385
45100
  }
44386
45101
  try {
@@ -44396,13 +45111,13 @@ function useBuildingUnitController() {
44396
45111
  async function updateById(req, res, next) {
44397
45112
  const data = req.body;
44398
45113
  const id = req.params.id ?? "";
44399
- const validation = import_joi47.default.object({
44400
- id: import_joi47.default.string().hex().required(),
45114
+ const validation = import_joi49.default.object({
45115
+ id: import_joi49.default.string().hex().required(),
44401
45116
  value: schemaUpdateOptions
44402
45117
  });
44403
45118
  const { error } = validation.validate({ id, value: data });
44404
45119
  if (error) {
44405
- next(new import_nodejs_utils78.BadRequestError(error.message));
45120
+ next(new import_nodejs_utils81.BadRequestError(error.message));
44406
45121
  return;
44407
45122
  }
44408
45123
  try {
@@ -44417,18 +45132,18 @@ function useBuildingUnitController() {
44417
45132
  }
44418
45133
  async function getAll(req, res, next) {
44419
45134
  const query = req.query;
44420
- const validation = import_joi47.default.object({
44421
- page: import_joi47.default.number().min(1).optional().allow("", null),
44422
- limit: import_joi47.default.number().min(1).optional().allow("", null),
44423
- search: import_joi47.default.string().optional().allow("", null),
44424
- school: import_joi47.default.string().hex().optional().allow("", null),
44425
- building: import_joi47.default.string().hex().optional().allow("", null),
44426
- status: import_joi47.default.string().optional().allow("", null),
44427
- type: import_joi47.default.string().optional().allow("", null)
45135
+ const validation = import_joi49.default.object({
45136
+ page: import_joi49.default.number().min(1).optional().allow("", null),
45137
+ limit: import_joi49.default.number().min(1).optional().allow("", null),
45138
+ search: import_joi49.default.string().optional().allow("", null),
45139
+ school: import_joi49.default.string().hex().optional().allow("", null),
45140
+ building: import_joi49.default.string().hex().optional().allow("", null),
45141
+ status: import_joi49.default.string().optional().allow("", null),
45142
+ type: import_joi49.default.string().optional().allow("", null)
44428
45143
  });
44429
45144
  const { error } = validation.validate(query);
44430
45145
  if (error) {
44431
- next(new import_nodejs_utils78.BadRequestError(error.message));
45146
+ next(new import_nodejs_utils81.BadRequestError(error.message));
44432
45147
  return;
44433
45148
  }
44434
45149
  const page = parseInt(req.query.page) ?? 1;
@@ -44466,12 +45181,12 @@ function useBuildingUnitController() {
44466
45181
  }
44467
45182
  async function getById(req, res, next) {
44468
45183
  const id = req.params.id;
44469
- const validation = import_joi47.default.object({
44470
- id: import_joi47.default.string().hex().required()
45184
+ const validation = import_joi49.default.object({
45185
+ id: import_joi49.default.string().hex().required()
44471
45186
  });
44472
45187
  const { error } = validation.validate({ id });
44473
45188
  if (error) {
44474
- next(new import_nodejs_utils78.BadRequestError(error.message));
45189
+ next(new import_nodejs_utils81.BadRequestError(error.message));
44475
45190
  return;
44476
45191
  }
44477
45192
  try {
@@ -44487,12 +45202,12 @@ function useBuildingUnitController() {
44487
45202
  }
44488
45203
  async function deleteById(req, res, next) {
44489
45204
  const id = req.params.id;
44490
- const validation = import_joi47.default.object({
44491
- id: import_joi47.default.string().hex().required()
45205
+ const validation = import_joi49.default.object({
45206
+ id: import_joi49.default.string().hex().required()
44492
45207
  });
44493
45208
  const { error } = validation.validate({ id });
44494
45209
  if (error) {
44495
- next(new import_nodejs_utils78.BadRequestError(error.message));
45210
+ next(new import_nodejs_utils81.BadRequestError(error.message));
44496
45211
  return;
44497
45212
  }
44498
45213
  try {
@@ -44512,6 +45227,579 @@ function useBuildingUnitController() {
44512
45227
  };
44513
45228
  }
44514
45229
 
45230
+ // src/resources/kindergarten-domain/kindergarten.domain.model.ts
45231
+ var import_nodejs_utils82 = require("@eeplatform/nodejs-utils");
45232
+ var import_joi50 = __toESM(require("joi"));
45233
+ var import_mongodb46 = require("mongodb");
45234
+ var schemaKindergartenDomain = import_joi50.default.object({
45235
+ _id: import_joi50.default.string().hex().optional().allow(null, ""),
45236
+ title: import_joi50.default.string().max(100).required(),
45237
+ school: import_joi50.default.string().hex().required(),
45238
+ status: import_joi50.default.string().valid("active", "inactive", "deleted").optional(),
45239
+ createdAt: import_joi50.default.string().isoDate().optional().allow(null, ""),
45240
+ updatedAt: import_joi50.default.string().isoDate().optional().allow(null, ""),
45241
+ deletedAt: import_joi50.default.string().isoDate().optional().allow(null, "")
45242
+ });
45243
+ function modelKindergartenDomain(value) {
45244
+ const { error } = schemaKindergartenDomain.validate(value);
45245
+ if (error) {
45246
+ throw new import_nodejs_utils82.BadRequestError(
45247
+ `Invalid kindergarten domain data: ${error.message}`
45248
+ );
45249
+ }
45250
+ if (value._id && typeof value._id === "string") {
45251
+ try {
45252
+ value._id = new import_mongodb46.ObjectId(value._id);
45253
+ } catch (error2) {
45254
+ throw new Error("Invalid _id.");
45255
+ }
45256
+ }
45257
+ if (value.school && typeof value.school === "string") {
45258
+ try {
45259
+ value.school = new import_mongodb46.ObjectId(value.school);
45260
+ } catch (error2) {
45261
+ throw new Error("Invalid school.");
45262
+ }
45263
+ }
45264
+ return {
45265
+ _id: value._id,
45266
+ title: value.title,
45267
+ school: value.school,
45268
+ status: value.status ?? "active",
45269
+ createdAt: value.createdAt ?? (/* @__PURE__ */ new Date()).toISOString(),
45270
+ updatedAt: value.updatedAt ?? "",
45271
+ deletedAt: value.deletedAt ?? ""
45272
+ };
45273
+ }
45274
+
45275
+ // src/resources/kindergarten-domain/kindergarten.domain.repository.ts
45276
+ var import_nodejs_utils83 = require("@eeplatform/nodejs-utils");
45277
+ var import_mongodb47 = require("mongodb");
45278
+ function useKindergartenDomainRepo() {
45279
+ const db = import_nodejs_utils83.useAtlas.getDb();
45280
+ if (!db) {
45281
+ throw new Error("Unable to connect to server.");
45282
+ }
45283
+ const namespace_collection = "deped.kindergarten.domains";
45284
+ const collection = db.collection(namespace_collection);
45285
+ const { getCache, setCache, delNamespace } = (0, import_nodejs_utils83.useCache)(namespace_collection);
45286
+ async function createIndexes() {
45287
+ try {
45288
+ await collection.createIndexes([
45289
+ { key: { title: 1 } },
45290
+ { key: { school: 1 } },
45291
+ { key: { createdAt: 1 } },
45292
+ { key: { createdBy: 1 } },
45293
+ { key: { title: "text" } },
45294
+ {
45295
+ key: { title: 1, school: 1, status: 1 },
45296
+ unique: true,
45297
+ name: "unique_kindergarten_domain"
45298
+ }
45299
+ ]);
45300
+ } catch (error) {
45301
+ throw new Error("Failed to create index on kindergarten domains.");
45302
+ }
45303
+ }
45304
+ function delCachedData() {
45305
+ delNamespace().then(() => {
45306
+ import_nodejs_utils83.logger.log({
45307
+ level: "info",
45308
+ message: `Cache namespace cleared for ${namespace_collection}`
45309
+ });
45310
+ }).catch((err) => {
45311
+ import_nodejs_utils83.logger.log({
45312
+ level: "error",
45313
+ message: `Failed to clear cache namespace for ${namespace_collection}: ${err.message}`
45314
+ });
45315
+ });
45316
+ }
45317
+ async function add(value, session) {
45318
+ try {
45319
+ value = modelKindergartenDomain(value);
45320
+ const res = await collection.insertOne(value, { session });
45321
+ delCachedData();
45322
+ return res.insertedId;
45323
+ } catch (error) {
45324
+ import_nodejs_utils83.logger.log({
45325
+ level: "error",
45326
+ message: error.message
45327
+ });
45328
+ if (error instanceof import_nodejs_utils83.AppError) {
45329
+ throw error;
45330
+ } else {
45331
+ const isDuplicated = error.message.includes("duplicate");
45332
+ if (isDuplicated) {
45333
+ throw new import_nodejs_utils83.BadRequestError("Kindergarten domain already exists.");
45334
+ }
45335
+ throw new Error("Failed to create kindergarten domain.");
45336
+ }
45337
+ }
45338
+ }
45339
+ async function getAll({
45340
+ search = "",
45341
+ page = 1,
45342
+ limit = 10,
45343
+ sort = {},
45344
+ status = "active",
45345
+ createdBy,
45346
+ school = ""
45347
+ } = {}) {
45348
+ page = page > 0 ? page - 1 : 0;
45349
+ const query = {
45350
+ deletedAt: { $in: ["", null] },
45351
+ status
45352
+ };
45353
+ sort = Object.keys(sort).length > 0 ? sort : { _id: 1 };
45354
+ const cacheKeyOptions = {
45355
+ status,
45356
+ page,
45357
+ limit,
45358
+ sort: JSON.stringify(sort)
45359
+ };
45360
+ if (createdBy) {
45361
+ try {
45362
+ query.createdBy = new import_mongodb47.ObjectId(createdBy);
45363
+ } catch (error) {
45364
+ throw new import_nodejs_utils83.BadRequestError("Invalid createdBy ID.");
45365
+ }
45366
+ cacheKeyOptions.createdBy = createdBy;
45367
+ }
45368
+ if (search) {
45369
+ query.$text = { $search: search };
45370
+ cacheKeyOptions.search = search;
45371
+ }
45372
+ if (school) {
45373
+ try {
45374
+ query.school = new import_mongodb47.ObjectId(school);
45375
+ } catch (error) {
45376
+ throw new import_nodejs_utils83.BadRequestError("Invalid school ID.");
45377
+ }
45378
+ cacheKeyOptions.school = school;
45379
+ }
45380
+ const cacheKey = (0, import_nodejs_utils83.makeCacheKey)(namespace_collection, cacheKeyOptions);
45381
+ import_nodejs_utils83.logger.log({
45382
+ level: "info",
45383
+ message: `Cache key for getAll kindergarten domains: ${cacheKey}`
45384
+ });
45385
+ try {
45386
+ const cached = await getCache(cacheKey);
45387
+ if (cached) {
45388
+ import_nodejs_utils83.logger.log({
45389
+ level: "info",
45390
+ message: `Cache hit for getAll kindergarten domains: ${cacheKey}`
45391
+ });
45392
+ return cached;
45393
+ }
45394
+ const items = await collection.aggregate([
45395
+ { $match: query },
45396
+ { $sort: sort },
45397
+ { $skip: page * limit },
45398
+ { $limit: limit }
45399
+ ]).toArray();
45400
+ const total = await collection.countDocuments(query);
45401
+ const result = (0, import_nodejs_utils83.paginate)(items, total, page, limit);
45402
+ setCache(cacheKey, result, 300).then(() => {
45403
+ import_nodejs_utils83.logger.log({
45404
+ level: "info",
45405
+ message: `Cache set for getAll kindergarten domains: ${cacheKey}`
45406
+ });
45407
+ }).catch((err) => {
45408
+ import_nodejs_utils83.logger.log({
45409
+ level: "error",
45410
+ message: `Failed to set cache for getAll kindergarten domains: ${err.message}`
45411
+ });
45412
+ });
45413
+ return result;
45414
+ } catch (error) {
45415
+ if (error instanceof import_nodejs_utils83.AppError) {
45416
+ throw error;
45417
+ } else {
45418
+ throw new import_nodejs_utils83.InternalServerError("Failed to get kindergarten domains.");
45419
+ }
45420
+ }
45421
+ }
45422
+ async function getById(_id) {
45423
+ try {
45424
+ _id = new import_mongodb47.ObjectId(_id);
45425
+ } catch (error) {
45426
+ throw new import_nodejs_utils83.BadRequestError(namespace_collection + " Invalid ID.");
45427
+ }
45428
+ const cacheKey = (0, import_nodejs_utils83.makeCacheKey)(namespace_collection, {
45429
+ _id: _id.toString()
45430
+ });
45431
+ import_nodejs_utils83.logger.log({
45432
+ level: "info",
45433
+ message: `Cache key for getById kindergarten domain: ${cacheKey}`
45434
+ });
45435
+ try {
45436
+ const cached = await getCache(cacheKey);
45437
+ if (cached) {
45438
+ import_nodejs_utils83.logger.log({
45439
+ level: "info",
45440
+ message: `Cache hit for getById kindergarten domain: ${cacheKey}`
45441
+ });
45442
+ return cached;
45443
+ }
45444
+ const result = await collection.findOne({
45445
+ _id,
45446
+ deletedAt: { $in: ["", null] }
45447
+ });
45448
+ if (!result) {
45449
+ throw new import_nodejs_utils83.BadRequestError("Kindergarten domain not found.");
45450
+ }
45451
+ setCache(cacheKey, result, 300).then(() => {
45452
+ import_nodejs_utils83.logger.log({
45453
+ level: "info",
45454
+ message: `Cache set for getById kindergarten domain: ${cacheKey}`
45455
+ });
45456
+ }).catch((err) => {
45457
+ import_nodejs_utils83.logger.log({
45458
+ level: "error",
45459
+ message: `Failed to set cache for getById kindergarten domain: ${err.message}`
45460
+ });
45461
+ });
45462
+ return result;
45463
+ } catch (error) {
45464
+ if (error instanceof import_nodejs_utils83.AppError) {
45465
+ throw error;
45466
+ } else {
45467
+ throw new import_nodejs_utils83.InternalServerError("Failed to get kindergarten domain.");
45468
+ }
45469
+ }
45470
+ }
45471
+ async function getBySchool(school) {
45472
+ try {
45473
+ school = new import_mongodb47.ObjectId(school);
45474
+ } catch (error) {
45475
+ throw new import_nodejs_utils83.BadRequestError("Invalid school ID.");
45476
+ }
45477
+ const cacheKey = (0, import_nodejs_utils83.makeCacheKey)(namespace_collection, {
45478
+ school: school.toString()
45479
+ });
45480
+ import_nodejs_utils83.logger.log({
45481
+ level: "info",
45482
+ message: `Cache key for kindergarten domain by school: ${cacheKey}`
45483
+ });
45484
+ try {
45485
+ const cached = await getCache(cacheKey);
45486
+ if (cached) {
45487
+ import_nodejs_utils83.logger.log({
45488
+ level: "info",
45489
+ message: `Cache hit for kindergarten domain by school: ${cacheKey}`
45490
+ });
45491
+ return cached;
45492
+ }
45493
+ const result = await collection.find({
45494
+ school,
45495
+ deletedAt: { $in: ["", null] }
45496
+ }).toArray();
45497
+ setCache(cacheKey, result, 300).then(() => {
45498
+ import_nodejs_utils83.logger.log({
45499
+ level: "info",
45500
+ message: `Cache set for kindergarten domain by school: ${cacheKey}`
45501
+ });
45502
+ }).catch((err) => {
45503
+ import_nodejs_utils83.logger.log({
45504
+ level: "error",
45505
+ message: `Failed to set cache for kindergarten domain by school: ${err.message}`
45506
+ });
45507
+ });
45508
+ return result;
45509
+ } catch (error) {
45510
+ if (error instanceof import_nodejs_utils83.AppError) {
45511
+ throw error;
45512
+ } else {
45513
+ throw new import_nodejs_utils83.InternalServerError("Failed to get kindergarten domain.");
45514
+ }
45515
+ }
45516
+ }
45517
+ async function updateFieldById({ _id, field, value } = {}, session) {
45518
+ const allowedFields = ["title", "status"];
45519
+ if (!allowedFields.includes(field)) {
45520
+ throw new import_nodejs_utils83.BadRequestError(
45521
+ `Field "${field}" is not allowed to be updated.`
45522
+ );
45523
+ }
45524
+ try {
45525
+ _id = new import_mongodb47.ObjectId(_id);
45526
+ } catch (error) {
45527
+ throw new import_nodejs_utils83.BadRequestError(namespace_collection + " Invalid ID.");
45528
+ }
45529
+ try {
45530
+ await collection.updateOne(
45531
+ { _id, deletedAt: { $in: ["", null] } },
45532
+ { $set: { [field]: value, updatedAt: (/* @__PURE__ */ new Date()).toISOString() } },
45533
+ { session }
45534
+ );
45535
+ delCachedData();
45536
+ return `Successfully updated kindergarten domain ${field}.`;
45537
+ } catch (error) {
45538
+ throw new import_nodejs_utils83.InternalServerError(
45539
+ `Failed to update kindergarten domain ${field}.`
45540
+ );
45541
+ }
45542
+ }
45543
+ async function updateById(_id, value, session) {
45544
+ const { error } = schemaKindergartenDomain.validate(value);
45545
+ if (error) {
45546
+ throw new import_nodejs_utils83.BadRequestError(
45547
+ `Invalid kindergarten domain data: ${error.message}`
45548
+ );
45549
+ }
45550
+ try {
45551
+ _id = new import_mongodb47.ObjectId(_id);
45552
+ } catch (error2) {
45553
+ throw new import_nodejs_utils83.BadRequestError(namespace_collection + " Invalid ID.");
45554
+ }
45555
+ try {
45556
+ await collection.updateOne(
45557
+ { _id },
45558
+ { $set: { ...value, updatedAt: (/* @__PURE__ */ new Date()).toISOString() } },
45559
+ { session }
45560
+ );
45561
+ delCachedData();
45562
+ return `Successfully updated kindergarten domain.`;
45563
+ } catch (error2) {
45564
+ throw new import_nodejs_utils83.InternalServerError("Failed to update kindergarten domain.");
45565
+ }
45566
+ }
45567
+ async function deleteById(_id, session) {
45568
+ try {
45569
+ _id = new import_mongodb47.ObjectId(_id);
45570
+ } catch (error) {
45571
+ throw new import_nodejs_utils83.BadRequestError(namespace_collection + " Invalid ID.");
45572
+ }
45573
+ try {
45574
+ await collection.updateOne(
45575
+ { _id },
45576
+ { $set: { status: "deleted", deletedAt: (/* @__PURE__ */ new Date()).toISOString() } },
45577
+ { session }
45578
+ );
45579
+ delCachedData();
45580
+ return "Successfully deleted kindergarten domain.";
45581
+ } catch (error) {
45582
+ throw new import_nodejs_utils83.InternalServerError("Failed to delete kindergarten domain.");
45583
+ }
45584
+ }
45585
+ return {
45586
+ createIndexes,
45587
+ add,
45588
+ getAll,
45589
+ getById,
45590
+ getBySchool,
45591
+ updateFieldById,
45592
+ updateById,
45593
+ deleteById
45594
+ };
45595
+ }
45596
+
45597
+ // src/resources/kindergarten-domain/kindergarten.domain.service.ts
45598
+ var import_nodejs_utils84 = require("@eeplatform/nodejs-utils");
45599
+ function useKindergartenDomainService() {
45600
+ const { deleteById: _deleteById, getById } = useKindergartenDomainRepo();
45601
+ const { countByDomain } = useKindergartenRoutineRepo();
45602
+ async function deleteById(id) {
45603
+ const session = import_nodejs_utils84.useAtlas.getClient()?.startSession();
45604
+ if (!session) {
45605
+ throw new Error("Failed to start database session.");
45606
+ }
45607
+ try {
45608
+ session.startTransaction();
45609
+ const domain = await getById(id);
45610
+ if (!domain) {
45611
+ throw new import_nodejs_utils84.BadRequestError("Kindergarten domain not found.");
45612
+ }
45613
+ const usageCount = await countByDomain(domain.title);
45614
+ if (usageCount > 0) {
45615
+ throw new import_nodejs_utils84.BadRequestError(
45616
+ "Cannot delete domain as it is currently in use."
45617
+ );
45618
+ }
45619
+ await _deleteById(id, session);
45620
+ } catch (error) {
45621
+ await session.abortTransaction();
45622
+ if (error instanceof import_nodejs_utils84.AppError) {
45623
+ throw error;
45624
+ } else {
45625
+ throw new import_nodejs_utils84.AppError("Failed to delete kindergarten domain.", 500);
45626
+ }
45627
+ } finally {
45628
+ await session.endSession();
45629
+ }
45630
+ }
45631
+ return {
45632
+ deleteById
45633
+ };
45634
+ }
45635
+
45636
+ // src/resources/kindergarten-domain/kindergarten.domain.controller.ts
45637
+ var import_nodejs_utils85 = require("@eeplatform/nodejs-utils");
45638
+ var import_joi51 = __toESM(require("joi"));
45639
+ function useKindergartenDomainController() {
45640
+ const {
45641
+ add: _add,
45642
+ getAll: _getAll,
45643
+ getById: _getById,
45644
+ getBySchool: _getBySchool,
45645
+ updateFieldById: _updateFieldById
45646
+ } = useKindergartenDomainRepo();
45647
+ async function add(req, res, next) {
45648
+ const value = req.body;
45649
+ const { error } = schemaKindergartenDomain.validate(value);
45650
+ if (error) {
45651
+ next(new import_nodejs_utils85.BadRequestError(error.message));
45652
+ return;
45653
+ }
45654
+ try {
45655
+ const data = await _add(value);
45656
+ res.json({
45657
+ message: "Successfully created kindergarten domain.",
45658
+ data
45659
+ });
45660
+ return;
45661
+ } catch (error2) {
45662
+ next(error2);
45663
+ }
45664
+ }
45665
+ async function getAll(req, res, next) {
45666
+ const query = req.query;
45667
+ const validation = import_joi51.default.object({
45668
+ page: import_joi51.default.number().min(1).optional().allow("", null),
45669
+ limit: import_joi51.default.number().min(1).optional().allow("", null),
45670
+ search: import_joi51.default.string().optional().allow("", null),
45671
+ status: import_joi51.default.string().optional().allow("", null),
45672
+ school: import_joi51.default.string().hex().optional().allow("", null),
45673
+ createdBy: import_joi51.default.string().hex().optional().allow("", null)
45674
+ });
45675
+ const { error } = validation.validate(query);
45676
+ const page = typeof req.query.page === "string" ? Number(req.query.page) : 1;
45677
+ const limit = typeof req.query.limit === "string" ? Number(req.query.limit) : 10;
45678
+ const search = req.query.search ?? "";
45679
+ const status = req.query.status ?? "active";
45680
+ const school = req.query.school ?? "";
45681
+ const createdBy = req.query.createdBy ?? "";
45682
+ const isPageNumber = isFinite(page);
45683
+ if (!isPageNumber) {
45684
+ next(new import_nodejs_utils85.BadRequestError("Invalid page number."));
45685
+ return;
45686
+ }
45687
+ const isLimitNumber = isFinite(limit);
45688
+ if (!isLimitNumber) {
45689
+ next(new import_nodejs_utils85.BadRequestError("Invalid limit number."));
45690
+ return;
45691
+ }
45692
+ if (error) {
45693
+ next(new import_nodejs_utils85.BadRequestError(error.message));
45694
+ return;
45695
+ }
45696
+ try {
45697
+ const data = await _getAll({
45698
+ page,
45699
+ limit,
45700
+ search,
45701
+ status,
45702
+ school,
45703
+ createdBy: createdBy || void 0
45704
+ });
45705
+ res.json(data);
45706
+ return;
45707
+ } catch (error2) {
45708
+ next(error2);
45709
+ }
45710
+ }
45711
+ async function getById(req, res, next) {
45712
+ const id = req.params.id;
45713
+ const validation = import_joi51.default.object({
45714
+ id: import_joi51.default.string().hex().required()
45715
+ });
45716
+ const { error } = validation.validate({ id });
45717
+ if (error) {
45718
+ next(new import_nodejs_utils85.BadRequestError(error.message));
45719
+ return;
45720
+ }
45721
+ try {
45722
+ const data = await _getById(id);
45723
+ res.json({
45724
+ message: "Successfully retrieved kindergarten domain.",
45725
+ data
45726
+ });
45727
+ return;
45728
+ } catch (error2) {
45729
+ next(error2);
45730
+ }
45731
+ }
45732
+ async function getBySchool(req, res, next) {
45733
+ const school = req.params.school;
45734
+ const validation = import_joi51.default.object({
45735
+ school: import_joi51.default.string().hex().required()
45736
+ });
45737
+ const { error } = validation.validate({ school });
45738
+ if (error) {
45739
+ next(new import_nodejs_utils85.BadRequestError(error.message));
45740
+ return;
45741
+ }
45742
+ try {
45743
+ const data = await _getBySchool(school);
45744
+ res.json({
45745
+ message: "Successfully retrieved kindergarten domains.",
45746
+ data
45747
+ });
45748
+ return;
45749
+ } catch (error2) {
45750
+ next(error2);
45751
+ }
45752
+ }
45753
+ async function updateField(req, res, next) {
45754
+ const _id = req.params.id;
45755
+ const { field, value } = req.body;
45756
+ const validation = import_joi51.default.object({
45757
+ _id: import_joi51.default.string().hex().required(),
45758
+ field: import_joi51.default.string().valid("title", "status").required(),
45759
+ value: import_joi51.default.alternatives().try(import_joi51.default.string(), import_joi51.default.array(), import_joi51.default.object()).required()
45760
+ });
45761
+ const { error } = validation.validate({ _id, field, value });
45762
+ if (error) {
45763
+ next(new import_nodejs_utils85.BadRequestError(error.message));
45764
+ return;
45765
+ }
45766
+ try {
45767
+ const message = await _updateFieldById({ _id, field, value });
45768
+ res.json({ message });
45769
+ return;
45770
+ } catch (error2) {
45771
+ next(error2);
45772
+ }
45773
+ }
45774
+ const { deleteById: _deleteById } = useKindergartenDomainService();
45775
+ async function deleteById(req, res, next) {
45776
+ const _id = req.params.id;
45777
+ const validation = import_joi51.default.object({
45778
+ _id: import_joi51.default.string().hex().required()
45779
+ });
45780
+ const { error } = validation.validate({ _id });
45781
+ if (error) {
45782
+ next(new import_nodejs_utils85.BadRequestError(error.message));
45783
+ return;
45784
+ }
45785
+ try {
45786
+ const message = await _deleteById(_id);
45787
+ res.json({ message });
45788
+ return;
45789
+ } catch (error2) {
45790
+ next(error2);
45791
+ }
45792
+ }
45793
+ return {
45794
+ add,
45795
+ getAll,
45796
+ getById,
45797
+ getBySchool,
45798
+ updateField,
45799
+ deleteById
45800
+ };
45801
+ }
45802
+
44515
45803
  // src/config.ts
44516
45804
  var dotenv = __toESM(require("dotenv"));
44517
45805
  dotenv.config();
@@ -44529,6 +45817,8 @@ dotenv.config();
44529
45817
  allowedSectionStudentStatuses,
44530
45818
  modelBasicEduCount,
44531
45819
  modelDivision,
45820
+ modelKindergartenDomain,
45821
+ modelKindergartenRoutine,
44532
45822
  modelProgram,
44533
45823
  modelProgramScreening,
44534
45824
  modelRegion,
@@ -44551,6 +45841,9 @@ dotenv.config();
44551
45841
  schemaEnrollment,
44552
45842
  schemaGenerateSections,
44553
45843
  schemaGradeLevel,
45844
+ schemaKindergartenDomain,
45845
+ schemaKindergartenRoutine,
45846
+ schemaKindergartenRoutineUpdate,
44554
45847
  schemaPersonnel,
44555
45848
  schemaPlantilla,
44556
45849
  schemaProgram,
@@ -44592,6 +45885,11 @@ dotenv.config();
44592
45885
  useEnrollmentService,
44593
45886
  useGradeLevelController,
44594
45887
  useGradeLevelRepo,
45888
+ useKindergartenDomainController,
45889
+ useKindergartenDomainRepo,
45890
+ useKindergartenDomainService,
45891
+ useKindergartenRoutineController,
45892
+ useKindergartenRoutineRepo,
44595
45893
  useLearnerController,
44596
45894
  useLearnerRepo,
44597
45895
  usePersonnelController,