@eeplatform/basic-edu 1.9.4 → 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;
@@ -42889,7 +43599,7 @@ function useSectionService() {
42889
43599
  pageTeacher++;
42890
43600
  } while (pageTeacher < pagesTeachers);
42891
43601
  if (!teachers.length) {
42892
- throw new import_nodejs_utils69.BadRequestError(
43602
+ throw new import_nodejs_utils72.BadRequestError(
42893
43603
  "Could not proceed, no teaching personnel found."
42894
43604
  );
42895
43605
  }
@@ -42897,7 +43607,7 @@ function useSectionService() {
42897
43607
  for (let index = 0; index < teachers.length; index++) {
42898
43608
  const teacher = teachers[index];
42899
43609
  if (!teacher._id) {
42900
- throw new import_nodejs_utils69.BadRequestError("Teacher ID is missing.");
43610
+ throw new import_nodejs_utils72.BadRequestError("Teacher ID is missing.");
42901
43611
  }
42902
43612
  await addTeachingLoad(
42903
43613
  {
@@ -42916,10 +43626,10 @@ function useSectionService() {
42916
43626
  return "Sections generated successfully.";
42917
43627
  } catch (error2) {
42918
43628
  await session.abortTransaction();
42919
- if (error2 instanceof import_nodejs_utils69.AppError) {
43629
+ if (error2 instanceof import_nodejs_utils72.AppError) {
42920
43630
  throw error2;
42921
43631
  } else {
42922
- throw new import_nodejs_utils69.InternalServerError("Failed to generate sections.");
43632
+ throw new import_nodejs_utils72.InternalServerError("Failed to generate sections.");
42923
43633
  }
42924
43634
  } finally {
42925
43635
  await session?.endSession();
@@ -42928,7 +43638,7 @@ function useSectionService() {
42928
43638
  async function generateSectionPreview(value) {
42929
43639
  const { error } = schemaGenerateSections.validate(value);
42930
43640
  if (error) {
42931
- throw new import_nodejs_utils69.BadRequestError(
43641
+ throw new import_nodejs_utils72.BadRequestError(
42932
43642
  `Invalid section generation data: ${error.message}`
42933
43643
  );
42934
43644
  }
@@ -42940,20 +43650,20 @@ function useSectionService() {
42940
43650
  specialProgram: value.specialProgram
42941
43651
  });
42942
43652
  if (studentCount === 0) {
42943
- 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.");
42944
43654
  }
42945
43655
  const gradeLevelData = await getByGradeLevel({
42946
43656
  school: value.school,
42947
43657
  gradeLevel: value.gradeLevel
42948
43658
  });
42949
43659
  if (!gradeLevelData) {
42950
- throw new import_nodejs_utils69.BadRequestError("Grade level not found.");
43660
+ throw new import_nodejs_utils72.BadRequestError("Grade level not found.");
42951
43661
  }
42952
43662
  const minPerSection = value.minStudents ?? gradeLevelData.minNumberOfLearners;
42953
43663
  const maxPerSection = value.maxStudents ?? gradeLevelData.maxNumberOfLearners;
42954
43664
  const sectionsNeeded = Math.ceil(studentCount / minPerSection);
42955
43665
  if (sectionsNeeded > value.set.length) {
42956
- throw new import_nodejs_utils69.BadRequestError(
43666
+ throw new import_nodejs_utils72.BadRequestError(
42957
43667
  "Insufficient number of section names in set[]."
42958
43668
  );
42959
43669
  }
@@ -42963,7 +43673,7 @@ function useSectionService() {
42963
43673
  maxPerSection
42964
43674
  );
42965
43675
  if (sectionSizes.length === 0) {
42966
- throw new import_nodejs_utils69.BadRequestError("Unable to compute section sizes.");
43676
+ throw new import_nodejs_utils72.BadRequestError("Unable to compute section sizes.");
42967
43677
  }
42968
43678
  const sections = sectionSizes.map((size, index) => ({
42969
43679
  name: value.set[index],
@@ -42975,10 +43685,10 @@ function useSectionService() {
42975
43685
  sections
42976
43686
  };
42977
43687
  } catch (error2) {
42978
- if (error2 instanceof import_nodejs_utils69.AppError) {
43688
+ if (error2 instanceof import_nodejs_utils72.AppError) {
42979
43689
  throw error2;
42980
43690
  } else {
42981
- throw new import_nodejs_utils69.InternalServerError("Failed to generate section preview.");
43691
+ throw new import_nodejs_utils72.InternalServerError("Failed to generate section preview.");
42982
43692
  }
42983
43693
  }
42984
43694
  }
@@ -43006,7 +43716,7 @@ function useSectionController() {
43006
43716
  const value = req.body;
43007
43717
  const { error } = schemaSection.validate(value);
43008
43718
  if (error) {
43009
- next(new import_nodejs_utils70.BadRequestError(error.message));
43719
+ next(new import_nodejs_utils73.BadRequestError(error.message));
43010
43720
  return;
43011
43721
  }
43012
43722
  try {
@@ -43024,7 +43734,7 @@ function useSectionController() {
43024
43734
  const value = req.body;
43025
43735
  const { error } = schemaGenerateSections.validate(value);
43026
43736
  if (error) {
43027
- next(new import_nodejs_utils70.BadRequestError(error.message));
43737
+ next(new import_nodejs_utils73.BadRequestError(error.message));
43028
43738
  return;
43029
43739
  }
43030
43740
  try {
@@ -43042,7 +43752,7 @@ function useSectionController() {
43042
43752
  const value = req.body;
43043
43753
  const { error } = schemaGenerateSections.validate(value);
43044
43754
  if (error) {
43045
- next(new import_nodejs_utils70.BadRequestError(error.message));
43755
+ next(new import_nodejs_utils73.BadRequestError(error.message));
43046
43756
  return;
43047
43757
  }
43048
43758
  try {
@@ -43055,14 +43765,14 @@ function useSectionController() {
43055
43765
  }
43056
43766
  async function getAll(req, res, next) {
43057
43767
  const query = req.query;
43058
- const validation = import_joi43.default.object({
43059
- page: import_joi43.default.number().min(1).optional().allow("", null),
43060
- limit: import_joi43.default.number().min(1).optional().allow("", null),
43061
- search: import_joi43.default.string().optional().allow("", null),
43062
- status: import_joi43.default.string().optional().allow("", null),
43063
- school: import_joi43.default.string().hex().optional().allow("", null),
43064
- schoolYear: import_joi43.default.string().optional().allow("", null),
43065
- 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)
43066
43776
  });
43067
43777
  const { error } = validation.validate(query);
43068
43778
  const page = typeof req.query.page === "string" ? Number(req.query.page) : 1;
@@ -43074,16 +43784,16 @@ function useSectionController() {
43074
43784
  const gradeLevel = req.query.gradeLevel ?? "";
43075
43785
  const isPageNumber = isFinite(page);
43076
43786
  if (!isPageNumber) {
43077
- next(new import_nodejs_utils70.BadRequestError("Invalid page number."));
43787
+ next(new import_nodejs_utils73.BadRequestError("Invalid page number."));
43078
43788
  return;
43079
43789
  }
43080
43790
  const isLimitNumber = isFinite(limit);
43081
43791
  if (!isLimitNumber) {
43082
- next(new import_nodejs_utils70.BadRequestError("Invalid limit number."));
43792
+ next(new import_nodejs_utils73.BadRequestError("Invalid limit number."));
43083
43793
  return;
43084
43794
  }
43085
43795
  if (error) {
43086
- next(new import_nodejs_utils70.BadRequestError(error.message));
43796
+ next(new import_nodejs_utils73.BadRequestError(error.message));
43087
43797
  return;
43088
43798
  }
43089
43799
  try {
@@ -43104,12 +43814,12 @@ function useSectionController() {
43104
43814
  }
43105
43815
  async function getById(req, res, next) {
43106
43816
  const id = req.params.id;
43107
- const validation = import_joi43.default.object({
43108
- id: import_joi43.default.string().hex().required()
43817
+ const validation = import_joi45.default.object({
43818
+ id: import_joi45.default.string().hex().required()
43109
43819
  });
43110
43820
  const { error } = validation.validate({ id });
43111
43821
  if (error) {
43112
- next(new import_nodejs_utils70.BadRequestError(error.message));
43822
+ next(new import_nodejs_utils73.BadRequestError(error.message));
43113
43823
  return;
43114
43824
  }
43115
43825
  try {
@@ -43122,12 +43832,12 @@ function useSectionController() {
43122
43832
  }
43123
43833
  async function getByName(req, res, next) {
43124
43834
  const name = req.params.name;
43125
- const validation = import_joi43.default.object({
43126
- name: import_joi43.default.string().required()
43835
+ const validation = import_joi45.default.object({
43836
+ name: import_joi45.default.string().required()
43127
43837
  });
43128
43838
  const { error } = validation.validate({ name });
43129
43839
  if (error) {
43130
- next(new import_nodejs_utils70.BadRequestError(error.message));
43840
+ next(new import_nodejs_utils73.BadRequestError(error.message));
43131
43841
  return;
43132
43842
  }
43133
43843
  try {
@@ -43143,12 +43853,12 @@ function useSectionController() {
43143
43853
  }
43144
43854
  async function getBySchool(req, res, next) {
43145
43855
  const school = req.params.school;
43146
- const validation = import_joi43.default.object({
43147
- school: import_joi43.default.string().hex().required()
43856
+ const validation = import_joi45.default.object({
43857
+ school: import_joi45.default.string().hex().required()
43148
43858
  });
43149
43859
  const { error } = validation.validate({ school });
43150
43860
  if (error) {
43151
- next(new import_nodejs_utils70.BadRequestError(error.message));
43861
+ next(new import_nodejs_utils73.BadRequestError(error.message));
43152
43862
  return;
43153
43863
  }
43154
43864
  try {
@@ -43165,14 +43875,14 @@ function useSectionController() {
43165
43875
  async function updateField(req, res, next) {
43166
43876
  const _id = req.params.id;
43167
43877
  const { field, value } = req.body;
43168
- const validation = import_joi43.default.object({
43169
- _id: import_joi43.default.string().hex().required(),
43170
- field: import_joi43.default.string().valid("name", "schoolYear", "gradeLevel", "adviser", "adviserName").required(),
43171
- 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()
43172
43882
  });
43173
43883
  const { error } = validation.validate({ _id, field, value });
43174
43884
  if (error) {
43175
- next(new import_nodejs_utils70.BadRequestError(error.message));
43885
+ next(new import_nodejs_utils73.BadRequestError(error.message));
43176
43886
  return;
43177
43887
  }
43178
43888
  try {
@@ -43186,13 +43896,13 @@ function useSectionController() {
43186
43896
  async function addStudent(req, res, next) {
43187
43897
  const _id = req.params.id;
43188
43898
  const { studentId } = req.body;
43189
- const validation = import_joi43.default.object({
43190
- _id: import_joi43.default.string().hex().required(),
43191
- 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()
43192
43902
  });
43193
43903
  const { error } = validation.validate({ _id, studentId });
43194
43904
  if (error) {
43195
- next(new import_nodejs_utils70.BadRequestError(error.message));
43905
+ next(new import_nodejs_utils73.BadRequestError(error.message));
43196
43906
  return;
43197
43907
  }
43198
43908
  try {
@@ -43206,13 +43916,13 @@ function useSectionController() {
43206
43916
  async function removeStudent(req, res, next) {
43207
43917
  const _id = req.params.id;
43208
43918
  const { studentId } = req.body;
43209
- const validation = import_joi43.default.object({
43210
- _id: import_joi43.default.string().hex().required(),
43211
- 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()
43212
43922
  });
43213
43923
  const { error } = validation.validate({ _id, studentId });
43214
43924
  if (error) {
43215
- next(new import_nodejs_utils70.BadRequestError(error.message));
43925
+ next(new import_nodejs_utils73.BadRequestError(error.message));
43216
43926
  return;
43217
43927
  }
43218
43928
  try {
@@ -43225,12 +43935,12 @@ function useSectionController() {
43225
43935
  }
43226
43936
  async function deleteById(req, res, next) {
43227
43937
  const _id = req.params.id;
43228
- const validation = import_joi43.default.object({
43229
- _id: import_joi43.default.string().hex().required()
43938
+ const validation = import_joi45.default.object({
43939
+ _id: import_joi45.default.string().hex().required()
43230
43940
  });
43231
43941
  const { error } = validation.validate({ _id });
43232
43942
  if (error) {
43233
- next(new import_nodejs_utils70.BadRequestError(error.message));
43943
+ next(new import_nodejs_utils73.BadRequestError(error.message));
43234
43944
  return;
43235
43945
  }
43236
43946
  try {
@@ -43257,15 +43967,15 @@ function useSectionController() {
43257
43967
  }
43258
43968
 
43259
43969
  // src/resources/section-student/section.student.controller.ts
43260
- var import_nodejs_utils71 = require("@eeplatform/nodejs-utils");
43261
- var import_joi44 = __toESM(require("joi"));
43970
+ var import_nodejs_utils74 = require("@eeplatform/nodejs-utils");
43971
+ var import_joi46 = __toESM(require("joi"));
43262
43972
  function useSectionStudentController() {
43263
43973
  const { add: _add, getAll: _getAll } = useSectionStudentRepo();
43264
43974
  async function add(req, res, next) {
43265
43975
  const value = req.body;
43266
43976
  const { error } = schemaSectionStudent.validate(value);
43267
43977
  if (error) {
43268
- next(new import_nodejs_utils71.BadRequestError(error.message));
43978
+ next(new import_nodejs_utils74.BadRequestError(error.message));
43269
43979
  return;
43270
43980
  }
43271
43981
  try {
@@ -43281,15 +43991,15 @@ function useSectionStudentController() {
43281
43991
  }
43282
43992
  async function getAll(req, res, next) {
43283
43993
  const query = req.query;
43284
- const validation = import_joi44.default.object({
43285
- page: import_joi44.default.number().min(1).optional().allow("", null),
43286
- limit: import_joi44.default.number().min(1).optional().allow("", null),
43287
- search: import_joi44.default.string().optional().allow("", null),
43288
- status: import_joi44.default.string().optional().allow("", null),
43289
- school: import_joi44.default.string().optional().allow("", null),
43290
- gradeLevel: import_joi44.default.string().optional().allow("", null),
43291
- section: import_joi44.default.string().optional().allow("", null),
43292
- 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)
43293
44003
  });
43294
44004
  const { error } = validation.validate(query);
43295
44005
  const page = typeof req.query.page === "string" ? Number(req.query.page) : 1;
@@ -43302,16 +44012,16 @@ function useSectionStudentController() {
43302
44012
  const schoolYear = req.query.schoolYear ?? "";
43303
44013
  const isPageNumber = isFinite(page);
43304
44014
  if (!isPageNumber) {
43305
- next(new import_nodejs_utils71.BadRequestError("Invalid page number."));
44015
+ next(new import_nodejs_utils74.BadRequestError("Invalid page number."));
43306
44016
  return;
43307
44017
  }
43308
44018
  const isLimitNumber = isFinite(limit);
43309
44019
  if (!isLimitNumber) {
43310
- next(new import_nodejs_utils71.BadRequestError("Invalid limit number."));
44020
+ next(new import_nodejs_utils74.BadRequestError("Invalid limit number."));
43311
44021
  return;
43312
44022
  }
43313
44023
  if (error) {
43314
- next(new import_nodejs_utils71.BadRequestError(error.message));
44024
+ next(new import_nodejs_utils74.BadRequestError(error.message));
43315
44025
  return;
43316
44026
  }
43317
44027
  try {
@@ -43338,64 +44048,64 @@ function useSectionStudentController() {
43338
44048
  }
43339
44049
 
43340
44050
  // src/resources/building/building.model.ts
43341
- var import_nodejs_utils72 = require("@eeplatform/nodejs-utils");
43342
- var import_joi45 = __toESM(require("joi"));
43343
- var import_mongodb41 = require("mongodb");
43344
- var schemaBuilding = import_joi45.default.object({
43345
- _id: import_joi45.default.string().hex().optional(),
43346
- school: import_joi45.default.string().hex().required(),
43347
- serial: import_joi45.default.string().optional().allow("", null),
43348
- name: import_joi45.default.string().required(),
43349
- levels: import_joi45.default.number().integer().min(1).required(),
43350
- createdAt: import_joi45.default.date().optional().allow("", null),
43351
- updatedAt: import_joi45.default.date().optional().allow("", null),
43352
- deletedAt: import_joi45.default.date().optional().allow("", null),
43353
- 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)
43354
44064
  });
43355
- var schemaBuildingUnit = import_joi45.default.object({
43356
- _id: import_joi45.default.string().hex().optional(),
43357
- school: import_joi45.default.string().hex().required(),
43358
- name: import_joi45.default.string().optional().allow("", null),
43359
- building: import_joi45.default.string().hex().required(),
43360
- buildingName: import_joi45.default.string().optional().allow("", null),
43361
- level: import_joi45.default.number().integer().min(1).required(),
43362
- category: import_joi45.default.string().required(),
43363
- type: import_joi45.default.string().required(),
43364
- seating_capacity: import_joi45.default.number().integer().min(0).required(),
43365
- standing_capacity: import_joi45.default.number().integer().min(0).required(),
43366
- description: import_joi45.default.string().optional().allow("", null),
43367
- unit_of_measurement: import_joi45.default.string().valid("sqm").required(),
43368
- area: import_joi45.default.number().positive().required(),
43369
- 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)
43370
44080
  });
43371
- var schemaUpdateOptions = import_joi45.default.object({
43372
- name: import_joi45.default.string().optional().allow("", null),
43373
- building: import_joi45.default.string().hex().optional().allow("", null),
43374
- buildingName: import_joi45.default.string().optional().allow("", null),
43375
- level: import_joi45.default.number().integer().min(1).optional().allow("", null),
43376
- category: import_joi45.default.string().optional().allow("", null),
43377
- type: import_joi45.default.string().optional().allow("", null),
43378
- seating_capacity: import_joi45.default.number().integer().min(0).optional().allow("", null),
43379
- standing_capacity: import_joi45.default.number().integer().min(0).optional().allow("", null),
43380
- 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)
43381
44091
  });
43382
44092
  function MBuilding(value) {
43383
44093
  const { error } = schemaBuilding.validate(value);
43384
44094
  if (error) {
43385
- import_nodejs_utils72.logger.info(`Building Model: ${error.message}`);
43386
- 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);
43387
44097
  }
43388
44098
  if (value._id && typeof value._id === "string") {
43389
44099
  try {
43390
- value._id = new import_mongodb41.ObjectId(value._id);
44100
+ value._id = new import_mongodb43.ObjectId(value._id);
43391
44101
  } catch (error2) {
43392
- throw new import_nodejs_utils72.BadRequestError("Invalid _id format");
44102
+ throw new import_nodejs_utils75.BadRequestError("Invalid _id format");
43393
44103
  }
43394
44104
  }
43395
44105
  try {
43396
- value.school = new import_mongodb41.ObjectId(value.school);
44106
+ value.school = new import_mongodb43.ObjectId(value.school);
43397
44107
  } catch (error2) {
43398
- throw new import_nodejs_utils72.BadRequestError("Invalid school format");
44108
+ throw new import_nodejs_utils75.BadRequestError("Invalid school format");
43399
44109
  }
43400
44110
  return {
43401
44111
  _id: value._id ?? void 0,
@@ -43412,25 +44122,25 @@ function MBuilding(value) {
43412
44122
  function MBuildingUnit(value) {
43413
44123
  const { error } = schemaBuildingUnit.validate(value);
43414
44124
  if (error) {
43415
- import_nodejs_utils72.logger.info(`Building Unit Model: ${error.message}`);
43416
- 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);
43417
44127
  }
43418
44128
  if (value._id && typeof value._id === "string") {
43419
44129
  try {
43420
- value._id = new import_mongodb41.ObjectId(value._id);
44130
+ value._id = new import_mongodb43.ObjectId(value._id);
43421
44131
  } catch (error2) {
43422
- throw new import_nodejs_utils72.BadRequestError("Invalid ID");
44132
+ throw new import_nodejs_utils75.BadRequestError("Invalid ID");
43423
44133
  }
43424
44134
  }
43425
44135
  try {
43426
- value.school = new import_mongodb41.ObjectId(value.school);
44136
+ value.school = new import_mongodb43.ObjectId(value.school);
43427
44137
  } catch (error2) {
43428
- throw new import_nodejs_utils72.BadRequestError("Invalid school ID");
44138
+ throw new import_nodejs_utils75.BadRequestError("Invalid school ID");
43429
44139
  }
43430
44140
  try {
43431
- value.building = new import_mongodb41.ObjectId(value.building);
44141
+ value.building = new import_mongodb43.ObjectId(value.building);
43432
44142
  } catch (error2) {
43433
- throw new import_nodejs_utils72.BadRequestError("Invalid building ID");
44143
+ throw new import_nodejs_utils75.BadRequestError("Invalid building ID");
43434
44144
  }
43435
44145
  return {
43436
44146
  _id: value._id ?? void 0,
@@ -43454,16 +44164,16 @@ function MBuildingUnit(value) {
43454
44164
  }
43455
44165
 
43456
44166
  // src/resources/building/building.repository.ts
43457
- var import_nodejs_utils73 = require("@eeplatform/nodejs-utils");
43458
- var import_mongodb42 = require("mongodb");
44167
+ var import_nodejs_utils76 = require("@eeplatform/nodejs-utils");
44168
+ var import_mongodb44 = require("mongodb");
43459
44169
  function useBuildingRepo() {
43460
- const db = import_nodejs_utils73.useAtlas.getDb();
44170
+ const db = import_nodejs_utils76.useAtlas.getDb();
43461
44171
  if (!db) {
43462
44172
  throw new Error("Unable to connect to server.");
43463
44173
  }
43464
44174
  const namespace_collection = "deped.buildings";
43465
44175
  const collection = db.collection(namespace_collection);
43466
- const { getCache, setCache, delNamespace } = (0, import_nodejs_utils73.useCache)(namespace_collection);
44176
+ const { getCache, setCache, delNamespace } = (0, import_nodejs_utils76.useCache)(namespace_collection);
43467
44177
  async function createIndexes() {
43468
44178
  try {
43469
44179
  await collection.createIndexes([
@@ -43482,16 +44192,16 @@ function useBuildingRepo() {
43482
44192
  delCachedData();
43483
44193
  return res.insertedId;
43484
44194
  } catch (error) {
43485
- import_nodejs_utils73.logger.log({
44195
+ import_nodejs_utils76.logger.log({
43486
44196
  level: "error",
43487
44197
  message: error.message
43488
44198
  });
43489
- if (error instanceof import_nodejs_utils73.AppError) {
44199
+ if (error instanceof import_nodejs_utils76.AppError) {
43490
44200
  throw error;
43491
44201
  } else {
43492
44202
  const isDuplicated = error.message.includes("duplicate");
43493
44203
  if (isDuplicated) {
43494
- throw new import_nodejs_utils73.BadRequestError("Building already exists.");
44204
+ throw new import_nodejs_utils76.BadRequestError("Building already exists.");
43495
44205
  }
43496
44206
  throw new Error("Failed to create building.");
43497
44207
  }
@@ -43499,9 +44209,9 @@ function useBuildingRepo() {
43499
44209
  }
43500
44210
  async function updateById(_id, value, session) {
43501
44211
  try {
43502
- _id = new import_mongodb42.ObjectId(_id);
44212
+ _id = new import_mongodb44.ObjectId(_id);
43503
44213
  } catch (error) {
43504
- throw new import_nodejs_utils73.BadRequestError(namespace_collection + " Invalid ID.");
44214
+ throw new import_nodejs_utils76.BadRequestError(namespace_collection + " Invalid ID.");
43505
44215
  }
43506
44216
  try {
43507
44217
  const res = await collection.updateOne(
@@ -43512,11 +44222,11 @@ function useBuildingRepo() {
43512
44222
  delCachedData();
43513
44223
  return res;
43514
44224
  } catch (error) {
43515
- import_nodejs_utils73.logger.log({
44225
+ import_nodejs_utils76.logger.log({
43516
44226
  level: "error",
43517
44227
  message: error.message
43518
44228
  });
43519
- if (error instanceof import_nodejs_utils73.AppError) {
44229
+ if (error instanceof import_nodejs_utils76.AppError) {
43520
44230
  throw error;
43521
44231
  } else {
43522
44232
  throw new Error("Failed to update building.");
@@ -43541,9 +44251,9 @@ function useBuildingRepo() {
43541
44251
  }
43542
44252
  if (school) {
43543
44253
  try {
43544
- query.school = new import_mongodb42.ObjectId(school);
44254
+ query.school = new import_mongodb44.ObjectId(school);
43545
44255
  } catch (error) {
43546
- throw new import_nodejs_utils73.BadRequestError("Invalid school ID.");
44256
+ throw new import_nodejs_utils76.BadRequestError("Invalid school ID.");
43547
44257
  }
43548
44258
  }
43549
44259
  const cacheParams = {
@@ -43557,15 +44267,15 @@ function useBuildingRepo() {
43557
44267
  cacheParams.school = school;
43558
44268
  if (status !== "active")
43559
44269
  cacheParams.status = status;
43560
- const cacheKey = (0, import_nodejs_utils73.makeCacheKey)(namespace_collection, cacheParams);
43561
- import_nodejs_utils73.logger.log({
44270
+ const cacheKey = (0, import_nodejs_utils76.makeCacheKey)(namespace_collection, cacheParams);
44271
+ import_nodejs_utils76.logger.log({
43562
44272
  level: "info",
43563
44273
  message: `Cache key for getAll buildings: ${cacheKey}`
43564
44274
  });
43565
44275
  try {
43566
44276
  const cached = await getCache(cacheKey);
43567
44277
  if (cached) {
43568
- import_nodejs_utils73.logger.log({
44278
+ import_nodejs_utils76.logger.log({
43569
44279
  level: "info",
43570
44280
  message: `Cache hit for getAll buildings: ${cacheKey}`
43571
44281
  });
@@ -43578,35 +44288,35 @@ function useBuildingRepo() {
43578
44288
  { $limit: limit }
43579
44289
  ]).toArray();
43580
44290
  const length = await collection.countDocuments(query);
43581
- const data = (0, import_nodejs_utils73.paginate)(items, page, limit, length);
44291
+ const data = (0, import_nodejs_utils76.paginate)(items, page, limit, length);
43582
44292
  setCache(cacheKey, data, 600).then(() => {
43583
- import_nodejs_utils73.logger.log({
44293
+ import_nodejs_utils76.logger.log({
43584
44294
  level: "info",
43585
44295
  message: `Cache set for getAll buildings: ${cacheKey}`
43586
44296
  });
43587
44297
  }).catch((err) => {
43588
- import_nodejs_utils73.logger.log({
44298
+ import_nodejs_utils76.logger.log({
43589
44299
  level: "error",
43590
44300
  message: `Failed to set cache for getAll buildings: ${err.message}`
43591
44301
  });
43592
44302
  });
43593
44303
  return data;
43594
44304
  } catch (error) {
43595
- import_nodejs_utils73.logger.log({ level: "error", message: `${error}` });
44305
+ import_nodejs_utils76.logger.log({ level: "error", message: `${error}` });
43596
44306
  throw error;
43597
44307
  }
43598
44308
  }
43599
44309
  async function getById(_id) {
43600
44310
  try {
43601
- _id = new import_mongodb42.ObjectId(_id);
44311
+ _id = new import_mongodb44.ObjectId(_id);
43602
44312
  } catch (error) {
43603
- throw new import_nodejs_utils73.BadRequestError(namespace_collection + " Invalid ID.");
44313
+ throw new import_nodejs_utils76.BadRequestError(namespace_collection + " Invalid ID.");
43604
44314
  }
43605
- 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) });
43606
44316
  try {
43607
44317
  const cached = await getCache(cacheKey);
43608
44318
  if (cached) {
43609
- import_nodejs_utils73.logger.log({
44319
+ import_nodejs_utils76.logger.log({
43610
44320
  level: "info",
43611
44321
  message: `Cache hit for getById building: ${cacheKey}`
43612
44322
  });
@@ -43616,30 +44326,30 @@ function useBuildingRepo() {
43616
44326
  _id
43617
44327
  });
43618
44328
  setCache(cacheKey, result, 300).then(() => {
43619
- import_nodejs_utils73.logger.log({
44329
+ import_nodejs_utils76.logger.log({
43620
44330
  level: "info",
43621
44331
  message: `Cache set for building by id: ${cacheKey}`
43622
44332
  });
43623
44333
  }).catch((err) => {
43624
- import_nodejs_utils73.logger.log({
44334
+ import_nodejs_utils76.logger.log({
43625
44335
  level: "error",
43626
44336
  message: `Failed to set cache for building by id: ${err.message}`
43627
44337
  });
43628
44338
  });
43629
44339
  return result;
43630
44340
  } catch (error) {
43631
- if (error instanceof import_nodejs_utils73.AppError) {
44341
+ if (error instanceof import_nodejs_utils76.AppError) {
43632
44342
  throw error;
43633
44343
  } else {
43634
- throw new import_nodejs_utils73.InternalServerError("Failed to get building.");
44344
+ throw new import_nodejs_utils76.InternalServerError("Failed to get building.");
43635
44345
  }
43636
44346
  }
43637
44347
  }
43638
44348
  async function deleteById(_id, session) {
43639
44349
  try {
43640
- _id = new import_mongodb42.ObjectId(_id);
44350
+ _id = new import_mongodb44.ObjectId(_id);
43641
44351
  } catch (error) {
43642
- throw new import_nodejs_utils73.BadRequestError(namespace_collection + " Invalid ID.");
44352
+ throw new import_nodejs_utils76.BadRequestError(namespace_collection + " Invalid ID.");
43643
44353
  }
43644
44354
  try {
43645
44355
  const res = await collection.updateOne(
@@ -43649,25 +44359,25 @@ function useBuildingRepo() {
43649
44359
  delCachedData();
43650
44360
  return res;
43651
44361
  } catch (error) {
43652
- import_nodejs_utils73.logger.log({
44362
+ import_nodejs_utils76.logger.log({
43653
44363
  level: "error",
43654
44364
  message: error.message
43655
44365
  });
43656
- if (error instanceof import_nodejs_utils73.AppError) {
44366
+ if (error instanceof import_nodejs_utils76.AppError) {
43657
44367
  throw error;
43658
44368
  } else {
43659
- throw new import_nodejs_utils73.InternalServerError("Failed to delete building.");
44369
+ throw new import_nodejs_utils76.InternalServerError("Failed to delete building.");
43660
44370
  }
43661
44371
  }
43662
44372
  }
43663
44373
  function delCachedData() {
43664
44374
  delNamespace().then(() => {
43665
- import_nodejs_utils73.logger.log({
44375
+ import_nodejs_utils76.logger.log({
43666
44376
  level: "info",
43667
44377
  message: `Cache namespace cleared for ${namespace_collection}`
43668
44378
  });
43669
44379
  }).catch((err) => {
43670
- import_nodejs_utils73.logger.log({
44380
+ import_nodejs_utils76.logger.log({
43671
44381
  level: "error",
43672
44382
  message: `Failed to clear cache namespace for ${namespace_collection}: ${err.message}`
43673
44383
  });
@@ -43684,19 +44394,19 @@ function useBuildingRepo() {
43684
44394
  }
43685
44395
 
43686
44396
  // src/resources/building/building.service.ts
43687
- var import_nodejs_utils75 = require("@eeplatform/nodejs-utils");
44397
+ var import_nodejs_utils78 = require("@eeplatform/nodejs-utils");
43688
44398
 
43689
44399
  // src/resources/building/building-unit.repository.ts
43690
- var import_nodejs_utils74 = require("@eeplatform/nodejs-utils");
43691
- var import_mongodb43 = require("mongodb");
44400
+ var import_nodejs_utils77 = require("@eeplatform/nodejs-utils");
44401
+ var import_mongodb45 = require("mongodb");
43692
44402
  function useBuildingUnitRepo() {
43693
- const db = import_nodejs_utils74.useAtlas.getDb();
44403
+ const db = import_nodejs_utils77.useAtlas.getDb();
43694
44404
  if (!db) {
43695
44405
  throw new Error("Unable to connect to server.");
43696
44406
  }
43697
44407
  const namespace_collection = "deped.building.units";
43698
44408
  const collection = db.collection(namespace_collection);
43699
- const { getCache, setCache, delNamespace } = (0, import_nodejs_utils74.useCache)(namespace_collection);
44409
+ const { getCache, setCache, delNamespace } = (0, import_nodejs_utils77.useCache)(namespace_collection);
43700
44410
  async function createIndexes() {
43701
44411
  try {
43702
44412
  await collection.createIndexes([
@@ -43724,12 +44434,12 @@ function useBuildingUnitRepo() {
43724
44434
  }
43725
44435
  function delCachedData() {
43726
44436
  delNamespace().then(() => {
43727
- import_nodejs_utils74.logger.log({
44437
+ import_nodejs_utils77.logger.log({
43728
44438
  level: "info",
43729
44439
  message: `Cache namespace cleared for ${namespace_collection}`
43730
44440
  });
43731
44441
  }).catch((err) => {
43732
- import_nodejs_utils74.logger.log({
44442
+ import_nodejs_utils77.logger.log({
43733
44443
  level: "error",
43734
44444
  message: `Failed to clear cache namespace for ${namespace_collection}: ${err.message}`
43735
44445
  });
@@ -43742,11 +44452,11 @@ function useBuildingUnitRepo() {
43742
44452
  delCachedData();
43743
44453
  return res.insertedId;
43744
44454
  } catch (error) {
43745
- import_nodejs_utils74.logger.log({
44455
+ import_nodejs_utils77.logger.log({
43746
44456
  level: "error",
43747
44457
  message: error.message
43748
44458
  });
43749
- if (error instanceof import_nodejs_utils74.AppError) {
44459
+ if (error instanceof import_nodejs_utils77.AppError) {
43750
44460
  throw error;
43751
44461
  } else {
43752
44462
  throw new Error("Failed to create building unit.");
@@ -43756,12 +44466,12 @@ function useBuildingUnitRepo() {
43756
44466
  async function updateById(_id, value, session) {
43757
44467
  const { error } = schemaUpdateOptions.validate(value);
43758
44468
  if (error) {
43759
- throw new import_nodejs_utils74.BadRequestError(error.message);
44469
+ throw new import_nodejs_utils77.BadRequestError(error.message);
43760
44470
  }
43761
44471
  try {
43762
- _id = new import_mongodb43.ObjectId(_id);
44472
+ _id = new import_mongodb45.ObjectId(_id);
43763
44473
  } catch (error2) {
43764
- throw new import_nodejs_utils74.BadRequestError(namespace_collection + " Invalid ID.");
44474
+ throw new import_nodejs_utils77.BadRequestError(namespace_collection + " Invalid ID.");
43765
44475
  }
43766
44476
  try {
43767
44477
  const res = await collection.updateOne(
@@ -43772,11 +44482,11 @@ function useBuildingUnitRepo() {
43772
44482
  delCachedData();
43773
44483
  return res;
43774
44484
  } catch (error2) {
43775
- import_nodejs_utils74.logger.log({
44485
+ import_nodejs_utils77.logger.log({
43776
44486
  level: "error",
43777
44487
  message: error2.message
43778
44488
  });
43779
- if (error2 instanceof import_nodejs_utils74.AppError) {
44489
+ if (error2 instanceof import_nodejs_utils77.AppError) {
43780
44490
  throw error2;
43781
44491
  } else {
43782
44492
  throw new Error("Failed to create building unit.");
@@ -43786,12 +44496,12 @@ function useBuildingUnitRepo() {
43786
44496
  async function updateByBuildingId(building, value, session) {
43787
44497
  const { error } = schemaUpdateOptions.validate(value);
43788
44498
  if (error) {
43789
- throw new import_nodejs_utils74.BadRequestError(error.message);
44499
+ throw new import_nodejs_utils77.BadRequestError(error.message);
43790
44500
  }
43791
44501
  try {
43792
- building = new import_mongodb43.ObjectId(building);
44502
+ building = new import_mongodb45.ObjectId(building);
43793
44503
  } catch (error2) {
43794
- throw new import_nodejs_utils74.BadRequestError("Invalid building ID.");
44504
+ throw new import_nodejs_utils77.BadRequestError("Invalid building ID.");
43795
44505
  }
43796
44506
  try {
43797
44507
  const res = await collection.updateMany(
@@ -43802,11 +44512,11 @@ function useBuildingUnitRepo() {
43802
44512
  delCachedData();
43803
44513
  return res;
43804
44514
  } catch (error2) {
43805
- import_nodejs_utils74.logger.log({
44515
+ import_nodejs_utils77.logger.log({
43806
44516
  level: "error",
43807
44517
  message: error2.message
43808
44518
  });
43809
- if (error2 instanceof import_nodejs_utils74.AppError) {
44519
+ if (error2 instanceof import_nodejs_utils77.AppError) {
43810
44520
  throw error2;
43811
44521
  } else {
43812
44522
  throw new Error("Failed to update building unit.");
@@ -43840,17 +44550,17 @@ function useBuildingUnitRepo() {
43840
44550
  }
43841
44551
  if (school) {
43842
44552
  try {
43843
- query.school = new import_mongodb43.ObjectId(school);
44553
+ query.school = new import_mongodb45.ObjectId(school);
43844
44554
  } catch (error) {
43845
- throw new import_nodejs_utils74.BadRequestError("Invalid school ID.");
44555
+ throw new import_nodejs_utils77.BadRequestError("Invalid school ID.");
43846
44556
  }
43847
44557
  cacheParams.school = school;
43848
44558
  }
43849
44559
  if (building) {
43850
44560
  try {
43851
- query.building = new import_mongodb43.ObjectId(building);
44561
+ query.building = new import_mongodb45.ObjectId(building);
43852
44562
  } catch (error) {
43853
- throw new import_nodejs_utils74.BadRequestError("Invalid building ID.");
44563
+ throw new import_nodejs_utils77.BadRequestError("Invalid building ID.");
43854
44564
  }
43855
44565
  cacheParams.building = building;
43856
44566
  }
@@ -43858,15 +44568,15 @@ function useBuildingUnitRepo() {
43858
44568
  query.type = type;
43859
44569
  cacheParams.type = type;
43860
44570
  }
43861
- const cacheKey = (0, import_nodejs_utils74.makeCacheKey)(namespace_collection, cacheParams);
43862
- import_nodejs_utils74.logger.log({
44571
+ const cacheKey = (0, import_nodejs_utils77.makeCacheKey)(namespace_collection, cacheParams);
44572
+ import_nodejs_utils77.logger.log({
43863
44573
  level: "info",
43864
44574
  message: `Cache key for getAll building units: ${cacheKey}`
43865
44575
  });
43866
44576
  try {
43867
44577
  const cached = await getCache(cacheKey);
43868
44578
  if (cached) {
43869
- import_nodejs_utils74.logger.log({
44579
+ import_nodejs_utils77.logger.log({
43870
44580
  level: "info",
43871
44581
  message: `Cache hit for getAll building units: ${cacheKey}`
43872
44582
  });
@@ -43879,21 +44589,21 @@ function useBuildingUnitRepo() {
43879
44589
  { $limit: limit }
43880
44590
  ]).toArray();
43881
44591
  const length = await collection.countDocuments(query);
43882
- const data = (0, import_nodejs_utils74.paginate)(items, page, limit, length);
44592
+ const data = (0, import_nodejs_utils77.paginate)(items, page, limit, length);
43883
44593
  setCache(cacheKey, data, 600).then(() => {
43884
- import_nodejs_utils74.logger.log({
44594
+ import_nodejs_utils77.logger.log({
43885
44595
  level: "info",
43886
44596
  message: `Cache set for getAll building units: ${cacheKey}`
43887
44597
  });
43888
44598
  }).catch((err) => {
43889
- import_nodejs_utils74.logger.log({
44599
+ import_nodejs_utils77.logger.log({
43890
44600
  level: "error",
43891
44601
  message: `Failed to set cache for getAll building units: ${err.message}`
43892
44602
  });
43893
44603
  });
43894
44604
  return data;
43895
44605
  } catch (error) {
43896
- import_nodejs_utils74.logger.log({ level: "error", message: `${error}` });
44606
+ import_nodejs_utils77.logger.log({ level: "error", message: `${error}` });
43897
44607
  throw error;
43898
44608
  }
43899
44609
  }
@@ -43906,10 +44616,10 @@ function useBuildingUnitRepo() {
43906
44616
  tag: "countByBuilding"
43907
44617
  };
43908
44618
  try {
43909
- query.building = new import_mongodb43.ObjectId(building);
44619
+ query.building = new import_mongodb45.ObjectId(building);
43910
44620
  cacheKeyOptions.building = String(building);
43911
44621
  } catch (error) {
43912
- throw new import_nodejs_utils74.BadRequestError("Invalid building ID.");
44622
+ throw new import_nodejs_utils77.BadRequestError("Invalid building ID.");
43913
44623
  }
43914
44624
  if (level) {
43915
44625
  query.level = level;
@@ -43918,21 +44628,21 @@ function useBuildingUnitRepo() {
43918
44628
  try {
43919
44629
  return await collection.countDocuments(query);
43920
44630
  } catch (error) {
43921
- import_nodejs_utils74.logger.log({ level: "error", message: `${error}` });
43922
- 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.");
43923
44633
  }
43924
44634
  }
43925
44635
  async function getById(_id) {
43926
44636
  try {
43927
- _id = new import_mongodb43.ObjectId(_id);
44637
+ _id = new import_mongodb45.ObjectId(_id);
43928
44638
  } catch (error) {
43929
- throw new import_nodejs_utils74.BadRequestError(namespace_collection + " Invalid ID.");
44639
+ throw new import_nodejs_utils77.BadRequestError(namespace_collection + " Invalid ID.");
43930
44640
  }
43931
- 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) });
43932
44642
  try {
43933
44643
  const cached = await getCache(cacheKey);
43934
44644
  if (cached) {
43935
- import_nodejs_utils74.logger.log({
44645
+ import_nodejs_utils77.logger.log({
43936
44646
  level: "info",
43937
44647
  message: `Cache hit for getById building unit: ${cacheKey}`
43938
44648
  });
@@ -43943,42 +44653,42 @@ function useBuildingUnitRepo() {
43943
44653
  deletedAt: { $in: ["", null] }
43944
44654
  });
43945
44655
  if (!result) {
43946
- throw new import_nodejs_utils74.BadRequestError("Building unit not found.");
44656
+ throw new import_nodejs_utils77.BadRequestError("Building unit not found.");
43947
44657
  }
43948
44658
  setCache(cacheKey, result, 300).then(() => {
43949
- import_nodejs_utils74.logger.log({
44659
+ import_nodejs_utils77.logger.log({
43950
44660
  level: "info",
43951
44661
  message: `Cache set for building unit by id: ${cacheKey}`
43952
44662
  });
43953
44663
  }).catch((err) => {
43954
- import_nodejs_utils74.logger.log({
44664
+ import_nodejs_utils77.logger.log({
43955
44665
  level: "error",
43956
44666
  message: `Failed to set cache for building unit by id: ${err.message}`
43957
44667
  });
43958
44668
  });
43959
44669
  return result;
43960
44670
  } catch (error) {
43961
- if (error instanceof import_nodejs_utils74.AppError) {
44671
+ if (error instanceof import_nodejs_utils77.AppError) {
43962
44672
  throw error;
43963
44673
  } else {
43964
- throw new import_nodejs_utils74.InternalServerError("Failed to get building unit.");
44674
+ throw new import_nodejs_utils77.InternalServerError("Failed to get building unit.");
43965
44675
  }
43966
44676
  }
43967
44677
  }
43968
44678
  async function getByBuildingLevel(building, level) {
43969
44679
  try {
43970
- building = new import_mongodb43.ObjectId(building);
44680
+ building = new import_mongodb45.ObjectId(building);
43971
44681
  } catch (error) {
43972
- throw new import_nodejs_utils74.BadRequestError("Invalid building ID.");
44682
+ throw new import_nodejs_utils77.BadRequestError("Invalid building ID.");
43973
44683
  }
43974
- const cacheKey = (0, import_nodejs_utils74.makeCacheKey)(namespace_collection, {
44684
+ const cacheKey = (0, import_nodejs_utils77.makeCacheKey)(namespace_collection, {
43975
44685
  building: String(building),
43976
44686
  level
43977
44687
  });
43978
44688
  try {
43979
44689
  const cached = await getCache(cacheKey);
43980
44690
  if (cached) {
43981
- import_nodejs_utils74.logger.log({
44691
+ import_nodejs_utils77.logger.log({
43982
44692
  level: "info",
43983
44693
  message: `Cache hit for getById building unit: ${cacheKey}`
43984
44694
  });
@@ -43990,38 +44700,38 @@ function useBuildingUnitRepo() {
43990
44700
  status: "active"
43991
44701
  });
43992
44702
  setCache(cacheKey, result, 300).then(() => {
43993
- import_nodejs_utils74.logger.log({
44703
+ import_nodejs_utils77.logger.log({
43994
44704
  level: "info",
43995
44705
  message: `Cache set for building unit by id: ${cacheKey}`
43996
44706
  });
43997
44707
  }).catch((err) => {
43998
- import_nodejs_utils74.logger.log({
44708
+ import_nodejs_utils77.logger.log({
43999
44709
  level: "error",
44000
44710
  message: `Failed to set cache for building unit by id: ${err.message}`
44001
44711
  });
44002
44712
  });
44003
44713
  return result;
44004
44714
  } catch (error) {
44005
- if (error instanceof import_nodejs_utils74.AppError) {
44715
+ if (error instanceof import_nodejs_utils77.AppError) {
44006
44716
  throw error;
44007
44717
  } else {
44008
- throw new import_nodejs_utils74.InternalServerError("Failed to get building unit.");
44718
+ throw new import_nodejs_utils77.InternalServerError("Failed to get building unit.");
44009
44719
  }
44010
44720
  }
44011
44721
  }
44012
44722
  async function getByBuilding(building) {
44013
44723
  try {
44014
- building = new import_mongodb43.ObjectId(building);
44724
+ building = new import_mongodb45.ObjectId(building);
44015
44725
  } catch (error) {
44016
- throw new import_nodejs_utils74.BadRequestError("Invalid building ID.");
44726
+ throw new import_nodejs_utils77.BadRequestError("Invalid building ID.");
44017
44727
  }
44018
- const cacheKey = (0, import_nodejs_utils74.makeCacheKey)(namespace_collection, {
44728
+ const cacheKey = (0, import_nodejs_utils77.makeCacheKey)(namespace_collection, {
44019
44729
  building: String(building)
44020
44730
  });
44021
44731
  try {
44022
44732
  const cached = await getCache(cacheKey);
44023
44733
  if (cached) {
44024
- import_nodejs_utils74.logger.log({
44734
+ import_nodejs_utils77.logger.log({
44025
44735
  level: "info",
44026
44736
  message: `Cache hit for getById building unit: ${cacheKey}`
44027
44737
  });
@@ -44032,30 +44742,30 @@ function useBuildingUnitRepo() {
44032
44742
  status: "active"
44033
44743
  });
44034
44744
  setCache(cacheKey, result, 300).then(() => {
44035
- import_nodejs_utils74.logger.log({
44745
+ import_nodejs_utils77.logger.log({
44036
44746
  level: "info",
44037
44747
  message: `Cache set for building unit by id: ${cacheKey}`
44038
44748
  });
44039
44749
  }).catch((err) => {
44040
- import_nodejs_utils74.logger.log({
44750
+ import_nodejs_utils77.logger.log({
44041
44751
  level: "error",
44042
44752
  message: `Failed to set cache for building unit by id: ${err.message}`
44043
44753
  });
44044
44754
  });
44045
44755
  return result;
44046
44756
  } catch (error) {
44047
- if (error instanceof import_nodejs_utils74.AppError) {
44757
+ if (error instanceof import_nodejs_utils77.AppError) {
44048
44758
  throw error;
44049
44759
  } else {
44050
- throw new import_nodejs_utils74.InternalServerError("Failed to get building unit.");
44760
+ throw new import_nodejs_utils77.InternalServerError("Failed to get building unit.");
44051
44761
  }
44052
44762
  }
44053
44763
  }
44054
44764
  async function deleteById(_id, session) {
44055
44765
  try {
44056
- _id = new import_mongodb43.ObjectId(_id);
44766
+ _id = new import_mongodb45.ObjectId(_id);
44057
44767
  } catch (error) {
44058
- throw new import_nodejs_utils74.BadRequestError(namespace_collection + " Invalid ID.");
44768
+ throw new import_nodejs_utils77.BadRequestError(namespace_collection + " Invalid ID.");
44059
44769
  }
44060
44770
  try {
44061
44771
  const res = await collection.updateOne(
@@ -44066,11 +44776,11 @@ function useBuildingUnitRepo() {
44066
44776
  delCachedData();
44067
44777
  return "Room/Facility deleted successfully.";
44068
44778
  } catch (error) {
44069
- import_nodejs_utils74.logger.log({
44779
+ import_nodejs_utils77.logger.log({
44070
44780
  level: "error",
44071
44781
  message: error.message
44072
44782
  });
44073
- if (error instanceof import_nodejs_utils74.AppError) {
44783
+ if (error instanceof import_nodejs_utils77.AppError) {
44074
44784
  throw error;
44075
44785
  } else {
44076
44786
  throw new Error("Failed to deleted room/facility.");
@@ -44101,16 +44811,16 @@ function useBuildingService() {
44101
44811
  const { getByBuildingLevel, getByBuilding, updateByBuildingId } = useBuildingUnitRepo();
44102
44812
  async function updateById(id, data) {
44103
44813
  data.levels = Number(data.levels);
44104
- const session = import_nodejs_utils75.useAtlas.getClient()?.startSession();
44814
+ const session = import_nodejs_utils78.useAtlas.getClient()?.startSession();
44105
44815
  try {
44106
44816
  const building = await _getById(id);
44107
44817
  if (!building) {
44108
- throw new import_nodejs_utils75.NotFoundError("Building not found.");
44818
+ throw new import_nodejs_utils78.NotFoundError("Building not found.");
44109
44819
  }
44110
44820
  if (data.levels < building.levels) {
44111
44821
  const unit = await getByBuildingLevel(id, building.levels);
44112
44822
  if (unit) {
44113
- throw new import_nodejs_utils75.BadRequestError(
44823
+ throw new import_nodejs_utils78.BadRequestError(
44114
44824
  "Cannot reduce floors, there are existing building units at higher floors."
44115
44825
  );
44116
44826
  }
@@ -44132,7 +44842,7 @@ function useBuildingService() {
44132
44842
  async function deleteById(id) {
44133
44843
  const building = await getByBuilding(id);
44134
44844
  if (building) {
44135
- throw new import_nodejs_utils75.BadRequestError(
44845
+ throw new import_nodejs_utils78.BadRequestError(
44136
44846
  "Cannot delete building with existing room/facility. Please delete room/facility first."
44137
44847
  );
44138
44848
  }
@@ -44150,24 +44860,24 @@ function useBuildingService() {
44150
44860
  }
44151
44861
 
44152
44862
  // src/resources/building/building.controller.ts
44153
- var import_nodejs_utils76 = require("@eeplatform/nodejs-utils");
44154
- var import_joi46 = __toESM(require("joi"));
44863
+ var import_nodejs_utils79 = require("@eeplatform/nodejs-utils");
44864
+ var import_joi48 = __toESM(require("joi"));
44155
44865
  function useBuildingController() {
44156
44866
  const { getAll: _getAll, getById: _getById, add: _add } = useBuildingRepo();
44157
44867
  const { updateById: _updateById, deleteById: _deleteById } = useBuildingService();
44158
44868
  async function createBuilding(req, res, next) {
44159
44869
  const value = req.body;
44160
- const validation = import_joi46.default.object({
44161
- name: import_joi46.default.string().required(),
44162
- school: import_joi46.default.string().hex().required(),
44163
- levels: import_joi46.default.number().integer().min(1).required(),
44164
- serial: import_joi46.default.string().optional().allow("", null),
44165
- 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)
44166
44876
  });
44167
44877
  const { error } = validation.validate(value);
44168
44878
  if (error) {
44169
- next(new import_nodejs_utils76.BadRequestError(error.message));
44170
- 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}`);
44171
44881
  return;
44172
44882
  }
44173
44883
  try {
@@ -44181,18 +44891,18 @@ function useBuildingController() {
44181
44891
  async function updateById(req, res, next) {
44182
44892
  const value = req.body;
44183
44893
  const id = req.params.id ?? "";
44184
- const validation = import_joi46.default.object({
44185
- id: import_joi46.default.string().hex().required(),
44186
- value: import_joi46.default.object({
44187
- name: import_joi46.default.string().required(),
44188
- serial: import_joi46.default.string().optional().allow("", null),
44189
- 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()
44190
44900
  })
44191
44901
  });
44192
44902
  const { error } = validation.validate({ id, value });
44193
44903
  if (error) {
44194
- next(new import_nodejs_utils76.BadRequestError(error.message));
44195
- 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}`);
44196
44906
  return;
44197
44907
  }
44198
44908
  try {
@@ -44205,16 +44915,16 @@ function useBuildingController() {
44205
44915
  }
44206
44916
  async function getAll(req, res, next) {
44207
44917
  const query = req.query;
44208
- const validation = import_joi46.default.object({
44209
- page: import_joi46.default.number().min(1).optional().allow("", null),
44210
- limit: import_joi46.default.number().min(1).optional().allow("", null),
44211
- search: import_joi46.default.string().optional().allow("", null),
44212
- school: import_joi46.default.string().hex().optional().allow("", null),
44213
- 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)
44214
44924
  });
44215
44925
  const { error } = validation.validate(query);
44216
44926
  if (error) {
44217
- next(new import_nodejs_utils76.BadRequestError(error.message));
44927
+ next(new import_nodejs_utils79.BadRequestError(error.message));
44218
44928
  return;
44219
44929
  }
44220
44930
  const page = parseInt(req.query.page) ?? 1;
@@ -44248,12 +44958,12 @@ function useBuildingController() {
44248
44958
  }
44249
44959
  async function getById(req, res, next) {
44250
44960
  const id = req.params.id;
44251
- const validation = import_joi46.default.object({
44252
- id: import_joi46.default.string().hex().required()
44961
+ const validation = import_joi48.default.object({
44962
+ id: import_joi48.default.string().hex().required()
44253
44963
  });
44254
44964
  const { error } = validation.validate({ id });
44255
44965
  if (error) {
44256
- next(new import_nodejs_utils76.BadRequestError(error.message));
44966
+ next(new import_nodejs_utils79.BadRequestError(error.message));
44257
44967
  return;
44258
44968
  }
44259
44969
  try {
@@ -44269,12 +44979,12 @@ function useBuildingController() {
44269
44979
  }
44270
44980
  async function deleteById(req, res, next) {
44271
44981
  const id = req.params.id;
44272
- const validation = import_joi46.default.object({
44273
- id: import_joi46.default.string().hex().required()
44982
+ const validation = import_joi48.default.object({
44983
+ id: import_joi48.default.string().hex().required()
44274
44984
  });
44275
44985
  const { error } = validation.validate({ id });
44276
44986
  if (error) {
44277
- next(new import_nodejs_utils76.BadRequestError(error.message));
44987
+ next(new import_nodejs_utils79.BadRequestError(error.message));
44278
44988
  return;
44279
44989
  }
44280
44990
  try {
@@ -44295,7 +45005,7 @@ function useBuildingController() {
44295
45005
  }
44296
45006
 
44297
45007
  // src/resources/building/building-unit.service.ts
44298
- var import_nodejs_utils77 = require("@eeplatform/nodejs-utils");
45008
+ var import_nodejs_utils80 = require("@eeplatform/nodejs-utils");
44299
45009
  function useBuildingUnitService() {
44300
45010
  const {
44301
45011
  add: _add,
@@ -44303,7 +45013,7 @@ function useBuildingUnitService() {
44303
45013
  deleteById: _deleteById
44304
45014
  } = useBuildingUnitRepo();
44305
45015
  async function add(value) {
44306
- const session = import_nodejs_utils77.useAtlas.getClient()?.startSession();
45016
+ const session = import_nodejs_utils80.useAtlas.getClient()?.startSession();
44307
45017
  if (!session) {
44308
45018
  throw new Error("Unable to start session for building unit service.");
44309
45019
  }
@@ -44354,8 +45064,8 @@ function useBuildingUnitService() {
44354
45064
  }
44355
45065
 
44356
45066
  // src/resources/building/building-unit.controller.ts
44357
- var import_nodejs_utils78 = require("@eeplatform/nodejs-utils");
44358
- var import_joi47 = __toESM(require("joi"));
45067
+ var import_nodejs_utils81 = require("@eeplatform/nodejs-utils");
45068
+ var import_joi49 = __toESM(require("joi"));
44359
45069
  function useBuildingUnitController() {
44360
45070
  const {
44361
45071
  getAll: _getAll,
@@ -44365,27 +45075,27 @@ function useBuildingUnitController() {
44365
45075
  const { add: _add, deleteById: _deleteById } = useBuildingUnitService();
44366
45076
  async function add(req, res, next) {
44367
45077
  const data = req.body;
44368
- const validation = import_joi47.default.object({
44369
- building: import_joi47.default.object({
44370
- school: import_joi47.default.string().hex().required(),
44371
- name: import_joi47.default.string().optional().allow("", null),
44372
- building: import_joi47.default.string().hex().required(),
44373
- buildingName: import_joi47.default.string().optional().allow("", null),
44374
- level: import_joi47.default.number().integer().min(1).required(),
44375
- category: import_joi47.default.string().required(),
44376
- type: import_joi47.default.string().required(),
44377
- seating_capacity: import_joi47.default.number().integer().min(0).required(),
44378
- standing_capacity: import_joi47.default.number().integer().min(0).required(),
44379
- description: import_joi47.default.string().optional().allow("", null),
44380
- unit_of_measurement: import_joi47.default.string().valid("sqm").required(),
44381
- area: import_joi47.default.number().positive().required(),
44382
- 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)
44383
45093
  }),
44384
- 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)
44385
45095
  });
44386
45096
  const { error } = validation.validate(data);
44387
45097
  if (error) {
44388
- next(new import_nodejs_utils78.BadRequestError(error.message));
45098
+ next(new import_nodejs_utils81.BadRequestError(error.message));
44389
45099
  return;
44390
45100
  }
44391
45101
  try {
@@ -44401,13 +45111,13 @@ function useBuildingUnitController() {
44401
45111
  async function updateById(req, res, next) {
44402
45112
  const data = req.body;
44403
45113
  const id = req.params.id ?? "";
44404
- const validation = import_joi47.default.object({
44405
- id: import_joi47.default.string().hex().required(),
45114
+ const validation = import_joi49.default.object({
45115
+ id: import_joi49.default.string().hex().required(),
44406
45116
  value: schemaUpdateOptions
44407
45117
  });
44408
45118
  const { error } = validation.validate({ id, value: data });
44409
45119
  if (error) {
44410
- next(new import_nodejs_utils78.BadRequestError(error.message));
45120
+ next(new import_nodejs_utils81.BadRequestError(error.message));
44411
45121
  return;
44412
45122
  }
44413
45123
  try {
@@ -44422,18 +45132,18 @@ function useBuildingUnitController() {
44422
45132
  }
44423
45133
  async function getAll(req, res, next) {
44424
45134
  const query = req.query;
44425
- const validation = import_joi47.default.object({
44426
- page: import_joi47.default.number().min(1).optional().allow("", null),
44427
- limit: import_joi47.default.number().min(1).optional().allow("", null),
44428
- search: import_joi47.default.string().optional().allow("", null),
44429
- school: import_joi47.default.string().hex().optional().allow("", null),
44430
- building: import_joi47.default.string().hex().optional().allow("", null),
44431
- status: import_joi47.default.string().optional().allow("", null),
44432
- 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)
44433
45143
  });
44434
45144
  const { error } = validation.validate(query);
44435
45145
  if (error) {
44436
- next(new import_nodejs_utils78.BadRequestError(error.message));
45146
+ next(new import_nodejs_utils81.BadRequestError(error.message));
44437
45147
  return;
44438
45148
  }
44439
45149
  const page = parseInt(req.query.page) ?? 1;
@@ -44471,12 +45181,12 @@ function useBuildingUnitController() {
44471
45181
  }
44472
45182
  async function getById(req, res, next) {
44473
45183
  const id = req.params.id;
44474
- const validation = import_joi47.default.object({
44475
- id: import_joi47.default.string().hex().required()
45184
+ const validation = import_joi49.default.object({
45185
+ id: import_joi49.default.string().hex().required()
44476
45186
  });
44477
45187
  const { error } = validation.validate({ id });
44478
45188
  if (error) {
44479
- next(new import_nodejs_utils78.BadRequestError(error.message));
45189
+ next(new import_nodejs_utils81.BadRequestError(error.message));
44480
45190
  return;
44481
45191
  }
44482
45192
  try {
@@ -44492,12 +45202,12 @@ function useBuildingUnitController() {
44492
45202
  }
44493
45203
  async function deleteById(req, res, next) {
44494
45204
  const id = req.params.id;
44495
- const validation = import_joi47.default.object({
44496
- id: import_joi47.default.string().hex().required()
45205
+ const validation = import_joi49.default.object({
45206
+ id: import_joi49.default.string().hex().required()
44497
45207
  });
44498
45208
  const { error } = validation.validate({ id });
44499
45209
  if (error) {
44500
- next(new import_nodejs_utils78.BadRequestError(error.message));
45210
+ next(new import_nodejs_utils81.BadRequestError(error.message));
44501
45211
  return;
44502
45212
  }
44503
45213
  try {
@@ -44517,6 +45227,579 @@ function useBuildingUnitController() {
44517
45227
  };
44518
45228
  }
44519
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
+
44520
45803
  // src/config.ts
44521
45804
  var dotenv = __toESM(require("dotenv"));
44522
45805
  dotenv.config();
@@ -44534,6 +45817,8 @@ dotenv.config();
44534
45817
  allowedSectionStudentStatuses,
44535
45818
  modelBasicEduCount,
44536
45819
  modelDivision,
45820
+ modelKindergartenDomain,
45821
+ modelKindergartenRoutine,
44537
45822
  modelProgram,
44538
45823
  modelProgramScreening,
44539
45824
  modelRegion,
@@ -44556,6 +45841,9 @@ dotenv.config();
44556
45841
  schemaEnrollment,
44557
45842
  schemaGenerateSections,
44558
45843
  schemaGradeLevel,
45844
+ schemaKindergartenDomain,
45845
+ schemaKindergartenRoutine,
45846
+ schemaKindergartenRoutineUpdate,
44559
45847
  schemaPersonnel,
44560
45848
  schemaPlantilla,
44561
45849
  schemaProgram,
@@ -44597,6 +45885,11 @@ dotenv.config();
44597
45885
  useEnrollmentService,
44598
45886
  useGradeLevelController,
44599
45887
  useGradeLevelRepo,
45888
+ useKindergartenDomainController,
45889
+ useKindergartenDomainRepo,
45890
+ useKindergartenDomainService,
45891
+ useKindergartenRoutineController,
45892
+ useKindergartenRoutineRepo,
44600
45893
  useLearnerController,
44601
45894
  useLearnerRepo,
44602
45895
  usePersonnelController,