@eeplatform/basic-edu 1.6.0 → 1.7.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/CHANGELOG.md +6 -0
- package/CONVENTION.md +632 -0
- package/dist/index.d.ts +23 -2
- package/dist/index.js +635 -425
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +560 -349
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1426,6 +1426,7 @@ __export(src_exports, {
|
|
|
1426
1426
|
useSectionPresetController: () => useSectionPresetController,
|
|
1427
1427
|
useSectionPresetRepo: () => useSectionPresetRepo,
|
|
1428
1428
|
useSectionRepo: () => useSectionRepo,
|
|
1429
|
+
useSectionStudentController: () => useSectionStudentController,
|
|
1429
1430
|
useSectionStudentRepo: () => useSectionStudentRepo,
|
|
1430
1431
|
useSectionSubjectController: () => useSectionSubjectController,
|
|
1431
1432
|
useSectionSubjectRepo: () => useSectionSubjectRepo,
|
|
@@ -37847,7 +37848,7 @@ function useSectionRepo() {
|
|
|
37847
37848
|
|
|
37848
37849
|
// src/resources/section/section.controller.ts
|
|
37849
37850
|
var import_nodejs_utils53 = require("@eeplatform/nodejs-utils");
|
|
37850
|
-
var
|
|
37851
|
+
var import_joi32 = __toESM(require("joi"));
|
|
37851
37852
|
|
|
37852
37853
|
// src/resources/section/section.service.ts
|
|
37853
37854
|
var import_nodejs_utils52 = require("@eeplatform/nodejs-utils");
|
|
@@ -37867,9 +37868,15 @@ var allowedSectionStudentStatuses = [
|
|
|
37867
37868
|
];
|
|
37868
37869
|
var schemaSectionStudent = import_joi28.default.object({
|
|
37869
37870
|
_id: import_joi28.default.string().hex().optional().allow(null, ""),
|
|
37871
|
+
lrn: import_joi28.default.string().required(),
|
|
37872
|
+
school: import_joi28.default.string().hex().required(),
|
|
37873
|
+
schoolName: import_joi28.default.string().optional().allow(null, ""),
|
|
37870
37874
|
section: import_joi28.default.string().hex().required(),
|
|
37871
37875
|
student: import_joi28.default.string().required(),
|
|
37872
37876
|
studentName: import_joi28.default.string().required(),
|
|
37877
|
+
gradeLevel: import_joi28.default.string().optional().allow(null, ""),
|
|
37878
|
+
educationLevel: import_joi28.default.string().optional().allow(null, ""),
|
|
37879
|
+
schoolYear: import_joi28.default.string().optional().allow(null, ""),
|
|
37873
37880
|
status: import_joi28.default.string().valid(...allowedSectionStudentStatuses).optional().allow(null, ""),
|
|
37874
37881
|
assignedAt: import_joi28.default.string().isoDate().optional().allow(null, ""),
|
|
37875
37882
|
updatedAt: import_joi28.default.string().isoDate().optional().allow(null, "")
|
|
@@ -37893,11 +37900,24 @@ function modelSectionStudent(value) {
|
|
|
37893
37900
|
throw new Error("Invalid section ID.");
|
|
37894
37901
|
}
|
|
37895
37902
|
}
|
|
37903
|
+
if (value.school && typeof value.school === "string") {
|
|
37904
|
+
try {
|
|
37905
|
+
value.school = new import_mongodb27.ObjectId(value.school);
|
|
37906
|
+
} catch (error2) {
|
|
37907
|
+
throw new Error("Invalid school ID.");
|
|
37908
|
+
}
|
|
37909
|
+
}
|
|
37896
37910
|
return {
|
|
37897
37911
|
_id: value._id,
|
|
37912
|
+
lrn: value.lrn,
|
|
37913
|
+
school: value.school,
|
|
37914
|
+
schoolName: value.schoolName,
|
|
37898
37915
|
section: value.section,
|
|
37899
37916
|
student: value.student,
|
|
37900
37917
|
studentName: value.studentName,
|
|
37918
|
+
gradeLevel: value.gradeLevel,
|
|
37919
|
+
educationLevel: value.educationLevel,
|
|
37920
|
+
schoolYear: value.schoolYear,
|
|
37901
37921
|
status: value.status ?? "active",
|
|
37902
37922
|
assignedAt: value.assignedAt ?? "",
|
|
37903
37923
|
updatedAt: value.updatedAt ?? ""
|
|
@@ -37905,6 +37925,8 @@ function modelSectionStudent(value) {
|
|
|
37905
37925
|
}
|
|
37906
37926
|
|
|
37907
37927
|
// src/resources/section-student/section.student.repository.ts
|
|
37928
|
+
var import_mongodb28 = require("mongodb");
|
|
37929
|
+
var import_joi29 = __toESM(require("joi"));
|
|
37908
37930
|
function useSectionStudentRepo() {
|
|
37909
37931
|
const db = import_nodejs_utils47.useAtlas.getDb();
|
|
37910
37932
|
if (!db) {
|
|
@@ -37968,48 +37990,140 @@ function useSectionStudentRepo() {
|
|
|
37968
37990
|
}
|
|
37969
37991
|
}
|
|
37970
37992
|
}
|
|
37993
|
+
async function getAll({
|
|
37994
|
+
page = 1,
|
|
37995
|
+
limit = 10,
|
|
37996
|
+
search = "",
|
|
37997
|
+
school = "",
|
|
37998
|
+
status = "",
|
|
37999
|
+
gradeLevel = "",
|
|
38000
|
+
section = "",
|
|
38001
|
+
schoolYear = ""
|
|
38002
|
+
} = {}) {
|
|
38003
|
+
const { error } = import_joi29.default.object({
|
|
38004
|
+
page: import_joi29.default.number().min(1).default(1),
|
|
38005
|
+
limit: import_joi29.default.number().min(1).max(100).default(10),
|
|
38006
|
+
search: import_joi29.default.string().allow("").default(""),
|
|
38007
|
+
status: import_joi29.default.string().allow("").default(""),
|
|
38008
|
+
school: import_joi29.default.string().hex().allow("").default(""),
|
|
38009
|
+
gradeLevel: import_joi29.default.string().allow("").default(""),
|
|
38010
|
+
section: import_joi29.default.string().hex().allow("").default(""),
|
|
38011
|
+
schoolYear: import_joi29.default.string().allow("").default("")
|
|
38012
|
+
}).validate({ page, limit, search, status, school, gradeLevel, section });
|
|
38013
|
+
if (error) {
|
|
38014
|
+
throw new import_nodejs_utils47.BadRequestError(error.details[0].message);
|
|
38015
|
+
}
|
|
38016
|
+
const query = { status: { $ne: "deleted" } };
|
|
38017
|
+
const cacheKeyOptions = { page, limit };
|
|
38018
|
+
if (status) {
|
|
38019
|
+
query.status = status;
|
|
38020
|
+
cacheKeyOptions.status = status;
|
|
38021
|
+
}
|
|
38022
|
+
if (school && typeof school === "string") {
|
|
38023
|
+
try {
|
|
38024
|
+
query.school = new import_mongodb28.ObjectId(school);
|
|
38025
|
+
} catch (error2) {
|
|
38026
|
+
throw new import_nodejs_utils47.BadRequestError("Invalid school ID format.");
|
|
38027
|
+
}
|
|
38028
|
+
cacheKeyOptions.school = school;
|
|
38029
|
+
}
|
|
38030
|
+
if (gradeLevel) {
|
|
38031
|
+
query.gradeLevel = gradeLevel;
|
|
38032
|
+
cacheKeyOptions.gradeLevel = gradeLevel;
|
|
38033
|
+
}
|
|
38034
|
+
if (search) {
|
|
38035
|
+
query.$text = { $search: search };
|
|
38036
|
+
cacheKeyOptions.search = search;
|
|
38037
|
+
}
|
|
38038
|
+
if (section && typeof section === "string") {
|
|
38039
|
+
try {
|
|
38040
|
+
query.section = new import_mongodb28.ObjectId(section);
|
|
38041
|
+
} catch (error2) {
|
|
38042
|
+
throw new import_nodejs_utils47.BadRequestError("Invalid section ID format.");
|
|
38043
|
+
}
|
|
38044
|
+
cacheKeyOptions.section = section;
|
|
38045
|
+
}
|
|
38046
|
+
if (schoolYear) {
|
|
38047
|
+
query.schoolYear = schoolYear;
|
|
38048
|
+
cacheKeyOptions.schoolYear = schoolYear;
|
|
38049
|
+
}
|
|
38050
|
+
const cacheKey = (0, import_nodejs_utils47.makeCacheKey)(namespace_collection, cacheKeyOptions);
|
|
38051
|
+
import_nodejs_utils47.logger.log({
|
|
38052
|
+
level: "info",
|
|
38053
|
+
message: `Cache key for getAll sections: ${cacheKey}`
|
|
38054
|
+
});
|
|
38055
|
+
const cachedData = await getCache(cacheKey);
|
|
38056
|
+
if (cachedData) {
|
|
38057
|
+
import_nodejs_utils47.logger.log({
|
|
38058
|
+
level: "info",
|
|
38059
|
+
message: `Cache hit for getAll sections: ${cacheKey}`
|
|
38060
|
+
});
|
|
38061
|
+
return cachedData;
|
|
38062
|
+
}
|
|
38063
|
+
page = page > 0 ? page - 1 : 0;
|
|
38064
|
+
const items = await collection.aggregate([
|
|
38065
|
+
{ $match: query },
|
|
38066
|
+
{ $skip: page * limit },
|
|
38067
|
+
{ $limit: limit }
|
|
38068
|
+
]).toArray();
|
|
38069
|
+
const length = await collection.countDocuments(query);
|
|
38070
|
+
const data = (0, import_nodejs_utils47.paginate)(items, page, limit, length);
|
|
38071
|
+
setCache(cacheKey, data, 600).then(() => {
|
|
38072
|
+
import_nodejs_utils47.logger.log({
|
|
38073
|
+
level: "info",
|
|
38074
|
+
message: `Cache set for getAll section students: ${cacheKey}`
|
|
38075
|
+
});
|
|
38076
|
+
}).catch((err) => {
|
|
38077
|
+
import_nodejs_utils47.logger.log({
|
|
38078
|
+
level: "error",
|
|
38079
|
+
message: `Failed to set cache for getAll section students: ${err.message}`
|
|
38080
|
+
});
|
|
38081
|
+
});
|
|
38082
|
+
return data;
|
|
38083
|
+
}
|
|
37971
38084
|
return {
|
|
37972
38085
|
createIndexes,
|
|
37973
38086
|
delCachedData,
|
|
37974
|
-
add
|
|
38087
|
+
add,
|
|
38088
|
+
getAll
|
|
37975
38089
|
};
|
|
37976
38090
|
}
|
|
37977
38091
|
|
|
37978
38092
|
// src/resources/section-subject/section.subject.model.ts
|
|
37979
38093
|
var import_nodejs_utils48 = require("@eeplatform/nodejs-utils");
|
|
37980
|
-
var
|
|
37981
|
-
var
|
|
37982
|
-
var schemaSectionSubject =
|
|
37983
|
-
_id:
|
|
37984
|
-
school:
|
|
37985
|
-
schoolName:
|
|
37986
|
-
section:
|
|
37987
|
-
sectionName:
|
|
37988
|
-
gradeLevel:
|
|
37989
|
-
educationLevel:
|
|
37990
|
-
schoolYear:
|
|
37991
|
-
subjectCode:
|
|
37992
|
-
subjectName:
|
|
37993
|
-
teacher:
|
|
37994
|
-
teacherName:
|
|
37995
|
-
classroom:
|
|
37996
|
-
classroomName:
|
|
37997
|
-
daysOfWeek:
|
|
37998
|
-
schedule:
|
|
37999
|
-
sessionDuration:
|
|
38000
|
-
sessionFrequency:
|
|
38001
|
-
status:
|
|
38002
|
-
createdAt:
|
|
38003
|
-
updatedAt:
|
|
38004
|
-
deletedAt:
|
|
38094
|
+
var import_joi30 = __toESM(require("joi"));
|
|
38095
|
+
var import_mongodb29 = require("mongodb");
|
|
38096
|
+
var schemaSectionSubject = import_joi30.default.object({
|
|
38097
|
+
_id: import_joi30.default.string().hex().optional().allow(null, ""),
|
|
38098
|
+
school: import_joi30.default.string().hex().required(),
|
|
38099
|
+
schoolName: import_joi30.default.string().optional().allow(null, ""),
|
|
38100
|
+
section: import_joi30.default.string().hex().required(),
|
|
38101
|
+
sectionName: import_joi30.default.string().required(),
|
|
38102
|
+
gradeLevel: import_joi30.default.string().required(),
|
|
38103
|
+
educationLevel: import_joi30.default.string().required(),
|
|
38104
|
+
schoolYear: import_joi30.default.string().required(),
|
|
38105
|
+
subjectCode: import_joi30.default.string().required(),
|
|
38106
|
+
subjectName: import_joi30.default.string().required(),
|
|
38107
|
+
teacher: import_joi30.default.string().hex().optional().allow(null, ""),
|
|
38108
|
+
teacherName: import_joi30.default.string().optional().allow(null, ""),
|
|
38109
|
+
classroom: import_joi30.default.string().optional().allow(null, ""),
|
|
38110
|
+
classroomName: import_joi30.default.string().optional().allow(null, ""),
|
|
38111
|
+
daysOfWeek: import_joi30.default.array().items(import_joi30.default.string()).optional().allow(null),
|
|
38112
|
+
schedule: import_joi30.default.string().optional().allow(null, ""),
|
|
38113
|
+
sessionDuration: import_joi30.default.number().optional().allow(null, 0),
|
|
38114
|
+
sessionFrequency: import_joi30.default.number().optional().allow(null, 0),
|
|
38115
|
+
status: import_joi30.default.string().valid("active", "draft").optional(),
|
|
38116
|
+
createdAt: import_joi30.default.string().isoDate().optional().allow(null, ""),
|
|
38117
|
+
updatedAt: import_joi30.default.string().isoDate().optional().allow(null, ""),
|
|
38118
|
+
deletedAt: import_joi30.default.string().isoDate().optional().allow(null, "")
|
|
38005
38119
|
});
|
|
38006
|
-
var schemaSectionSubjectSetup =
|
|
38007
|
-
teacher:
|
|
38008
|
-
teacherName:
|
|
38009
|
-
classroom:
|
|
38010
|
-
classroomName:
|
|
38011
|
-
daysOfWeek:
|
|
38012
|
-
schedule:
|
|
38120
|
+
var schemaSectionSubjectSetup = import_joi30.default.object({
|
|
38121
|
+
teacher: import_joi30.default.string().hex().optional().allow(null, ""),
|
|
38122
|
+
teacherName: import_joi30.default.string().optional().allow(null, ""),
|
|
38123
|
+
classroom: import_joi30.default.string().optional().allow(null, ""),
|
|
38124
|
+
classroomName: import_joi30.default.string().optional().allow(null, ""),
|
|
38125
|
+
daysOfWeek: import_joi30.default.array().items(import_joi30.default.string()).optional().allow(null),
|
|
38126
|
+
schedule: import_joi30.default.string().optional().allow(null, "")
|
|
38013
38127
|
});
|
|
38014
38128
|
function modelSectionSubject(value) {
|
|
38015
38129
|
const { error } = schemaSectionSubject.validate(value);
|
|
@@ -38018,28 +38132,28 @@ function modelSectionSubject(value) {
|
|
|
38018
38132
|
}
|
|
38019
38133
|
if (value._id && typeof value._id === "string") {
|
|
38020
38134
|
try {
|
|
38021
|
-
value._id = new
|
|
38135
|
+
value._id = new import_mongodb29.ObjectId(value._id);
|
|
38022
38136
|
} catch (error2) {
|
|
38023
38137
|
throw new Error("Invalid _id.");
|
|
38024
38138
|
}
|
|
38025
38139
|
}
|
|
38026
38140
|
if (value.school && typeof value.school === "string") {
|
|
38027
38141
|
try {
|
|
38028
|
-
value.school = new
|
|
38142
|
+
value.school = new import_mongodb29.ObjectId(value.school);
|
|
38029
38143
|
} catch (error2) {
|
|
38030
38144
|
throw new Error("Invalid school ID.");
|
|
38031
38145
|
}
|
|
38032
38146
|
}
|
|
38033
38147
|
if (value.section && typeof value.section === "string") {
|
|
38034
38148
|
try {
|
|
38035
|
-
value.section = new
|
|
38149
|
+
value.section = new import_mongodb29.ObjectId(value.section);
|
|
38036
38150
|
} catch (error2) {
|
|
38037
38151
|
throw new Error("Invalid section ID.");
|
|
38038
38152
|
}
|
|
38039
38153
|
}
|
|
38040
38154
|
if (value.teacher && typeof value.teacher === "string") {
|
|
38041
38155
|
try {
|
|
38042
|
-
value.teacher = new
|
|
38156
|
+
value.teacher = new import_mongodb29.ObjectId(value.teacher);
|
|
38043
38157
|
} catch (error2) {
|
|
38044
38158
|
throw new Error("Invalid teacher ID.");
|
|
38045
38159
|
}
|
|
@@ -38072,7 +38186,7 @@ function modelSectionSubject(value) {
|
|
|
38072
38186
|
|
|
38073
38187
|
// src/resources/section-subject/section.subject.repository.ts
|
|
38074
38188
|
var import_nodejs_utils49 = require("@eeplatform/nodejs-utils");
|
|
38075
|
-
var
|
|
38189
|
+
var import_mongodb30 = require("mongodb");
|
|
38076
38190
|
function useSectionSubjectRepo() {
|
|
38077
38191
|
const db = import_nodejs_utils49.useAtlas.getDb();
|
|
38078
38192
|
if (!db) {
|
|
@@ -38175,7 +38289,7 @@ function useSectionSubjectRepo() {
|
|
|
38175
38289
|
}
|
|
38176
38290
|
if (school) {
|
|
38177
38291
|
try {
|
|
38178
|
-
query.school = new
|
|
38292
|
+
query.school = new import_mongodb30.ObjectId(school);
|
|
38179
38293
|
} catch (error) {
|
|
38180
38294
|
throw new import_nodejs_utils49.BadRequestError("Invalid school ID.");
|
|
38181
38295
|
}
|
|
@@ -38183,7 +38297,7 @@ function useSectionSubjectRepo() {
|
|
|
38183
38297
|
}
|
|
38184
38298
|
if (section) {
|
|
38185
38299
|
try {
|
|
38186
|
-
query.section = new
|
|
38300
|
+
query.section = new import_mongodb30.ObjectId(section);
|
|
38187
38301
|
} catch (error) {
|
|
38188
38302
|
throw new import_nodejs_utils49.BadRequestError("Invalid section ID.");
|
|
38189
38303
|
}
|
|
@@ -38191,7 +38305,7 @@ function useSectionSubjectRepo() {
|
|
|
38191
38305
|
}
|
|
38192
38306
|
if (teacher) {
|
|
38193
38307
|
try {
|
|
38194
|
-
query.teacher = new
|
|
38308
|
+
query.teacher = new import_mongodb30.ObjectId(teacher);
|
|
38195
38309
|
} catch (error) {
|
|
38196
38310
|
throw new import_nodejs_utils49.BadRequestError("Invalid teacher ID.");
|
|
38197
38311
|
}
|
|
@@ -38255,7 +38369,7 @@ function useSectionSubjectRepo() {
|
|
|
38255
38369
|
}
|
|
38256
38370
|
async function getById(_id) {
|
|
38257
38371
|
try {
|
|
38258
|
-
_id = new
|
|
38372
|
+
_id = new import_mongodb30.ObjectId(_id);
|
|
38259
38373
|
} catch (error) {
|
|
38260
38374
|
throw new import_nodejs_utils49.BadRequestError("Invalid ID.");
|
|
38261
38375
|
}
|
|
@@ -38298,7 +38412,7 @@ function useSectionSubjectRepo() {
|
|
|
38298
38412
|
}
|
|
38299
38413
|
async function getBySection(section) {
|
|
38300
38414
|
try {
|
|
38301
|
-
section = new
|
|
38415
|
+
section = new import_mongodb30.ObjectId(section);
|
|
38302
38416
|
} catch (error) {
|
|
38303
38417
|
throw new import_nodejs_utils49.BadRequestError("Invalid section ID.");
|
|
38304
38418
|
}
|
|
@@ -38342,7 +38456,7 @@ function useSectionSubjectRepo() {
|
|
|
38342
38456
|
}
|
|
38343
38457
|
async function getByTeacher(teacher) {
|
|
38344
38458
|
try {
|
|
38345
|
-
teacher = new
|
|
38459
|
+
teacher = new import_mongodb30.ObjectId(teacher);
|
|
38346
38460
|
} catch (error) {
|
|
38347
38461
|
throw new import_nodejs_utils49.BadRequestError("Invalid teacher ID.");
|
|
38348
38462
|
}
|
|
@@ -38386,7 +38500,7 @@ function useSectionSubjectRepo() {
|
|
|
38386
38500
|
}
|
|
38387
38501
|
async function getBySchool(school) {
|
|
38388
38502
|
try {
|
|
38389
|
-
school = new
|
|
38503
|
+
school = new import_mongodb30.ObjectId(school);
|
|
38390
38504
|
} catch (error) {
|
|
38391
38505
|
throw new import_nodejs_utils49.BadRequestError("Invalid school ID.");
|
|
38392
38506
|
}
|
|
@@ -38442,19 +38556,19 @@ function useSectionSubjectRepo() {
|
|
|
38442
38556
|
);
|
|
38443
38557
|
}
|
|
38444
38558
|
try {
|
|
38445
|
-
_id = new
|
|
38559
|
+
_id = new import_mongodb30.ObjectId(_id);
|
|
38446
38560
|
} catch (error) {
|
|
38447
38561
|
throw new import_nodejs_utils49.BadRequestError("Invalid ID.");
|
|
38448
38562
|
}
|
|
38449
38563
|
if (field === "teacher" && value) {
|
|
38450
38564
|
try {
|
|
38451
|
-
value = new
|
|
38565
|
+
value = new import_mongodb30.ObjectId(value).toString();
|
|
38452
38566
|
} catch (error) {
|
|
38453
38567
|
throw new import_nodejs_utils49.BadRequestError("Invalid teacher ID.");
|
|
38454
38568
|
}
|
|
38455
38569
|
}
|
|
38456
38570
|
try {
|
|
38457
|
-
const updateValue = field === "teacher" ? new
|
|
38571
|
+
const updateValue = field === "teacher" ? new import_mongodb30.ObjectId(value) : value;
|
|
38458
38572
|
await collection.updateOne(
|
|
38459
38573
|
{ _id, deletedAt: { $in: ["", null] } },
|
|
38460
38574
|
{ $set: { [field]: updateValue, updatedAt: (/* @__PURE__ */ new Date()).toISOString() } },
|
|
@@ -38476,7 +38590,7 @@ function useSectionSubjectRepo() {
|
|
|
38476
38590
|
);
|
|
38477
38591
|
}
|
|
38478
38592
|
try {
|
|
38479
|
-
_id = new
|
|
38593
|
+
_id = new import_mongodb30.ObjectId(_id);
|
|
38480
38594
|
} catch (error2) {
|
|
38481
38595
|
throw new import_nodejs_utils49.BadRequestError("Invalid ID.");
|
|
38482
38596
|
}
|
|
@@ -38494,7 +38608,7 @@ function useSectionSubjectRepo() {
|
|
|
38494
38608
|
}
|
|
38495
38609
|
async function deleteById(_id) {
|
|
38496
38610
|
try {
|
|
38497
|
-
_id = new
|
|
38611
|
+
_id = new import_mongodb30.ObjectId(_id);
|
|
38498
38612
|
} catch (error) {
|
|
38499
38613
|
throw new import_nodejs_utils49.BadRequestError("Invalid ID.");
|
|
38500
38614
|
}
|
|
@@ -38559,7 +38673,7 @@ function useSectionSubjectService() {
|
|
|
38559
38673
|
|
|
38560
38674
|
// src/resources/section-subject/section.subject.controller.ts
|
|
38561
38675
|
var import_nodejs_utils51 = require("@eeplatform/nodejs-utils");
|
|
38562
|
-
var
|
|
38676
|
+
var import_joi31 = __toESM(require("joi"));
|
|
38563
38677
|
function useSectionSubjectController() {
|
|
38564
38678
|
const {
|
|
38565
38679
|
getAll: _getAll,
|
|
@@ -38592,17 +38706,17 @@ function useSectionSubjectController() {
|
|
|
38592
38706
|
}
|
|
38593
38707
|
async function getAll(req, res, next) {
|
|
38594
38708
|
const query = req.query;
|
|
38595
|
-
const validation =
|
|
38596
|
-
page:
|
|
38597
|
-
limit:
|
|
38598
|
-
search:
|
|
38599
|
-
status:
|
|
38600
|
-
school:
|
|
38601
|
-
section:
|
|
38602
|
-
teacher:
|
|
38603
|
-
schoolYear:
|
|
38604
|
-
gradeLevel:
|
|
38605
|
-
subjectCode:
|
|
38709
|
+
const validation = import_joi31.default.object({
|
|
38710
|
+
page: import_joi31.default.number().min(1).optional().allow("", null),
|
|
38711
|
+
limit: import_joi31.default.number().min(1).optional().allow("", null),
|
|
38712
|
+
search: import_joi31.default.string().optional().allow("", null),
|
|
38713
|
+
status: import_joi31.default.string().optional().allow("", null),
|
|
38714
|
+
school: import_joi31.default.string().hex().optional().allow("", null),
|
|
38715
|
+
section: import_joi31.default.string().hex().optional().allow("", null),
|
|
38716
|
+
teacher: import_joi31.default.string().hex().optional().allow("", null),
|
|
38717
|
+
schoolYear: import_joi31.default.string().optional().allow("", null),
|
|
38718
|
+
gradeLevel: import_joi31.default.string().optional().allow("", null),
|
|
38719
|
+
subjectCode: import_joi31.default.string().optional().allow("", null)
|
|
38606
38720
|
});
|
|
38607
38721
|
const { error } = validation.validate(query);
|
|
38608
38722
|
const page = typeof req.query.page === "string" ? Number(req.query.page) : 1;
|
|
@@ -38650,8 +38764,8 @@ function useSectionSubjectController() {
|
|
|
38650
38764
|
}
|
|
38651
38765
|
async function getById(req, res, next) {
|
|
38652
38766
|
const id = req.params.id;
|
|
38653
|
-
const validation =
|
|
38654
|
-
id:
|
|
38767
|
+
const validation = import_joi31.default.object({
|
|
38768
|
+
id: import_joi31.default.string().hex().required()
|
|
38655
38769
|
});
|
|
38656
38770
|
const { error } = validation.validate({ id });
|
|
38657
38771
|
if (error) {
|
|
@@ -38671,8 +38785,8 @@ function useSectionSubjectController() {
|
|
|
38671
38785
|
}
|
|
38672
38786
|
async function getBySection(req, res, next) {
|
|
38673
38787
|
const section = req.params.section;
|
|
38674
|
-
const validation =
|
|
38675
|
-
section:
|
|
38788
|
+
const validation = import_joi31.default.object({
|
|
38789
|
+
section: import_joi31.default.string().hex().required()
|
|
38676
38790
|
});
|
|
38677
38791
|
const { error } = validation.validate({ section });
|
|
38678
38792
|
if (error) {
|
|
@@ -38692,8 +38806,8 @@ function useSectionSubjectController() {
|
|
|
38692
38806
|
}
|
|
38693
38807
|
async function getByTeacher(req, res, next) {
|
|
38694
38808
|
const teacher = req.params.teacher;
|
|
38695
|
-
const validation =
|
|
38696
|
-
teacher:
|
|
38809
|
+
const validation = import_joi31.default.object({
|
|
38810
|
+
teacher: import_joi31.default.string().hex().required()
|
|
38697
38811
|
});
|
|
38698
38812
|
const { error } = validation.validate({ teacher });
|
|
38699
38813
|
if (error) {
|
|
@@ -38713,8 +38827,8 @@ function useSectionSubjectController() {
|
|
|
38713
38827
|
}
|
|
38714
38828
|
async function getBySchool(req, res, next) {
|
|
38715
38829
|
const school = req.params.school;
|
|
38716
|
-
const validation =
|
|
38717
|
-
school:
|
|
38830
|
+
const validation = import_joi31.default.object({
|
|
38831
|
+
school: import_joi31.default.string().hex().required()
|
|
38718
38832
|
});
|
|
38719
38833
|
const { error } = validation.validate({ school });
|
|
38720
38834
|
if (error) {
|
|
@@ -38735,9 +38849,9 @@ function useSectionSubjectController() {
|
|
|
38735
38849
|
async function updateField(req, res, next) {
|
|
38736
38850
|
const _id = req.params.id;
|
|
38737
38851
|
const { field, value } = req.body;
|
|
38738
|
-
const validation =
|
|
38739
|
-
_id:
|
|
38740
|
-
field:
|
|
38852
|
+
const validation = import_joi31.default.object({
|
|
38853
|
+
_id: import_joi31.default.string().hex().required(),
|
|
38854
|
+
field: import_joi31.default.string().valid(
|
|
38741
38855
|
"subjectCode",
|
|
38742
38856
|
"subjectName",
|
|
38743
38857
|
"teacher",
|
|
@@ -38745,7 +38859,7 @@ function useSectionSubjectController() {
|
|
|
38745
38859
|
"classroom",
|
|
38746
38860
|
"schedule"
|
|
38747
38861
|
).required(),
|
|
38748
|
-
value:
|
|
38862
|
+
value: import_joi31.default.string().required()
|
|
38749
38863
|
});
|
|
38750
38864
|
const { error } = validation.validate({ _id, field, value });
|
|
38751
38865
|
if (error) {
|
|
@@ -38778,8 +38892,8 @@ function useSectionSubjectController() {
|
|
|
38778
38892
|
}
|
|
38779
38893
|
async function deleteById(req, res, next) {
|
|
38780
38894
|
const _id = req.params.id;
|
|
38781
|
-
const validation =
|
|
38782
|
-
_id:
|
|
38895
|
+
const validation = import_joi31.default.object({
|
|
38896
|
+
_id: import_joi31.default.string().hex().required()
|
|
38783
38897
|
});
|
|
38784
38898
|
const { error } = validation.validate({ _id });
|
|
38785
38899
|
if (error) {
|
|
@@ -38815,6 +38929,7 @@ function useSectionService() {
|
|
|
38815
38929
|
const { add: assignStudent } = useSectionStudentRepo();
|
|
38816
38930
|
const { getAll: getAllCurriculumSubjects } = useCurriculumSubjectRepo();
|
|
38817
38931
|
const { add: addSectionSubject } = useSectionSubjectRepo();
|
|
38932
|
+
const { getById: getSchoolById } = useSchoolRepo();
|
|
38818
38933
|
function distributeStudents(total, minPer, maxPer) {
|
|
38819
38934
|
if (total <= 0)
|
|
38820
38935
|
return [];
|
|
@@ -38898,6 +39013,10 @@ function useSectionService() {
|
|
|
38898
39013
|
if (sectionSizes.length === 0) {
|
|
38899
39014
|
throw new import_nodejs_utils52.BadRequestError("Unable to compute section sizes.");
|
|
38900
39015
|
}
|
|
39016
|
+
const schoolData = await getSchoolById(value.school);
|
|
39017
|
+
if (!schoolData) {
|
|
39018
|
+
throw new import_nodejs_utils52.BadRequestError("School not found.");
|
|
39019
|
+
}
|
|
38901
39020
|
let totalStudentsProcessed = 0;
|
|
38902
39021
|
for (let i = 0; i < sectionSizes.length; i++) {
|
|
38903
39022
|
const size = sectionSizes[i];
|
|
@@ -38930,11 +39049,20 @@ function useSectionService() {
|
|
|
38930
39049
|
if (!student._id) {
|
|
38931
39050
|
throw new import_nodejs_utils52.BadRequestError("Learner ID is missing.");
|
|
38932
39051
|
}
|
|
39052
|
+
if (!student.learnerInfo.lrn) {
|
|
39053
|
+
throw new import_nodejs_utils52.BadRequestError("Learner LRN is missing.");
|
|
39054
|
+
}
|
|
38933
39055
|
await assignStudent(
|
|
38934
39056
|
{
|
|
38935
39057
|
section: section.toString(),
|
|
39058
|
+
lrn: student.learnerInfo.lrn,
|
|
38936
39059
|
student: student._id?.toString(),
|
|
38937
39060
|
studentName: `${student.learnerInfo.firstName} ${student.learnerInfo.lastName}`,
|
|
39061
|
+
school: value.school,
|
|
39062
|
+
schoolName: schoolData.name,
|
|
39063
|
+
gradeLevel: value.gradeLevel,
|
|
39064
|
+
educationLevel: gradeLevelData.educationLevel,
|
|
39065
|
+
schoolYear: value.schoolYear,
|
|
38938
39066
|
status: "active"
|
|
38939
39067
|
},
|
|
38940
39068
|
session
|
|
@@ -38949,7 +39077,7 @@ function useSectionService() {
|
|
|
38949
39077
|
await addSectionSubject(
|
|
38950
39078
|
{
|
|
38951
39079
|
school: value.school,
|
|
38952
|
-
schoolName:
|
|
39080
|
+
schoolName: schoolData.name,
|
|
38953
39081
|
gradeLevel: value.gradeLevel,
|
|
38954
39082
|
educationLevel: gradeLevelData.educationLevel,
|
|
38955
39083
|
schoolYear: value.schoolYear,
|
|
@@ -39039,14 +39167,14 @@ function useSectionController() {
|
|
|
39039
39167
|
}
|
|
39040
39168
|
async function getAll(req, res, next) {
|
|
39041
39169
|
const query = req.query;
|
|
39042
|
-
const validation =
|
|
39043
|
-
page:
|
|
39044
|
-
limit:
|
|
39045
|
-
search:
|
|
39046
|
-
status:
|
|
39047
|
-
school:
|
|
39048
|
-
schoolYear:
|
|
39049
|
-
gradeLevel:
|
|
39170
|
+
const validation = import_joi32.default.object({
|
|
39171
|
+
page: import_joi32.default.number().min(1).optional().allow("", null),
|
|
39172
|
+
limit: import_joi32.default.number().min(1).optional().allow("", null),
|
|
39173
|
+
search: import_joi32.default.string().optional().allow("", null),
|
|
39174
|
+
status: import_joi32.default.string().optional().allow("", null),
|
|
39175
|
+
school: import_joi32.default.string().hex().optional().allow("", null),
|
|
39176
|
+
schoolYear: import_joi32.default.string().optional().allow("", null),
|
|
39177
|
+
gradeLevel: import_joi32.default.string().optional().allow("", null)
|
|
39050
39178
|
});
|
|
39051
39179
|
const { error } = validation.validate(query);
|
|
39052
39180
|
const page = typeof req.query.page === "string" ? Number(req.query.page) : 1;
|
|
@@ -39088,8 +39216,8 @@ function useSectionController() {
|
|
|
39088
39216
|
}
|
|
39089
39217
|
async function getById(req, res, next) {
|
|
39090
39218
|
const id = req.params.id;
|
|
39091
|
-
const validation =
|
|
39092
|
-
id:
|
|
39219
|
+
const validation = import_joi32.default.object({
|
|
39220
|
+
id: import_joi32.default.string().hex().required()
|
|
39093
39221
|
});
|
|
39094
39222
|
const { error } = validation.validate({ id });
|
|
39095
39223
|
if (error) {
|
|
@@ -39106,8 +39234,8 @@ function useSectionController() {
|
|
|
39106
39234
|
}
|
|
39107
39235
|
async function getByName(req, res, next) {
|
|
39108
39236
|
const name = req.params.name;
|
|
39109
|
-
const validation =
|
|
39110
|
-
name:
|
|
39237
|
+
const validation = import_joi32.default.object({
|
|
39238
|
+
name: import_joi32.default.string().required()
|
|
39111
39239
|
});
|
|
39112
39240
|
const { error } = validation.validate({ name });
|
|
39113
39241
|
if (error) {
|
|
@@ -39127,8 +39255,8 @@ function useSectionController() {
|
|
|
39127
39255
|
}
|
|
39128
39256
|
async function getBySchool(req, res, next) {
|
|
39129
39257
|
const school = req.params.school;
|
|
39130
|
-
const validation =
|
|
39131
|
-
school:
|
|
39258
|
+
const validation = import_joi32.default.object({
|
|
39259
|
+
school: import_joi32.default.string().hex().required()
|
|
39132
39260
|
});
|
|
39133
39261
|
const { error } = validation.validate({ school });
|
|
39134
39262
|
if (error) {
|
|
@@ -39149,10 +39277,10 @@ function useSectionController() {
|
|
|
39149
39277
|
async function updateField(req, res, next) {
|
|
39150
39278
|
const _id = req.params.id;
|
|
39151
39279
|
const { field, value } = req.body;
|
|
39152
|
-
const validation =
|
|
39153
|
-
_id:
|
|
39154
|
-
field:
|
|
39155
|
-
value:
|
|
39280
|
+
const validation = import_joi32.default.object({
|
|
39281
|
+
_id: import_joi32.default.string().hex().required(),
|
|
39282
|
+
field: import_joi32.default.string().valid("name", "schoolYear", "gradeLevel", "adviser", "adviserName").required(),
|
|
39283
|
+
value: import_joi32.default.string().required()
|
|
39156
39284
|
});
|
|
39157
39285
|
const { error } = validation.validate({ _id, field, value });
|
|
39158
39286
|
if (error) {
|
|
@@ -39170,9 +39298,9 @@ function useSectionController() {
|
|
|
39170
39298
|
async function addStudent(req, res, next) {
|
|
39171
39299
|
const _id = req.params.id;
|
|
39172
39300
|
const { studentId } = req.body;
|
|
39173
|
-
const validation =
|
|
39174
|
-
_id:
|
|
39175
|
-
studentId:
|
|
39301
|
+
const validation = import_joi32.default.object({
|
|
39302
|
+
_id: import_joi32.default.string().hex().required(),
|
|
39303
|
+
studentId: import_joi32.default.string().required()
|
|
39176
39304
|
});
|
|
39177
39305
|
const { error } = validation.validate({ _id, studentId });
|
|
39178
39306
|
if (error) {
|
|
@@ -39190,9 +39318,9 @@ function useSectionController() {
|
|
|
39190
39318
|
async function removeStudent(req, res, next) {
|
|
39191
39319
|
const _id = req.params.id;
|
|
39192
39320
|
const { studentId } = req.body;
|
|
39193
|
-
const validation =
|
|
39194
|
-
_id:
|
|
39195
|
-
studentId:
|
|
39321
|
+
const validation = import_joi32.default.object({
|
|
39322
|
+
_id: import_joi32.default.string().hex().required(),
|
|
39323
|
+
studentId: import_joi32.default.string().required()
|
|
39196
39324
|
});
|
|
39197
39325
|
const { error } = validation.validate({ _id, studentId });
|
|
39198
39326
|
if (error) {
|
|
@@ -39209,8 +39337,8 @@ function useSectionController() {
|
|
|
39209
39337
|
}
|
|
39210
39338
|
async function deleteById(req, res, next) {
|
|
39211
39339
|
const _id = req.params.id;
|
|
39212
|
-
const validation =
|
|
39213
|
-
_id:
|
|
39340
|
+
const validation = import_joi32.default.object({
|
|
39341
|
+
_id: import_joi32.default.string().hex().required()
|
|
39214
39342
|
});
|
|
39215
39343
|
const { error } = validation.validate({ _id });
|
|
39216
39344
|
if (error) {
|
|
@@ -39239,65 +39367,146 @@ function useSectionController() {
|
|
|
39239
39367
|
};
|
|
39240
39368
|
}
|
|
39241
39369
|
|
|
39242
|
-
// src/resources/
|
|
39370
|
+
// src/resources/section-student/section.student.controller.ts
|
|
39243
39371
|
var import_nodejs_utils54 = require("@eeplatform/nodejs-utils");
|
|
39244
|
-
var
|
|
39245
|
-
|
|
39246
|
-
|
|
39247
|
-
|
|
39248
|
-
|
|
39249
|
-
|
|
39250
|
-
|
|
39251
|
-
|
|
39252
|
-
|
|
39253
|
-
|
|
39254
|
-
|
|
39255
|
-
|
|
39372
|
+
var import_joi33 = __toESM(require("joi"));
|
|
39373
|
+
function useSectionStudentController() {
|
|
39374
|
+
const { add: _add, getAll: _getAll } = useSectionStudentRepo();
|
|
39375
|
+
async function add(req, res, next) {
|
|
39376
|
+
const value = req.body;
|
|
39377
|
+
const { error } = schemaSectionStudent.validate(value);
|
|
39378
|
+
if (error) {
|
|
39379
|
+
next(new import_nodejs_utils54.BadRequestError(error.message));
|
|
39380
|
+
return;
|
|
39381
|
+
}
|
|
39382
|
+
try {
|
|
39383
|
+
const data = await _add(value);
|
|
39384
|
+
res.json({
|
|
39385
|
+
message: "Successfully created section student.",
|
|
39386
|
+
data
|
|
39387
|
+
});
|
|
39388
|
+
return;
|
|
39389
|
+
} catch (error2) {
|
|
39390
|
+
next(error2);
|
|
39391
|
+
}
|
|
39392
|
+
}
|
|
39393
|
+
async function getAll(req, res, next) {
|
|
39394
|
+
const query = req.query;
|
|
39395
|
+
const validation = import_joi33.default.object({
|
|
39396
|
+
page: import_joi33.default.number().min(1).optional().allow("", null),
|
|
39397
|
+
limit: import_joi33.default.number().min(1).optional().allow("", null),
|
|
39398
|
+
search: import_joi33.default.string().optional().allow("", null),
|
|
39399
|
+
status: import_joi33.default.string().optional().allow("", null),
|
|
39400
|
+
school: import_joi33.default.string().optional().allow("", null),
|
|
39401
|
+
gradeLevel: import_joi33.default.string().optional().allow("", null),
|
|
39402
|
+
section: import_joi33.default.string().optional().allow("", null),
|
|
39403
|
+
schoolYear: import_joi33.default.string().optional().allow("", null)
|
|
39404
|
+
});
|
|
39405
|
+
const { error } = validation.validate(query);
|
|
39406
|
+
const page = typeof req.query.page === "string" ? Number(req.query.page) : 1;
|
|
39407
|
+
const limit = typeof req.query.limit === "string" ? Number(req.query.limit) : 10;
|
|
39408
|
+
const search = req.query.search ?? "";
|
|
39409
|
+
const status = req.query.status ?? "active";
|
|
39410
|
+
const school = req.query.school ?? "";
|
|
39411
|
+
const gradeLevel = req.query.gradeLevel ?? "";
|
|
39412
|
+
const section = req.query.section ?? "";
|
|
39413
|
+
const schoolYear = req.query.schoolYear ?? "";
|
|
39414
|
+
const isPageNumber = isFinite(page);
|
|
39415
|
+
if (!isPageNumber) {
|
|
39416
|
+
next(new import_nodejs_utils54.BadRequestError("Invalid page number."));
|
|
39417
|
+
return;
|
|
39418
|
+
}
|
|
39419
|
+
const isLimitNumber = isFinite(limit);
|
|
39420
|
+
if (!isLimitNumber) {
|
|
39421
|
+
next(new import_nodejs_utils54.BadRequestError("Invalid limit number."));
|
|
39422
|
+
return;
|
|
39423
|
+
}
|
|
39424
|
+
if (error) {
|
|
39425
|
+
next(new import_nodejs_utils54.BadRequestError(error.message));
|
|
39426
|
+
return;
|
|
39427
|
+
}
|
|
39428
|
+
try {
|
|
39429
|
+
const data = await _getAll({
|
|
39430
|
+
page,
|
|
39431
|
+
limit,
|
|
39432
|
+
search,
|
|
39433
|
+
status,
|
|
39434
|
+
school,
|
|
39435
|
+
gradeLevel,
|
|
39436
|
+
section,
|
|
39437
|
+
schoolYear
|
|
39438
|
+
});
|
|
39439
|
+
res.json(data);
|
|
39440
|
+
return;
|
|
39441
|
+
} catch (error2) {
|
|
39442
|
+
next(error2);
|
|
39443
|
+
}
|
|
39444
|
+
}
|
|
39445
|
+
return {
|
|
39446
|
+
add,
|
|
39447
|
+
getAll
|
|
39448
|
+
};
|
|
39449
|
+
}
|
|
39450
|
+
|
|
39451
|
+
// src/resources/building/building.model.ts
|
|
39452
|
+
var import_nodejs_utils55 = require("@eeplatform/nodejs-utils");
|
|
39453
|
+
var import_joi34 = __toESM(require("joi"));
|
|
39454
|
+
var import_mongodb31 = require("mongodb");
|
|
39455
|
+
var schemaBuilding = import_joi34.default.object({
|
|
39456
|
+
_id: import_joi34.default.string().hex().optional(),
|
|
39457
|
+
school: import_joi34.default.string().hex().required(),
|
|
39458
|
+
serial: import_joi34.default.string().optional().allow("", null),
|
|
39459
|
+
name: import_joi34.default.string().required(),
|
|
39460
|
+
levels: import_joi34.default.number().integer().min(1).required(),
|
|
39461
|
+
createdAt: import_joi34.default.date().optional().allow("", null),
|
|
39462
|
+
updatedAt: import_joi34.default.date().optional().allow("", null),
|
|
39463
|
+
deletedAt: import_joi34.default.date().optional().allow("", null),
|
|
39464
|
+
status: import_joi34.default.string().optional().allow("", null)
|
|
39256
39465
|
});
|
|
39257
|
-
var schemaBuildingUnit =
|
|
39258
|
-
_id:
|
|
39259
|
-
school:
|
|
39260
|
-
name:
|
|
39261
|
-
building:
|
|
39262
|
-
buildingName:
|
|
39263
|
-
level:
|
|
39264
|
-
category:
|
|
39265
|
-
type:
|
|
39266
|
-
seating_capacity:
|
|
39267
|
-
standing_capacity:
|
|
39268
|
-
description:
|
|
39269
|
-
unit_of_measurement:
|
|
39270
|
-
area:
|
|
39271
|
-
status:
|
|
39466
|
+
var schemaBuildingUnit = import_joi34.default.object({
|
|
39467
|
+
_id: import_joi34.default.string().hex().optional(),
|
|
39468
|
+
school: import_joi34.default.string().hex().required(),
|
|
39469
|
+
name: import_joi34.default.string().optional().allow("", null),
|
|
39470
|
+
building: import_joi34.default.string().hex().required(),
|
|
39471
|
+
buildingName: import_joi34.default.string().optional().allow("", null),
|
|
39472
|
+
level: import_joi34.default.number().integer().min(1).required(),
|
|
39473
|
+
category: import_joi34.default.string().required(),
|
|
39474
|
+
type: import_joi34.default.string().required(),
|
|
39475
|
+
seating_capacity: import_joi34.default.number().integer().min(0).required(),
|
|
39476
|
+
standing_capacity: import_joi34.default.number().integer().min(0).required(),
|
|
39477
|
+
description: import_joi34.default.string().optional().allow("", null),
|
|
39478
|
+
unit_of_measurement: import_joi34.default.string().valid("sqm").required(),
|
|
39479
|
+
area: import_joi34.default.number().positive().required(),
|
|
39480
|
+
status: import_joi34.default.string().optional().allow("", null)
|
|
39272
39481
|
});
|
|
39273
|
-
var schemaUpdateOptions =
|
|
39274
|
-
name:
|
|
39275
|
-
building:
|
|
39276
|
-
buildingName:
|
|
39277
|
-
level:
|
|
39278
|
-
category:
|
|
39279
|
-
type:
|
|
39280
|
-
seating_capacity:
|
|
39281
|
-
standing_capacity:
|
|
39282
|
-
area:
|
|
39482
|
+
var schemaUpdateOptions = import_joi34.default.object({
|
|
39483
|
+
name: import_joi34.default.string().optional().allow("", null),
|
|
39484
|
+
building: import_joi34.default.string().hex().optional().allow("", null),
|
|
39485
|
+
buildingName: import_joi34.default.string().optional().allow("", null),
|
|
39486
|
+
level: import_joi34.default.number().integer().min(1).optional().allow("", null),
|
|
39487
|
+
category: import_joi34.default.string().optional().allow("", null),
|
|
39488
|
+
type: import_joi34.default.string().optional().allow("", null),
|
|
39489
|
+
seating_capacity: import_joi34.default.number().integer().min(0).optional().allow("", null),
|
|
39490
|
+
standing_capacity: import_joi34.default.number().integer().min(0).optional().allow("", null),
|
|
39491
|
+
area: import_joi34.default.number().positive().optional().allow("", null)
|
|
39283
39492
|
});
|
|
39284
39493
|
function MBuilding(value) {
|
|
39285
39494
|
const { error } = schemaBuilding.validate(value);
|
|
39286
39495
|
if (error) {
|
|
39287
|
-
|
|
39288
|
-
throw new
|
|
39496
|
+
import_nodejs_utils55.logger.info(`Building Model: ${error.message}`);
|
|
39497
|
+
throw new import_nodejs_utils55.BadRequestError(error.message);
|
|
39289
39498
|
}
|
|
39290
39499
|
if (value._id && typeof value._id === "string") {
|
|
39291
39500
|
try {
|
|
39292
|
-
value._id = new
|
|
39501
|
+
value._id = new import_mongodb31.ObjectId(value._id);
|
|
39293
39502
|
} catch (error2) {
|
|
39294
|
-
throw new
|
|
39503
|
+
throw new import_nodejs_utils55.BadRequestError("Invalid _id format");
|
|
39295
39504
|
}
|
|
39296
39505
|
}
|
|
39297
39506
|
try {
|
|
39298
|
-
value.school = new
|
|
39507
|
+
value.school = new import_mongodb31.ObjectId(value.school);
|
|
39299
39508
|
} catch (error2) {
|
|
39300
|
-
throw new
|
|
39509
|
+
throw new import_nodejs_utils55.BadRequestError("Invalid school format");
|
|
39301
39510
|
}
|
|
39302
39511
|
return {
|
|
39303
39512
|
_id: value._id ?? void 0,
|
|
@@ -39314,25 +39523,25 @@ function MBuilding(value) {
|
|
|
39314
39523
|
function MBuildingUnit(value) {
|
|
39315
39524
|
const { error } = schemaBuildingUnit.validate(value);
|
|
39316
39525
|
if (error) {
|
|
39317
|
-
|
|
39318
|
-
throw new
|
|
39526
|
+
import_nodejs_utils55.logger.info(`Building Unit Model: ${error.message}`);
|
|
39527
|
+
throw new import_nodejs_utils55.BadRequestError(error.message);
|
|
39319
39528
|
}
|
|
39320
39529
|
if (value._id && typeof value._id === "string") {
|
|
39321
39530
|
try {
|
|
39322
|
-
value._id = new
|
|
39531
|
+
value._id = new import_mongodb31.ObjectId(value._id);
|
|
39323
39532
|
} catch (error2) {
|
|
39324
|
-
throw new
|
|
39533
|
+
throw new import_nodejs_utils55.BadRequestError("Invalid ID");
|
|
39325
39534
|
}
|
|
39326
39535
|
}
|
|
39327
39536
|
try {
|
|
39328
|
-
value.school = new
|
|
39537
|
+
value.school = new import_mongodb31.ObjectId(value.school);
|
|
39329
39538
|
} catch (error2) {
|
|
39330
|
-
throw new
|
|
39539
|
+
throw new import_nodejs_utils55.BadRequestError("Invalid school ID");
|
|
39331
39540
|
}
|
|
39332
39541
|
try {
|
|
39333
|
-
value.building = new
|
|
39542
|
+
value.building = new import_mongodb31.ObjectId(value.building);
|
|
39334
39543
|
} catch (error2) {
|
|
39335
|
-
throw new
|
|
39544
|
+
throw new import_nodejs_utils55.BadRequestError("Invalid building ID");
|
|
39336
39545
|
}
|
|
39337
39546
|
return {
|
|
39338
39547
|
_id: value._id ?? void 0,
|
|
@@ -39356,16 +39565,16 @@ function MBuildingUnit(value) {
|
|
|
39356
39565
|
}
|
|
39357
39566
|
|
|
39358
39567
|
// src/resources/building/building.repository.ts
|
|
39359
|
-
var
|
|
39360
|
-
var
|
|
39568
|
+
var import_nodejs_utils56 = require("@eeplatform/nodejs-utils");
|
|
39569
|
+
var import_mongodb32 = require("mongodb");
|
|
39361
39570
|
function useBuildingRepo() {
|
|
39362
|
-
const db =
|
|
39571
|
+
const db = import_nodejs_utils56.useAtlas.getDb();
|
|
39363
39572
|
if (!db) {
|
|
39364
39573
|
throw new Error("Unable to connect to server.");
|
|
39365
39574
|
}
|
|
39366
39575
|
const namespace_collection = "school.buildings";
|
|
39367
39576
|
const collection = db.collection(namespace_collection);
|
|
39368
|
-
const { getCache, setCache, delNamespace } = (0,
|
|
39577
|
+
const { getCache, setCache, delNamespace } = (0, import_nodejs_utils56.useCache)(namespace_collection);
|
|
39369
39578
|
async function createIndexes() {
|
|
39370
39579
|
try {
|
|
39371
39580
|
await collection.createIndexes([
|
|
@@ -39384,16 +39593,16 @@ function useBuildingRepo() {
|
|
|
39384
39593
|
delCachedData();
|
|
39385
39594
|
return res.insertedId;
|
|
39386
39595
|
} catch (error) {
|
|
39387
|
-
|
|
39596
|
+
import_nodejs_utils56.logger.log({
|
|
39388
39597
|
level: "error",
|
|
39389
39598
|
message: error.message
|
|
39390
39599
|
});
|
|
39391
|
-
if (error instanceof
|
|
39600
|
+
if (error instanceof import_nodejs_utils56.AppError) {
|
|
39392
39601
|
throw error;
|
|
39393
39602
|
} else {
|
|
39394
39603
|
const isDuplicated = error.message.includes("duplicate");
|
|
39395
39604
|
if (isDuplicated) {
|
|
39396
|
-
throw new
|
|
39605
|
+
throw new import_nodejs_utils56.BadRequestError("Building already exists.");
|
|
39397
39606
|
}
|
|
39398
39607
|
throw new Error("Failed to create building.");
|
|
39399
39608
|
}
|
|
@@ -39401,9 +39610,9 @@ function useBuildingRepo() {
|
|
|
39401
39610
|
}
|
|
39402
39611
|
async function updateById(_id, value, session) {
|
|
39403
39612
|
try {
|
|
39404
|
-
_id = new
|
|
39613
|
+
_id = new import_mongodb32.ObjectId(_id);
|
|
39405
39614
|
} catch (error) {
|
|
39406
|
-
throw new
|
|
39615
|
+
throw new import_nodejs_utils56.BadRequestError("Invalid ID.");
|
|
39407
39616
|
}
|
|
39408
39617
|
try {
|
|
39409
39618
|
const res = await collection.updateOne(
|
|
@@ -39414,11 +39623,11 @@ function useBuildingRepo() {
|
|
|
39414
39623
|
delCachedData();
|
|
39415
39624
|
return res;
|
|
39416
39625
|
} catch (error) {
|
|
39417
|
-
|
|
39626
|
+
import_nodejs_utils56.logger.log({
|
|
39418
39627
|
level: "error",
|
|
39419
39628
|
message: error.message
|
|
39420
39629
|
});
|
|
39421
|
-
if (error instanceof
|
|
39630
|
+
if (error instanceof import_nodejs_utils56.AppError) {
|
|
39422
39631
|
throw error;
|
|
39423
39632
|
} else {
|
|
39424
39633
|
throw new Error("Failed to update building.");
|
|
@@ -39443,9 +39652,9 @@ function useBuildingRepo() {
|
|
|
39443
39652
|
}
|
|
39444
39653
|
if (school) {
|
|
39445
39654
|
try {
|
|
39446
|
-
query.school = new
|
|
39655
|
+
query.school = new import_mongodb32.ObjectId(school);
|
|
39447
39656
|
} catch (error) {
|
|
39448
|
-
throw new
|
|
39657
|
+
throw new import_nodejs_utils56.BadRequestError("Invalid school ID.");
|
|
39449
39658
|
}
|
|
39450
39659
|
}
|
|
39451
39660
|
const cacheParams = {
|
|
@@ -39459,15 +39668,15 @@ function useBuildingRepo() {
|
|
|
39459
39668
|
cacheParams.school = school;
|
|
39460
39669
|
if (status !== "active")
|
|
39461
39670
|
cacheParams.status = status;
|
|
39462
|
-
const cacheKey = (0,
|
|
39463
|
-
|
|
39671
|
+
const cacheKey = (0, import_nodejs_utils56.makeCacheKey)(namespace_collection, cacheParams);
|
|
39672
|
+
import_nodejs_utils56.logger.log({
|
|
39464
39673
|
level: "info",
|
|
39465
39674
|
message: `Cache key for getAll buildings: ${cacheKey}`
|
|
39466
39675
|
});
|
|
39467
39676
|
try {
|
|
39468
39677
|
const cached = await getCache(cacheKey);
|
|
39469
39678
|
if (cached) {
|
|
39470
|
-
|
|
39679
|
+
import_nodejs_utils56.logger.log({
|
|
39471
39680
|
level: "info",
|
|
39472
39681
|
message: `Cache hit for getAll buildings: ${cacheKey}`
|
|
39473
39682
|
});
|
|
@@ -39480,35 +39689,35 @@ function useBuildingRepo() {
|
|
|
39480
39689
|
{ $limit: limit }
|
|
39481
39690
|
]).toArray();
|
|
39482
39691
|
const length = await collection.countDocuments(query);
|
|
39483
|
-
const data = (0,
|
|
39692
|
+
const data = (0, import_nodejs_utils56.paginate)(items, page, limit, length);
|
|
39484
39693
|
setCache(cacheKey, data, 600).then(() => {
|
|
39485
|
-
|
|
39694
|
+
import_nodejs_utils56.logger.log({
|
|
39486
39695
|
level: "info",
|
|
39487
39696
|
message: `Cache set for getAll buildings: ${cacheKey}`
|
|
39488
39697
|
});
|
|
39489
39698
|
}).catch((err) => {
|
|
39490
|
-
|
|
39699
|
+
import_nodejs_utils56.logger.log({
|
|
39491
39700
|
level: "error",
|
|
39492
39701
|
message: `Failed to set cache for getAll buildings: ${err.message}`
|
|
39493
39702
|
});
|
|
39494
39703
|
});
|
|
39495
39704
|
return data;
|
|
39496
39705
|
} catch (error) {
|
|
39497
|
-
|
|
39706
|
+
import_nodejs_utils56.logger.log({ level: "error", message: `${error}` });
|
|
39498
39707
|
throw error;
|
|
39499
39708
|
}
|
|
39500
39709
|
}
|
|
39501
39710
|
async function getById(_id) {
|
|
39502
39711
|
try {
|
|
39503
|
-
_id = new
|
|
39712
|
+
_id = new import_mongodb32.ObjectId(_id);
|
|
39504
39713
|
} catch (error) {
|
|
39505
|
-
throw new
|
|
39714
|
+
throw new import_nodejs_utils56.BadRequestError("Invalid ID.");
|
|
39506
39715
|
}
|
|
39507
|
-
const cacheKey = (0,
|
|
39716
|
+
const cacheKey = (0, import_nodejs_utils56.makeCacheKey)(namespace_collection, { _id: String(_id) });
|
|
39508
39717
|
try {
|
|
39509
39718
|
const cached = await getCache(cacheKey);
|
|
39510
39719
|
if (cached) {
|
|
39511
|
-
|
|
39720
|
+
import_nodejs_utils56.logger.log({
|
|
39512
39721
|
level: "info",
|
|
39513
39722
|
message: `Cache hit for getById building: ${cacheKey}`
|
|
39514
39723
|
});
|
|
@@ -39518,30 +39727,30 @@ function useBuildingRepo() {
|
|
|
39518
39727
|
_id
|
|
39519
39728
|
});
|
|
39520
39729
|
setCache(cacheKey, result, 300).then(() => {
|
|
39521
|
-
|
|
39730
|
+
import_nodejs_utils56.logger.log({
|
|
39522
39731
|
level: "info",
|
|
39523
39732
|
message: `Cache set for building by id: ${cacheKey}`
|
|
39524
39733
|
});
|
|
39525
39734
|
}).catch((err) => {
|
|
39526
|
-
|
|
39735
|
+
import_nodejs_utils56.logger.log({
|
|
39527
39736
|
level: "error",
|
|
39528
39737
|
message: `Failed to set cache for building by id: ${err.message}`
|
|
39529
39738
|
});
|
|
39530
39739
|
});
|
|
39531
39740
|
return result;
|
|
39532
39741
|
} catch (error) {
|
|
39533
|
-
if (error instanceof
|
|
39742
|
+
if (error instanceof import_nodejs_utils56.AppError) {
|
|
39534
39743
|
throw error;
|
|
39535
39744
|
} else {
|
|
39536
|
-
throw new
|
|
39745
|
+
throw new import_nodejs_utils56.InternalServerError("Failed to get building.");
|
|
39537
39746
|
}
|
|
39538
39747
|
}
|
|
39539
39748
|
}
|
|
39540
39749
|
async function deleteById(_id, session) {
|
|
39541
39750
|
try {
|
|
39542
|
-
_id = new
|
|
39751
|
+
_id = new import_mongodb32.ObjectId(_id);
|
|
39543
39752
|
} catch (error) {
|
|
39544
|
-
throw new
|
|
39753
|
+
throw new import_nodejs_utils56.BadRequestError("Invalid ID.");
|
|
39545
39754
|
}
|
|
39546
39755
|
try {
|
|
39547
39756
|
const res = await collection.updateOne(
|
|
@@ -39551,25 +39760,25 @@ function useBuildingRepo() {
|
|
|
39551
39760
|
delCachedData();
|
|
39552
39761
|
return res;
|
|
39553
39762
|
} catch (error) {
|
|
39554
|
-
|
|
39763
|
+
import_nodejs_utils56.logger.log({
|
|
39555
39764
|
level: "error",
|
|
39556
39765
|
message: error.message
|
|
39557
39766
|
});
|
|
39558
|
-
if (error instanceof
|
|
39767
|
+
if (error instanceof import_nodejs_utils56.AppError) {
|
|
39559
39768
|
throw error;
|
|
39560
39769
|
} else {
|
|
39561
|
-
throw new
|
|
39770
|
+
throw new import_nodejs_utils56.InternalServerError("Failed to delete building.");
|
|
39562
39771
|
}
|
|
39563
39772
|
}
|
|
39564
39773
|
}
|
|
39565
39774
|
function delCachedData() {
|
|
39566
39775
|
delNamespace().then(() => {
|
|
39567
|
-
|
|
39776
|
+
import_nodejs_utils56.logger.log({
|
|
39568
39777
|
level: "info",
|
|
39569
39778
|
message: `Cache namespace cleared for ${namespace_collection}`
|
|
39570
39779
|
});
|
|
39571
39780
|
}).catch((err) => {
|
|
39572
|
-
|
|
39781
|
+
import_nodejs_utils56.logger.log({
|
|
39573
39782
|
level: "error",
|
|
39574
39783
|
message: `Failed to clear cache namespace for ${namespace_collection}: ${err.message}`
|
|
39575
39784
|
});
|
|
@@ -39586,19 +39795,19 @@ function useBuildingRepo() {
|
|
|
39586
39795
|
}
|
|
39587
39796
|
|
|
39588
39797
|
// src/resources/building/building.service.ts
|
|
39589
|
-
var
|
|
39798
|
+
var import_nodejs_utils58 = require("@eeplatform/nodejs-utils");
|
|
39590
39799
|
|
|
39591
39800
|
// src/resources/building/building-unit.repository.ts
|
|
39592
|
-
var
|
|
39593
|
-
var
|
|
39801
|
+
var import_nodejs_utils57 = require("@eeplatform/nodejs-utils");
|
|
39802
|
+
var import_mongodb33 = require("mongodb");
|
|
39594
39803
|
function useBuildingUnitRepo() {
|
|
39595
|
-
const db =
|
|
39804
|
+
const db = import_nodejs_utils57.useAtlas.getDb();
|
|
39596
39805
|
if (!db) {
|
|
39597
39806
|
throw new Error("Unable to connect to server.");
|
|
39598
39807
|
}
|
|
39599
39808
|
const namespace_collection = "school.building-units";
|
|
39600
39809
|
const collection = db.collection(namespace_collection);
|
|
39601
|
-
const { getCache, setCache, delNamespace } = (0,
|
|
39810
|
+
const { getCache, setCache, delNamespace } = (0, import_nodejs_utils57.useCache)(namespace_collection);
|
|
39602
39811
|
async function createIndexes() {
|
|
39603
39812
|
try {
|
|
39604
39813
|
await collection.createIndexes([
|
|
@@ -39626,12 +39835,12 @@ function useBuildingUnitRepo() {
|
|
|
39626
39835
|
}
|
|
39627
39836
|
function delCachedData() {
|
|
39628
39837
|
delNamespace().then(() => {
|
|
39629
|
-
|
|
39838
|
+
import_nodejs_utils57.logger.log({
|
|
39630
39839
|
level: "info",
|
|
39631
39840
|
message: `Cache namespace cleared for ${namespace_collection}`
|
|
39632
39841
|
});
|
|
39633
39842
|
}).catch((err) => {
|
|
39634
|
-
|
|
39843
|
+
import_nodejs_utils57.logger.log({
|
|
39635
39844
|
level: "error",
|
|
39636
39845
|
message: `Failed to clear cache namespace for ${namespace_collection}: ${err.message}`
|
|
39637
39846
|
});
|
|
@@ -39644,11 +39853,11 @@ function useBuildingUnitRepo() {
|
|
|
39644
39853
|
delCachedData();
|
|
39645
39854
|
return res.insertedId;
|
|
39646
39855
|
} catch (error) {
|
|
39647
|
-
|
|
39856
|
+
import_nodejs_utils57.logger.log({
|
|
39648
39857
|
level: "error",
|
|
39649
39858
|
message: error.message
|
|
39650
39859
|
});
|
|
39651
|
-
if (error instanceof
|
|
39860
|
+
if (error instanceof import_nodejs_utils57.AppError) {
|
|
39652
39861
|
throw error;
|
|
39653
39862
|
} else {
|
|
39654
39863
|
throw new Error("Failed to create building unit.");
|
|
@@ -39658,12 +39867,12 @@ function useBuildingUnitRepo() {
|
|
|
39658
39867
|
async function updateById(_id, value, session) {
|
|
39659
39868
|
const { error } = schemaUpdateOptions.validate(value);
|
|
39660
39869
|
if (error) {
|
|
39661
|
-
throw new
|
|
39870
|
+
throw new import_nodejs_utils57.BadRequestError(error.message);
|
|
39662
39871
|
}
|
|
39663
39872
|
try {
|
|
39664
|
-
_id = new
|
|
39873
|
+
_id = new import_mongodb33.ObjectId(_id);
|
|
39665
39874
|
} catch (error2) {
|
|
39666
|
-
throw new
|
|
39875
|
+
throw new import_nodejs_utils57.BadRequestError("Invalid ID.");
|
|
39667
39876
|
}
|
|
39668
39877
|
try {
|
|
39669
39878
|
const res = await collection.updateOne(
|
|
@@ -39674,11 +39883,11 @@ function useBuildingUnitRepo() {
|
|
|
39674
39883
|
delCachedData();
|
|
39675
39884
|
return res;
|
|
39676
39885
|
} catch (error2) {
|
|
39677
|
-
|
|
39886
|
+
import_nodejs_utils57.logger.log({
|
|
39678
39887
|
level: "error",
|
|
39679
39888
|
message: error2.message
|
|
39680
39889
|
});
|
|
39681
|
-
if (error2 instanceof
|
|
39890
|
+
if (error2 instanceof import_nodejs_utils57.AppError) {
|
|
39682
39891
|
throw error2;
|
|
39683
39892
|
} else {
|
|
39684
39893
|
throw new Error("Failed to create building unit.");
|
|
@@ -39688,12 +39897,12 @@ function useBuildingUnitRepo() {
|
|
|
39688
39897
|
async function updateByBuildingId(building, value, session) {
|
|
39689
39898
|
const { error } = schemaUpdateOptions.validate(value);
|
|
39690
39899
|
if (error) {
|
|
39691
|
-
throw new
|
|
39900
|
+
throw new import_nodejs_utils57.BadRequestError(error.message);
|
|
39692
39901
|
}
|
|
39693
39902
|
try {
|
|
39694
|
-
building = new
|
|
39903
|
+
building = new import_mongodb33.ObjectId(building);
|
|
39695
39904
|
} catch (error2) {
|
|
39696
|
-
throw new
|
|
39905
|
+
throw new import_nodejs_utils57.BadRequestError("Invalid building ID.");
|
|
39697
39906
|
}
|
|
39698
39907
|
try {
|
|
39699
39908
|
const res = await collection.updateMany(
|
|
@@ -39704,11 +39913,11 @@ function useBuildingUnitRepo() {
|
|
|
39704
39913
|
delCachedData();
|
|
39705
39914
|
return res;
|
|
39706
39915
|
} catch (error2) {
|
|
39707
|
-
|
|
39916
|
+
import_nodejs_utils57.logger.log({
|
|
39708
39917
|
level: "error",
|
|
39709
39918
|
message: error2.message
|
|
39710
39919
|
});
|
|
39711
|
-
if (error2 instanceof
|
|
39920
|
+
if (error2 instanceof import_nodejs_utils57.AppError) {
|
|
39712
39921
|
throw error2;
|
|
39713
39922
|
} else {
|
|
39714
39923
|
throw new Error("Failed to update building unit.");
|
|
@@ -39735,16 +39944,16 @@ function useBuildingUnitRepo() {
|
|
|
39735
39944
|
}
|
|
39736
39945
|
if (school) {
|
|
39737
39946
|
try {
|
|
39738
|
-
query.school = new
|
|
39947
|
+
query.school = new import_mongodb33.ObjectId(school);
|
|
39739
39948
|
} catch (error) {
|
|
39740
|
-
throw new
|
|
39949
|
+
throw new import_nodejs_utils57.BadRequestError("Invalid school ID.");
|
|
39741
39950
|
}
|
|
39742
39951
|
}
|
|
39743
39952
|
if (building) {
|
|
39744
39953
|
try {
|
|
39745
|
-
query.building = new
|
|
39954
|
+
query.building = new import_mongodb33.ObjectId(building);
|
|
39746
39955
|
} catch (error) {
|
|
39747
|
-
throw new
|
|
39956
|
+
throw new import_nodejs_utils57.BadRequestError("Invalid building ID.");
|
|
39748
39957
|
}
|
|
39749
39958
|
}
|
|
39750
39959
|
const cacheParams = {
|
|
@@ -39760,15 +39969,15 @@ function useBuildingUnitRepo() {
|
|
|
39760
39969
|
cacheParams.building = building;
|
|
39761
39970
|
if (status !== "active")
|
|
39762
39971
|
cacheParams.status = status;
|
|
39763
|
-
const cacheKey = (0,
|
|
39764
|
-
|
|
39972
|
+
const cacheKey = (0, import_nodejs_utils57.makeCacheKey)(namespace_collection, cacheParams);
|
|
39973
|
+
import_nodejs_utils57.logger.log({
|
|
39765
39974
|
level: "info",
|
|
39766
39975
|
message: `Cache key for getAll building units: ${cacheKey}`
|
|
39767
39976
|
});
|
|
39768
39977
|
try {
|
|
39769
39978
|
const cached = await getCache(cacheKey);
|
|
39770
39979
|
if (cached) {
|
|
39771
|
-
|
|
39980
|
+
import_nodejs_utils57.logger.log({
|
|
39772
39981
|
level: "info",
|
|
39773
39982
|
message: `Cache hit for getAll building units: ${cacheKey}`
|
|
39774
39983
|
});
|
|
@@ -39781,35 +39990,35 @@ function useBuildingUnitRepo() {
|
|
|
39781
39990
|
{ $limit: limit }
|
|
39782
39991
|
]).toArray();
|
|
39783
39992
|
const length = await collection.countDocuments(query);
|
|
39784
|
-
const data = (0,
|
|
39993
|
+
const data = (0, import_nodejs_utils57.paginate)(items, page, limit, length);
|
|
39785
39994
|
setCache(cacheKey, data, 600).then(() => {
|
|
39786
|
-
|
|
39995
|
+
import_nodejs_utils57.logger.log({
|
|
39787
39996
|
level: "info",
|
|
39788
39997
|
message: `Cache set for getAll building units: ${cacheKey}`
|
|
39789
39998
|
});
|
|
39790
39999
|
}).catch((err) => {
|
|
39791
|
-
|
|
40000
|
+
import_nodejs_utils57.logger.log({
|
|
39792
40001
|
level: "error",
|
|
39793
40002
|
message: `Failed to set cache for getAll building units: ${err.message}`
|
|
39794
40003
|
});
|
|
39795
40004
|
});
|
|
39796
40005
|
return data;
|
|
39797
40006
|
} catch (error) {
|
|
39798
|
-
|
|
40007
|
+
import_nodejs_utils57.logger.log({ level: "error", message: `${error}` });
|
|
39799
40008
|
throw error;
|
|
39800
40009
|
}
|
|
39801
40010
|
}
|
|
39802
40011
|
async function getById(_id) {
|
|
39803
40012
|
try {
|
|
39804
|
-
_id = new
|
|
40013
|
+
_id = new import_mongodb33.ObjectId(_id);
|
|
39805
40014
|
} catch (error) {
|
|
39806
|
-
throw new
|
|
40015
|
+
throw new import_nodejs_utils57.BadRequestError("Invalid ID.");
|
|
39807
40016
|
}
|
|
39808
|
-
const cacheKey = (0,
|
|
40017
|
+
const cacheKey = (0, import_nodejs_utils57.makeCacheKey)(namespace_collection, { _id: String(_id) });
|
|
39809
40018
|
try {
|
|
39810
40019
|
const cached = await getCache(cacheKey);
|
|
39811
40020
|
if (cached) {
|
|
39812
|
-
|
|
40021
|
+
import_nodejs_utils57.logger.log({
|
|
39813
40022
|
level: "info",
|
|
39814
40023
|
message: `Cache hit for getById building unit: ${cacheKey}`
|
|
39815
40024
|
});
|
|
@@ -39820,42 +40029,42 @@ function useBuildingUnitRepo() {
|
|
|
39820
40029
|
deletedAt: { $in: ["", null] }
|
|
39821
40030
|
});
|
|
39822
40031
|
if (!result) {
|
|
39823
|
-
throw new
|
|
40032
|
+
throw new import_nodejs_utils57.BadRequestError("Building unit not found.");
|
|
39824
40033
|
}
|
|
39825
40034
|
setCache(cacheKey, result, 300).then(() => {
|
|
39826
|
-
|
|
40035
|
+
import_nodejs_utils57.logger.log({
|
|
39827
40036
|
level: "info",
|
|
39828
40037
|
message: `Cache set for building unit by id: ${cacheKey}`
|
|
39829
40038
|
});
|
|
39830
40039
|
}).catch((err) => {
|
|
39831
|
-
|
|
40040
|
+
import_nodejs_utils57.logger.log({
|
|
39832
40041
|
level: "error",
|
|
39833
40042
|
message: `Failed to set cache for building unit by id: ${err.message}`
|
|
39834
40043
|
});
|
|
39835
40044
|
});
|
|
39836
40045
|
return result;
|
|
39837
40046
|
} catch (error) {
|
|
39838
|
-
if (error instanceof
|
|
40047
|
+
if (error instanceof import_nodejs_utils57.AppError) {
|
|
39839
40048
|
throw error;
|
|
39840
40049
|
} else {
|
|
39841
|
-
throw new
|
|
40050
|
+
throw new import_nodejs_utils57.InternalServerError("Failed to get building unit.");
|
|
39842
40051
|
}
|
|
39843
40052
|
}
|
|
39844
40053
|
}
|
|
39845
40054
|
async function getByBuildingLevel(building, level) {
|
|
39846
40055
|
try {
|
|
39847
|
-
building = new
|
|
40056
|
+
building = new import_mongodb33.ObjectId(building);
|
|
39848
40057
|
} catch (error) {
|
|
39849
|
-
throw new
|
|
40058
|
+
throw new import_nodejs_utils57.BadRequestError("Invalid building ID.");
|
|
39850
40059
|
}
|
|
39851
|
-
const cacheKey = (0,
|
|
40060
|
+
const cacheKey = (0, import_nodejs_utils57.makeCacheKey)(namespace_collection, {
|
|
39852
40061
|
building: String(building),
|
|
39853
40062
|
level
|
|
39854
40063
|
});
|
|
39855
40064
|
try {
|
|
39856
40065
|
const cached = await getCache(cacheKey);
|
|
39857
40066
|
if (cached) {
|
|
39858
|
-
|
|
40067
|
+
import_nodejs_utils57.logger.log({
|
|
39859
40068
|
level: "info",
|
|
39860
40069
|
message: `Cache hit for getById building unit: ${cacheKey}`
|
|
39861
40070
|
});
|
|
@@ -39867,38 +40076,38 @@ function useBuildingUnitRepo() {
|
|
|
39867
40076
|
status: "active"
|
|
39868
40077
|
});
|
|
39869
40078
|
setCache(cacheKey, result, 300).then(() => {
|
|
39870
|
-
|
|
40079
|
+
import_nodejs_utils57.logger.log({
|
|
39871
40080
|
level: "info",
|
|
39872
40081
|
message: `Cache set for building unit by id: ${cacheKey}`
|
|
39873
40082
|
});
|
|
39874
40083
|
}).catch((err) => {
|
|
39875
|
-
|
|
40084
|
+
import_nodejs_utils57.logger.log({
|
|
39876
40085
|
level: "error",
|
|
39877
40086
|
message: `Failed to set cache for building unit by id: ${err.message}`
|
|
39878
40087
|
});
|
|
39879
40088
|
});
|
|
39880
40089
|
return result;
|
|
39881
40090
|
} catch (error) {
|
|
39882
|
-
if (error instanceof
|
|
40091
|
+
if (error instanceof import_nodejs_utils57.AppError) {
|
|
39883
40092
|
throw error;
|
|
39884
40093
|
} else {
|
|
39885
|
-
throw new
|
|
40094
|
+
throw new import_nodejs_utils57.InternalServerError("Failed to get building unit.");
|
|
39886
40095
|
}
|
|
39887
40096
|
}
|
|
39888
40097
|
}
|
|
39889
40098
|
async function getByBuilding(building) {
|
|
39890
40099
|
try {
|
|
39891
|
-
building = new
|
|
40100
|
+
building = new import_mongodb33.ObjectId(building);
|
|
39892
40101
|
} catch (error) {
|
|
39893
|
-
throw new
|
|
40102
|
+
throw new import_nodejs_utils57.BadRequestError("Invalid building ID.");
|
|
39894
40103
|
}
|
|
39895
|
-
const cacheKey = (0,
|
|
40104
|
+
const cacheKey = (0, import_nodejs_utils57.makeCacheKey)(namespace_collection, {
|
|
39896
40105
|
building: String(building)
|
|
39897
40106
|
});
|
|
39898
40107
|
try {
|
|
39899
40108
|
const cached = await getCache(cacheKey);
|
|
39900
40109
|
if (cached) {
|
|
39901
|
-
|
|
40110
|
+
import_nodejs_utils57.logger.log({
|
|
39902
40111
|
level: "info",
|
|
39903
40112
|
message: `Cache hit for getById building unit: ${cacheKey}`
|
|
39904
40113
|
});
|
|
@@ -39909,30 +40118,30 @@ function useBuildingUnitRepo() {
|
|
|
39909
40118
|
status: "active"
|
|
39910
40119
|
});
|
|
39911
40120
|
setCache(cacheKey, result, 300).then(() => {
|
|
39912
|
-
|
|
40121
|
+
import_nodejs_utils57.logger.log({
|
|
39913
40122
|
level: "info",
|
|
39914
40123
|
message: `Cache set for building unit by id: ${cacheKey}`
|
|
39915
40124
|
});
|
|
39916
40125
|
}).catch((err) => {
|
|
39917
|
-
|
|
40126
|
+
import_nodejs_utils57.logger.log({
|
|
39918
40127
|
level: "error",
|
|
39919
40128
|
message: `Failed to set cache for building unit by id: ${err.message}`
|
|
39920
40129
|
});
|
|
39921
40130
|
});
|
|
39922
40131
|
return result;
|
|
39923
40132
|
} catch (error) {
|
|
39924
|
-
if (error instanceof
|
|
40133
|
+
if (error instanceof import_nodejs_utils57.AppError) {
|
|
39925
40134
|
throw error;
|
|
39926
40135
|
} else {
|
|
39927
|
-
throw new
|
|
40136
|
+
throw new import_nodejs_utils57.InternalServerError("Failed to get building unit.");
|
|
39928
40137
|
}
|
|
39929
40138
|
}
|
|
39930
40139
|
}
|
|
39931
40140
|
async function deleteById(_id, session) {
|
|
39932
40141
|
try {
|
|
39933
|
-
_id = new
|
|
40142
|
+
_id = new import_mongodb33.ObjectId(_id);
|
|
39934
40143
|
} catch (error) {
|
|
39935
|
-
throw new
|
|
40144
|
+
throw new import_nodejs_utils57.BadRequestError("Invalid ID.");
|
|
39936
40145
|
}
|
|
39937
40146
|
try {
|
|
39938
40147
|
const res = await collection.updateOne(
|
|
@@ -39943,11 +40152,11 @@ function useBuildingUnitRepo() {
|
|
|
39943
40152
|
delCachedData();
|
|
39944
40153
|
return "Room/Facility deleted successfully.";
|
|
39945
40154
|
} catch (error) {
|
|
39946
|
-
|
|
40155
|
+
import_nodejs_utils57.logger.log({
|
|
39947
40156
|
level: "error",
|
|
39948
40157
|
message: error.message
|
|
39949
40158
|
});
|
|
39950
|
-
if (error instanceof
|
|
40159
|
+
if (error instanceof import_nodejs_utils57.AppError) {
|
|
39951
40160
|
throw error;
|
|
39952
40161
|
} else {
|
|
39953
40162
|
throw new Error("Failed to deleted room/facility.");
|
|
@@ -39977,16 +40186,16 @@ function useBuildingService() {
|
|
|
39977
40186
|
const { getByBuildingLevel, getByBuilding, updateByBuildingId } = useBuildingUnitRepo();
|
|
39978
40187
|
async function updateById(id, data) {
|
|
39979
40188
|
data.levels = Number(data.levels);
|
|
39980
|
-
const session =
|
|
40189
|
+
const session = import_nodejs_utils58.useAtlas.getClient()?.startSession();
|
|
39981
40190
|
try {
|
|
39982
40191
|
const building = await _getById(id);
|
|
39983
40192
|
if (!building) {
|
|
39984
|
-
throw new
|
|
40193
|
+
throw new import_nodejs_utils58.NotFoundError("Building not found.");
|
|
39985
40194
|
}
|
|
39986
40195
|
if (data.levels < building.levels) {
|
|
39987
40196
|
const unit = await getByBuildingLevel(id, building.levels);
|
|
39988
40197
|
if (unit) {
|
|
39989
|
-
throw new
|
|
40198
|
+
throw new import_nodejs_utils58.BadRequestError(
|
|
39990
40199
|
"Cannot reduce floors, there are existing building units at higher floors."
|
|
39991
40200
|
);
|
|
39992
40201
|
}
|
|
@@ -40008,7 +40217,7 @@ function useBuildingService() {
|
|
|
40008
40217
|
async function deleteById(id) {
|
|
40009
40218
|
const building = await getByBuilding(id);
|
|
40010
40219
|
if (building) {
|
|
40011
|
-
throw new
|
|
40220
|
+
throw new import_nodejs_utils58.BadRequestError(
|
|
40012
40221
|
"Cannot delete building with existing room/facility. Please delete room/facility first."
|
|
40013
40222
|
);
|
|
40014
40223
|
}
|
|
@@ -40026,24 +40235,24 @@ function useBuildingService() {
|
|
|
40026
40235
|
}
|
|
40027
40236
|
|
|
40028
40237
|
// src/resources/building/building.controller.ts
|
|
40029
|
-
var
|
|
40030
|
-
var
|
|
40238
|
+
var import_nodejs_utils59 = require("@eeplatform/nodejs-utils");
|
|
40239
|
+
var import_joi35 = __toESM(require("joi"));
|
|
40031
40240
|
function useBuildingController() {
|
|
40032
40241
|
const { getAll: _getAll, getById: _getById, add: _add } = useBuildingRepo();
|
|
40033
40242
|
const { updateById: _updateById, deleteById: _deleteById } = useBuildingService();
|
|
40034
40243
|
async function createBuilding(req, res, next) {
|
|
40035
40244
|
const value = req.body;
|
|
40036
|
-
const validation =
|
|
40037
|
-
name:
|
|
40038
|
-
school:
|
|
40039
|
-
levels:
|
|
40040
|
-
serial:
|
|
40041
|
-
status:
|
|
40245
|
+
const validation = import_joi35.default.object({
|
|
40246
|
+
name: import_joi35.default.string().required(),
|
|
40247
|
+
school: import_joi35.default.string().hex().required(),
|
|
40248
|
+
levels: import_joi35.default.number().integer().min(1).required(),
|
|
40249
|
+
serial: import_joi35.default.string().optional().allow("", null),
|
|
40250
|
+
status: import_joi35.default.string().optional().allow("", null)
|
|
40042
40251
|
});
|
|
40043
40252
|
const { error } = validation.validate(value);
|
|
40044
40253
|
if (error) {
|
|
40045
|
-
next(new
|
|
40046
|
-
|
|
40254
|
+
next(new import_nodejs_utils59.BadRequestError(error.message));
|
|
40255
|
+
import_nodejs_utils59.logger.info(`Controller: ${error.message}`);
|
|
40047
40256
|
return;
|
|
40048
40257
|
}
|
|
40049
40258
|
try {
|
|
@@ -40057,18 +40266,18 @@ function useBuildingController() {
|
|
|
40057
40266
|
async function updateById(req, res, next) {
|
|
40058
40267
|
const value = req.body;
|
|
40059
40268
|
const id = req.params.id ?? "";
|
|
40060
|
-
const validation =
|
|
40061
|
-
id:
|
|
40062
|
-
value:
|
|
40063
|
-
name:
|
|
40064
|
-
serial:
|
|
40065
|
-
levels:
|
|
40269
|
+
const validation = import_joi35.default.object({
|
|
40270
|
+
id: import_joi35.default.string().hex().required(),
|
|
40271
|
+
value: import_joi35.default.object({
|
|
40272
|
+
name: import_joi35.default.string().required(),
|
|
40273
|
+
serial: import_joi35.default.string().optional().allow("", null),
|
|
40274
|
+
levels: import_joi35.default.number().integer().min(1).required()
|
|
40066
40275
|
})
|
|
40067
40276
|
});
|
|
40068
40277
|
const { error } = validation.validate({ id, value });
|
|
40069
40278
|
if (error) {
|
|
40070
|
-
next(new
|
|
40071
|
-
|
|
40279
|
+
next(new import_nodejs_utils59.BadRequestError(error.message));
|
|
40280
|
+
import_nodejs_utils59.logger.info(`Controller: ${error.message}`);
|
|
40072
40281
|
return;
|
|
40073
40282
|
}
|
|
40074
40283
|
try {
|
|
@@ -40081,16 +40290,16 @@ function useBuildingController() {
|
|
|
40081
40290
|
}
|
|
40082
40291
|
async function getAll(req, res, next) {
|
|
40083
40292
|
const query = req.query;
|
|
40084
|
-
const validation =
|
|
40085
|
-
page:
|
|
40086
|
-
limit:
|
|
40087
|
-
search:
|
|
40088
|
-
school:
|
|
40089
|
-
status:
|
|
40293
|
+
const validation = import_joi35.default.object({
|
|
40294
|
+
page: import_joi35.default.number().min(1).optional().allow("", null),
|
|
40295
|
+
limit: import_joi35.default.number().min(1).optional().allow("", null),
|
|
40296
|
+
search: import_joi35.default.string().optional().allow("", null),
|
|
40297
|
+
school: import_joi35.default.string().hex().optional().allow("", null),
|
|
40298
|
+
status: import_joi35.default.string().optional().allow("", null)
|
|
40090
40299
|
});
|
|
40091
40300
|
const { error } = validation.validate(query);
|
|
40092
40301
|
if (error) {
|
|
40093
|
-
next(new
|
|
40302
|
+
next(new import_nodejs_utils59.BadRequestError(error.message));
|
|
40094
40303
|
return;
|
|
40095
40304
|
}
|
|
40096
40305
|
const page = parseInt(req.query.page) ?? 1;
|
|
@@ -40124,12 +40333,12 @@ function useBuildingController() {
|
|
|
40124
40333
|
}
|
|
40125
40334
|
async function getById(req, res, next) {
|
|
40126
40335
|
const id = req.params.id;
|
|
40127
|
-
const validation =
|
|
40128
|
-
id:
|
|
40336
|
+
const validation = import_joi35.default.object({
|
|
40337
|
+
id: import_joi35.default.string().hex().required()
|
|
40129
40338
|
});
|
|
40130
40339
|
const { error } = validation.validate({ id });
|
|
40131
40340
|
if (error) {
|
|
40132
|
-
next(new
|
|
40341
|
+
next(new import_nodejs_utils59.BadRequestError(error.message));
|
|
40133
40342
|
return;
|
|
40134
40343
|
}
|
|
40135
40344
|
try {
|
|
@@ -40145,12 +40354,12 @@ function useBuildingController() {
|
|
|
40145
40354
|
}
|
|
40146
40355
|
async function deleteById(req, res, next) {
|
|
40147
40356
|
const id = req.params.id;
|
|
40148
|
-
const validation =
|
|
40149
|
-
id:
|
|
40357
|
+
const validation = import_joi35.default.object({
|
|
40358
|
+
id: import_joi35.default.string().hex().required()
|
|
40150
40359
|
});
|
|
40151
40360
|
const { error } = validation.validate({ id });
|
|
40152
40361
|
if (error) {
|
|
40153
|
-
next(new
|
|
40362
|
+
next(new import_nodejs_utils59.BadRequestError(error.message));
|
|
40154
40363
|
return;
|
|
40155
40364
|
}
|
|
40156
40365
|
try {
|
|
@@ -40171,11 +40380,11 @@ function useBuildingController() {
|
|
|
40171
40380
|
}
|
|
40172
40381
|
|
|
40173
40382
|
// src/resources/building/building-unit.service.ts
|
|
40174
|
-
var
|
|
40383
|
+
var import_nodejs_utils60 = require("@eeplatform/nodejs-utils");
|
|
40175
40384
|
function useBuildingUnitService() {
|
|
40176
40385
|
const { add: _add } = useBuildingUnitRepo();
|
|
40177
40386
|
async function add(value) {
|
|
40178
|
-
const session =
|
|
40387
|
+
const session = import_nodejs_utils60.useAtlas.getClient()?.startSession();
|
|
40179
40388
|
if (!session) {
|
|
40180
40389
|
throw new Error("Unable to start session for building unit service.");
|
|
40181
40390
|
}
|
|
@@ -40202,8 +40411,8 @@ function useBuildingUnitService() {
|
|
|
40202
40411
|
}
|
|
40203
40412
|
|
|
40204
40413
|
// src/resources/building/building-unit.controller.ts
|
|
40205
|
-
var
|
|
40206
|
-
var
|
|
40414
|
+
var import_nodejs_utils61 = require("@eeplatform/nodejs-utils");
|
|
40415
|
+
var import_joi36 = __toESM(require("joi"));
|
|
40207
40416
|
function useBuildingUnitController() {
|
|
40208
40417
|
const {
|
|
40209
40418
|
getAll: _getAll,
|
|
@@ -40214,27 +40423,27 @@ function useBuildingUnitController() {
|
|
|
40214
40423
|
const { add: _add } = useBuildingUnitService();
|
|
40215
40424
|
async function add(req, res, next) {
|
|
40216
40425
|
const data = req.body;
|
|
40217
|
-
const validation =
|
|
40218
|
-
building:
|
|
40219
|
-
school:
|
|
40220
|
-
name:
|
|
40221
|
-
building:
|
|
40222
|
-
buildingName:
|
|
40223
|
-
level:
|
|
40224
|
-
category:
|
|
40225
|
-
type:
|
|
40226
|
-
seating_capacity:
|
|
40227
|
-
standing_capacity:
|
|
40228
|
-
description:
|
|
40229
|
-
unit_of_measurement:
|
|
40230
|
-
area:
|
|
40231
|
-
status:
|
|
40426
|
+
const validation = import_joi36.default.object({
|
|
40427
|
+
building: import_joi36.default.object({
|
|
40428
|
+
school: import_joi36.default.string().hex().required(),
|
|
40429
|
+
name: import_joi36.default.string().optional().allow("", null),
|
|
40430
|
+
building: import_joi36.default.string().hex().required(),
|
|
40431
|
+
buildingName: import_joi36.default.string().optional().allow("", null),
|
|
40432
|
+
level: import_joi36.default.number().integer().min(1).required(),
|
|
40433
|
+
category: import_joi36.default.string().required(),
|
|
40434
|
+
type: import_joi36.default.string().required(),
|
|
40435
|
+
seating_capacity: import_joi36.default.number().integer().min(0).required(),
|
|
40436
|
+
standing_capacity: import_joi36.default.number().integer().min(0).required(),
|
|
40437
|
+
description: import_joi36.default.string().optional().allow("", null),
|
|
40438
|
+
unit_of_measurement: import_joi36.default.string().valid("sqm").required(),
|
|
40439
|
+
area: import_joi36.default.number().positive().required(),
|
|
40440
|
+
status: import_joi36.default.string().optional().allow("", null)
|
|
40232
40441
|
}),
|
|
40233
|
-
qty:
|
|
40442
|
+
qty: import_joi36.default.number().integer().min(1).max(20).optional().default(1)
|
|
40234
40443
|
});
|
|
40235
40444
|
const { error } = validation.validate(data);
|
|
40236
40445
|
if (error) {
|
|
40237
|
-
next(new
|
|
40446
|
+
next(new import_nodejs_utils61.BadRequestError(error.message));
|
|
40238
40447
|
return;
|
|
40239
40448
|
}
|
|
40240
40449
|
try {
|
|
@@ -40250,13 +40459,13 @@ function useBuildingUnitController() {
|
|
|
40250
40459
|
async function updateById(req, res, next) {
|
|
40251
40460
|
const data = req.body;
|
|
40252
40461
|
const id = req.params.id ?? "";
|
|
40253
|
-
const validation =
|
|
40254
|
-
id:
|
|
40462
|
+
const validation = import_joi36.default.object({
|
|
40463
|
+
id: import_joi36.default.string().hex().required(),
|
|
40255
40464
|
value: schemaUpdateOptions
|
|
40256
40465
|
});
|
|
40257
40466
|
const { error } = validation.validate({ id, value: data });
|
|
40258
40467
|
if (error) {
|
|
40259
|
-
next(new
|
|
40468
|
+
next(new import_nodejs_utils61.BadRequestError(error.message));
|
|
40260
40469
|
return;
|
|
40261
40470
|
}
|
|
40262
40471
|
try {
|
|
@@ -40271,17 +40480,17 @@ function useBuildingUnitController() {
|
|
|
40271
40480
|
}
|
|
40272
40481
|
async function getAll(req, res, next) {
|
|
40273
40482
|
const query = req.query;
|
|
40274
|
-
const validation =
|
|
40275
|
-
page:
|
|
40276
|
-
limit:
|
|
40277
|
-
search:
|
|
40278
|
-
school:
|
|
40279
|
-
building:
|
|
40280
|
-
status:
|
|
40483
|
+
const validation = import_joi36.default.object({
|
|
40484
|
+
page: import_joi36.default.number().min(1).optional().allow("", null),
|
|
40485
|
+
limit: import_joi36.default.number().min(1).optional().allow("", null),
|
|
40486
|
+
search: import_joi36.default.string().optional().allow("", null),
|
|
40487
|
+
school: import_joi36.default.string().hex().optional().allow("", null),
|
|
40488
|
+
building: import_joi36.default.string().hex().optional().allow("", null),
|
|
40489
|
+
status: import_joi36.default.string().optional().allow("", null)
|
|
40281
40490
|
});
|
|
40282
40491
|
const { error } = validation.validate(query);
|
|
40283
40492
|
if (error) {
|
|
40284
|
-
next(new
|
|
40493
|
+
next(new import_nodejs_utils61.BadRequestError(error.message));
|
|
40285
40494
|
return;
|
|
40286
40495
|
}
|
|
40287
40496
|
const page = parseInt(req.query.page) ?? 1;
|
|
@@ -40317,12 +40526,12 @@ function useBuildingUnitController() {
|
|
|
40317
40526
|
}
|
|
40318
40527
|
async function getById(req, res, next) {
|
|
40319
40528
|
const id = req.params.id;
|
|
40320
|
-
const validation =
|
|
40321
|
-
id:
|
|
40529
|
+
const validation = import_joi36.default.object({
|
|
40530
|
+
id: import_joi36.default.string().hex().required()
|
|
40322
40531
|
});
|
|
40323
40532
|
const { error } = validation.validate({ id });
|
|
40324
40533
|
if (error) {
|
|
40325
|
-
next(new
|
|
40534
|
+
next(new import_nodejs_utils61.BadRequestError(error.message));
|
|
40326
40535
|
return;
|
|
40327
40536
|
}
|
|
40328
40537
|
try {
|
|
@@ -40338,12 +40547,12 @@ function useBuildingUnitController() {
|
|
|
40338
40547
|
}
|
|
40339
40548
|
async function deleteById(req, res, next) {
|
|
40340
40549
|
const id = req.params.id;
|
|
40341
|
-
const validation =
|
|
40342
|
-
id:
|
|
40550
|
+
const validation = import_joi36.default.object({
|
|
40551
|
+
id: import_joi36.default.string().hex().required()
|
|
40343
40552
|
});
|
|
40344
40553
|
const { error } = validation.validate({ id });
|
|
40345
40554
|
if (error) {
|
|
40346
|
-
next(new
|
|
40555
|
+
next(new import_nodejs_utils61.BadRequestError(error.message));
|
|
40347
40556
|
return;
|
|
40348
40557
|
}
|
|
40349
40558
|
try {
|
|
@@ -40364,42 +40573,42 @@ function useBuildingUnitController() {
|
|
|
40364
40573
|
}
|
|
40365
40574
|
|
|
40366
40575
|
// src/resources/personnel/personnel.model.ts
|
|
40367
|
-
var
|
|
40368
|
-
var
|
|
40369
|
-
var
|
|
40370
|
-
var schemaPersonnel =
|
|
40371
|
-
_id:
|
|
40372
|
-
school:
|
|
40373
|
-
schoolName:
|
|
40374
|
-
firstName:
|
|
40375
|
-
lastName:
|
|
40376
|
-
middleName:
|
|
40377
|
-
suffix:
|
|
40378
|
-
title:
|
|
40379
|
-
classification:
|
|
40380
|
-
status:
|
|
40381
|
-
createdAt:
|
|
40382
|
-
updatedAt:
|
|
40383
|
-
deletedAt:
|
|
40576
|
+
var import_nodejs_utils62 = require("@eeplatform/nodejs-utils");
|
|
40577
|
+
var import_joi37 = __toESM(require("joi"));
|
|
40578
|
+
var import_mongodb34 = require("mongodb");
|
|
40579
|
+
var schemaPersonnel = import_joi37.default.object({
|
|
40580
|
+
_id: import_joi37.default.string().hex().optional().allow("", null),
|
|
40581
|
+
school: import_joi37.default.string().hex().required(),
|
|
40582
|
+
schoolName: import_joi37.default.string().optional().allow("", null),
|
|
40583
|
+
firstName: import_joi37.default.string().required(),
|
|
40584
|
+
lastName: import_joi37.default.string().required(),
|
|
40585
|
+
middleName: import_joi37.default.string().optional().allow("", null),
|
|
40586
|
+
suffix: import_joi37.default.string().optional().allow("", null),
|
|
40587
|
+
title: import_joi37.default.string().optional().allow("", null),
|
|
40588
|
+
classification: import_joi37.default.string().required(),
|
|
40589
|
+
status: import_joi37.default.string().optional().allow("", null),
|
|
40590
|
+
createdAt: import_joi37.default.date().optional().allow("", null),
|
|
40591
|
+
updatedAt: import_joi37.default.date().optional().allow("", null),
|
|
40592
|
+
deletedAt: import_joi37.default.date().optional().allow("", null)
|
|
40384
40593
|
});
|
|
40385
40594
|
function MPersonnel(value) {
|
|
40386
40595
|
const { error } = schemaPersonnel.validate(value);
|
|
40387
40596
|
if (error) {
|
|
40388
|
-
|
|
40389
|
-
throw new
|
|
40597
|
+
import_nodejs_utils62.logger.info(`Personnel Model: ${error.message}`);
|
|
40598
|
+
throw new import_nodejs_utils62.BadRequestError(error.message);
|
|
40390
40599
|
}
|
|
40391
40600
|
if (value._id && typeof value._id === "string") {
|
|
40392
40601
|
try {
|
|
40393
|
-
value._id = new
|
|
40602
|
+
value._id = new import_mongodb34.ObjectId(value._id);
|
|
40394
40603
|
} catch (error2) {
|
|
40395
|
-
throw new
|
|
40604
|
+
throw new import_nodejs_utils62.BadRequestError("Invalid _id format");
|
|
40396
40605
|
}
|
|
40397
40606
|
}
|
|
40398
40607
|
if (value.school && typeof value.school === "string") {
|
|
40399
40608
|
try {
|
|
40400
|
-
value.school = new
|
|
40609
|
+
value.school = new import_mongodb34.ObjectId(value.school);
|
|
40401
40610
|
} catch (error2) {
|
|
40402
|
-
throw new
|
|
40611
|
+
throw new import_nodejs_utils62.BadRequestError("Invalid school format");
|
|
40403
40612
|
}
|
|
40404
40613
|
}
|
|
40405
40614
|
if (!value.status) {
|
|
@@ -40423,16 +40632,16 @@ function MPersonnel(value) {
|
|
|
40423
40632
|
}
|
|
40424
40633
|
|
|
40425
40634
|
// src/resources/personnel/personnel.repository.ts
|
|
40426
|
-
var
|
|
40427
|
-
var
|
|
40635
|
+
var import_nodejs_utils63 = require("@eeplatform/nodejs-utils");
|
|
40636
|
+
var import_mongodb35 = require("mongodb");
|
|
40428
40637
|
function usePersonnelRepo() {
|
|
40429
|
-
const db =
|
|
40638
|
+
const db = import_nodejs_utils63.useAtlas.getDb();
|
|
40430
40639
|
if (!db) {
|
|
40431
40640
|
throw new Error("Unable to connect to server.");
|
|
40432
40641
|
}
|
|
40433
40642
|
const namespace_collection = "deped.school.personnel";
|
|
40434
40643
|
const collection = db.collection(namespace_collection);
|
|
40435
|
-
const { getCache, setCache, delNamespace } = (0,
|
|
40644
|
+
const { getCache, setCache, delNamespace } = (0, import_nodejs_utils63.useCache)(namespace_collection);
|
|
40436
40645
|
async function createIndexes() {
|
|
40437
40646
|
try {
|
|
40438
40647
|
await collection.createIndexes([
|
|
@@ -40460,11 +40669,11 @@ function usePersonnelRepo() {
|
|
|
40460
40669
|
delCachedData();
|
|
40461
40670
|
return "Successfully added personnel.";
|
|
40462
40671
|
} catch (error) {
|
|
40463
|
-
|
|
40672
|
+
import_nodejs_utils63.logger.log({
|
|
40464
40673
|
level: "error",
|
|
40465
40674
|
message: error.message
|
|
40466
40675
|
});
|
|
40467
|
-
if (error instanceof
|
|
40676
|
+
if (error instanceof import_nodejs_utils63.AppError) {
|
|
40468
40677
|
throw error;
|
|
40469
40678
|
} else {
|
|
40470
40679
|
throw new Error("Failed to create personnel.");
|
|
@@ -40473,9 +40682,9 @@ function usePersonnelRepo() {
|
|
|
40473
40682
|
}
|
|
40474
40683
|
async function updateById(_id, value, session) {
|
|
40475
40684
|
try {
|
|
40476
|
-
_id = new
|
|
40685
|
+
_id = new import_mongodb35.ObjectId(_id);
|
|
40477
40686
|
} catch (error) {
|
|
40478
|
-
throw new
|
|
40687
|
+
throw new import_nodejs_utils63.BadRequestError("Invalid ID.");
|
|
40479
40688
|
}
|
|
40480
40689
|
try {
|
|
40481
40690
|
const res = await collection.updateOne(
|
|
@@ -40486,11 +40695,11 @@ function usePersonnelRepo() {
|
|
|
40486
40695
|
delCachedData();
|
|
40487
40696
|
return res;
|
|
40488
40697
|
} catch (error) {
|
|
40489
|
-
|
|
40698
|
+
import_nodejs_utils63.logger.log({
|
|
40490
40699
|
level: "error",
|
|
40491
40700
|
message: error.message
|
|
40492
40701
|
});
|
|
40493
|
-
if (error instanceof
|
|
40702
|
+
if (error instanceof import_nodejs_utils63.AppError) {
|
|
40494
40703
|
throw error;
|
|
40495
40704
|
} else {
|
|
40496
40705
|
throw new Error("Failed to update personnel.");
|
|
@@ -40521,21 +40730,21 @@ function usePersonnelRepo() {
|
|
|
40521
40730
|
}
|
|
40522
40731
|
if (school) {
|
|
40523
40732
|
try {
|
|
40524
|
-
query.school = new
|
|
40733
|
+
query.school = new import_mongodb35.ObjectId(school);
|
|
40525
40734
|
} catch (error) {
|
|
40526
|
-
throw new
|
|
40735
|
+
throw new import_nodejs_utils63.BadRequestError("Invalid school ID.");
|
|
40527
40736
|
}
|
|
40528
40737
|
cacheParams.school = school;
|
|
40529
40738
|
}
|
|
40530
|
-
const cacheKey = (0,
|
|
40531
|
-
|
|
40739
|
+
const cacheKey = (0, import_nodejs_utils63.makeCacheKey)(namespace_collection, cacheParams);
|
|
40740
|
+
import_nodejs_utils63.logger.log({
|
|
40532
40741
|
level: "info",
|
|
40533
40742
|
message: `Cache key for getAll personnel: ${cacheKey}`
|
|
40534
40743
|
});
|
|
40535
40744
|
try {
|
|
40536
40745
|
const cached = await getCache(cacheKey);
|
|
40537
40746
|
if (cached) {
|
|
40538
|
-
|
|
40747
|
+
import_nodejs_utils63.logger.log({
|
|
40539
40748
|
level: "info",
|
|
40540
40749
|
message: `Cache hit for getAll personnel: ${cacheKey}`
|
|
40541
40750
|
});
|
|
@@ -40548,35 +40757,35 @@ function usePersonnelRepo() {
|
|
|
40548
40757
|
{ $limit: limit }
|
|
40549
40758
|
]).toArray();
|
|
40550
40759
|
const length = await collection.countDocuments(query);
|
|
40551
|
-
const data = (0,
|
|
40760
|
+
const data = (0, import_nodejs_utils63.paginate)(items, page, limit, length);
|
|
40552
40761
|
setCache(cacheKey, data, 600).then(() => {
|
|
40553
|
-
|
|
40762
|
+
import_nodejs_utils63.logger.log({
|
|
40554
40763
|
level: "info",
|
|
40555
40764
|
message: `Cache set for getAll personnel: ${cacheKey}`
|
|
40556
40765
|
});
|
|
40557
40766
|
}).catch((err) => {
|
|
40558
|
-
|
|
40767
|
+
import_nodejs_utils63.logger.log({
|
|
40559
40768
|
level: "error",
|
|
40560
40769
|
message: `Failed to set cache for getAll personnel: ${err.message}`
|
|
40561
40770
|
});
|
|
40562
40771
|
});
|
|
40563
40772
|
return data;
|
|
40564
40773
|
} catch (error) {
|
|
40565
|
-
|
|
40774
|
+
import_nodejs_utils63.logger.log({ level: "error", message: `${error}` });
|
|
40566
40775
|
throw error;
|
|
40567
40776
|
}
|
|
40568
40777
|
}
|
|
40569
40778
|
async function getById(_id) {
|
|
40570
40779
|
try {
|
|
40571
|
-
_id = new
|
|
40780
|
+
_id = new import_mongodb35.ObjectId(_id);
|
|
40572
40781
|
} catch (error) {
|
|
40573
|
-
throw new
|
|
40782
|
+
throw new import_nodejs_utils63.BadRequestError("Invalid ID.");
|
|
40574
40783
|
}
|
|
40575
|
-
const cacheKey = (0,
|
|
40784
|
+
const cacheKey = (0, import_nodejs_utils63.makeCacheKey)(namespace_collection, { _id: String(_id) });
|
|
40576
40785
|
try {
|
|
40577
40786
|
const cached = await getCache(cacheKey);
|
|
40578
40787
|
if (cached) {
|
|
40579
|
-
|
|
40788
|
+
import_nodejs_utils63.logger.log({
|
|
40580
40789
|
level: "info",
|
|
40581
40790
|
message: `Cache hit for getById personnel: ${cacheKey}`
|
|
40582
40791
|
});
|
|
@@ -40586,30 +40795,30 @@ function usePersonnelRepo() {
|
|
|
40586
40795
|
_id
|
|
40587
40796
|
});
|
|
40588
40797
|
setCache(cacheKey, result, 300).then(() => {
|
|
40589
|
-
|
|
40798
|
+
import_nodejs_utils63.logger.log({
|
|
40590
40799
|
level: "info",
|
|
40591
40800
|
message: `Cache set for personnel by id: ${cacheKey}`
|
|
40592
40801
|
});
|
|
40593
40802
|
}).catch((err) => {
|
|
40594
|
-
|
|
40803
|
+
import_nodejs_utils63.logger.log({
|
|
40595
40804
|
level: "error",
|
|
40596
40805
|
message: `Failed to set cache for personnel by id: ${err.message}`
|
|
40597
40806
|
});
|
|
40598
40807
|
});
|
|
40599
40808
|
return result;
|
|
40600
40809
|
} catch (error) {
|
|
40601
|
-
if (error instanceof
|
|
40810
|
+
if (error instanceof import_nodejs_utils63.AppError) {
|
|
40602
40811
|
throw error;
|
|
40603
40812
|
} else {
|
|
40604
|
-
throw new
|
|
40813
|
+
throw new import_nodejs_utils63.InternalServerError("Failed to get personnel.");
|
|
40605
40814
|
}
|
|
40606
40815
|
}
|
|
40607
40816
|
}
|
|
40608
40817
|
async function deleteById(_id, session) {
|
|
40609
40818
|
try {
|
|
40610
|
-
_id = new
|
|
40819
|
+
_id = new import_mongodb35.ObjectId(_id);
|
|
40611
40820
|
} catch (error) {
|
|
40612
|
-
throw new
|
|
40821
|
+
throw new import_nodejs_utils63.BadRequestError("Invalid ID.");
|
|
40613
40822
|
}
|
|
40614
40823
|
try {
|
|
40615
40824
|
const res = await collection.updateOne(
|
|
@@ -40619,14 +40828,14 @@ function usePersonnelRepo() {
|
|
|
40619
40828
|
delCachedData();
|
|
40620
40829
|
return res;
|
|
40621
40830
|
} catch (error) {
|
|
40622
|
-
|
|
40831
|
+
import_nodejs_utils63.logger.log({
|
|
40623
40832
|
level: "error",
|
|
40624
40833
|
message: error.message
|
|
40625
40834
|
});
|
|
40626
|
-
if (error instanceof
|
|
40835
|
+
if (error instanceof import_nodejs_utils63.AppError) {
|
|
40627
40836
|
throw error;
|
|
40628
40837
|
} else {
|
|
40629
|
-
throw new
|
|
40838
|
+
throw new import_nodejs_utils63.InternalServerError("Failed to delete personnel.");
|
|
40630
40839
|
}
|
|
40631
40840
|
}
|
|
40632
40841
|
}
|
|
@@ -40635,11 +40844,11 @@ function usePersonnelRepo() {
|
|
|
40635
40844
|
classification,
|
|
40636
40845
|
status: "active"
|
|
40637
40846
|
};
|
|
40638
|
-
const cacheKey = (0,
|
|
40847
|
+
const cacheKey = (0, import_nodejs_utils63.makeCacheKey)(namespace_collection, { classification });
|
|
40639
40848
|
try {
|
|
40640
40849
|
const cached = await getCache(cacheKey);
|
|
40641
40850
|
if (cached) {
|
|
40642
|
-
|
|
40851
|
+
import_nodejs_utils63.logger.log({
|
|
40643
40852
|
level: "info",
|
|
40644
40853
|
message: `Cache hit for getByClassification personnel: ${cacheKey}`
|
|
40645
40854
|
});
|
|
@@ -40647,22 +40856,22 @@ function usePersonnelRepo() {
|
|
|
40647
40856
|
}
|
|
40648
40857
|
const result = await collection.find(query).toArray();
|
|
40649
40858
|
setCache(cacheKey, result, 300).then(() => {
|
|
40650
|
-
|
|
40859
|
+
import_nodejs_utils63.logger.log({
|
|
40651
40860
|
level: "info",
|
|
40652
40861
|
message: `Cache set for personnel by classification: ${cacheKey}`
|
|
40653
40862
|
});
|
|
40654
40863
|
}).catch((err) => {
|
|
40655
|
-
|
|
40864
|
+
import_nodejs_utils63.logger.log({
|
|
40656
40865
|
level: "error",
|
|
40657
40866
|
message: `Failed to set cache for personnel by classification: ${err.message}`
|
|
40658
40867
|
});
|
|
40659
40868
|
});
|
|
40660
40869
|
return result;
|
|
40661
40870
|
} catch (error) {
|
|
40662
|
-
if (error instanceof
|
|
40871
|
+
if (error instanceof import_nodejs_utils63.AppError) {
|
|
40663
40872
|
throw error;
|
|
40664
40873
|
} else {
|
|
40665
|
-
throw new
|
|
40874
|
+
throw new import_nodejs_utils63.InternalServerError(
|
|
40666
40875
|
"Failed to get personnel by classification."
|
|
40667
40876
|
);
|
|
40668
40877
|
}
|
|
@@ -40670,12 +40879,12 @@ function usePersonnelRepo() {
|
|
|
40670
40879
|
}
|
|
40671
40880
|
function delCachedData() {
|
|
40672
40881
|
delNamespace().then(() => {
|
|
40673
|
-
|
|
40882
|
+
import_nodejs_utils63.logger.log({
|
|
40674
40883
|
level: "info",
|
|
40675
40884
|
message: `Cache cleared for namespace: ${namespace_collection}`
|
|
40676
40885
|
});
|
|
40677
40886
|
}).catch((err) => {
|
|
40678
|
-
|
|
40887
|
+
import_nodejs_utils63.logger.log({
|
|
40679
40888
|
level: "error",
|
|
40680
40889
|
message: `Failed to clear cache for namespace: ${namespace_collection}: ${err.message}`
|
|
40681
40890
|
});
|
|
@@ -40694,8 +40903,8 @@ function usePersonnelRepo() {
|
|
|
40694
40903
|
}
|
|
40695
40904
|
|
|
40696
40905
|
// src/resources/personnel/personnel.controller.ts
|
|
40697
|
-
var
|
|
40698
|
-
var
|
|
40906
|
+
var import_nodejs_utils64 = require("@eeplatform/nodejs-utils");
|
|
40907
|
+
var import_joi38 = __toESM(require("joi"));
|
|
40699
40908
|
function usePersonnelController() {
|
|
40700
40909
|
const {
|
|
40701
40910
|
getAll: _getAll,
|
|
@@ -40709,8 +40918,8 @@ function usePersonnelController() {
|
|
|
40709
40918
|
const value = req.body;
|
|
40710
40919
|
const { error } = schemaPersonnel.validate(value);
|
|
40711
40920
|
if (error) {
|
|
40712
|
-
next(new
|
|
40713
|
-
|
|
40921
|
+
next(new import_nodejs_utils64.BadRequestError(error.message));
|
|
40922
|
+
import_nodejs_utils64.logger.info(`Controller: ${error.message}`);
|
|
40714
40923
|
return;
|
|
40715
40924
|
}
|
|
40716
40925
|
try {
|
|
@@ -40724,20 +40933,20 @@ function usePersonnelController() {
|
|
|
40724
40933
|
async function updateById(req, res, next) {
|
|
40725
40934
|
const value = req.body;
|
|
40726
40935
|
const id = req.params.id ?? "";
|
|
40727
|
-
const validation =
|
|
40728
|
-
id:
|
|
40729
|
-
value:
|
|
40730
|
-
firstName:
|
|
40731
|
-
lastName:
|
|
40732
|
-
middleName:
|
|
40733
|
-
classification:
|
|
40734
|
-
status:
|
|
40936
|
+
const validation = import_joi38.default.object({
|
|
40937
|
+
id: import_joi38.default.string().hex().required(),
|
|
40938
|
+
value: import_joi38.default.object({
|
|
40939
|
+
firstName: import_joi38.default.string().optional(),
|
|
40940
|
+
lastName: import_joi38.default.string().optional(),
|
|
40941
|
+
middleName: import_joi38.default.string().optional().allow("", null),
|
|
40942
|
+
classification: import_joi38.default.string().optional(),
|
|
40943
|
+
status: import_joi38.default.string().optional()
|
|
40735
40944
|
}).min(1)
|
|
40736
40945
|
});
|
|
40737
40946
|
const { error } = validation.validate({ id, value });
|
|
40738
40947
|
if (error) {
|
|
40739
|
-
next(new
|
|
40740
|
-
|
|
40948
|
+
next(new import_nodejs_utils64.BadRequestError(error.message));
|
|
40949
|
+
import_nodejs_utils64.logger.info(`Controller: ${error.message}`);
|
|
40741
40950
|
return;
|
|
40742
40951
|
}
|
|
40743
40952
|
try {
|
|
@@ -40750,16 +40959,16 @@ function usePersonnelController() {
|
|
|
40750
40959
|
}
|
|
40751
40960
|
async function getAll(req, res, next) {
|
|
40752
40961
|
const query = req.query;
|
|
40753
|
-
const validation =
|
|
40754
|
-
page:
|
|
40755
|
-
limit:
|
|
40756
|
-
search:
|
|
40757
|
-
status:
|
|
40758
|
-
classification:
|
|
40962
|
+
const validation = import_joi38.default.object({
|
|
40963
|
+
page: import_joi38.default.number().min(1).optional().allow("", null),
|
|
40964
|
+
limit: import_joi38.default.number().min(1).optional().allow("", null),
|
|
40965
|
+
search: import_joi38.default.string().optional().allow("", null),
|
|
40966
|
+
status: import_joi38.default.string().optional().allow("", null),
|
|
40967
|
+
classification: import_joi38.default.string().optional().allow("", null)
|
|
40759
40968
|
});
|
|
40760
40969
|
const { error } = validation.validate(query);
|
|
40761
40970
|
if (error) {
|
|
40762
|
-
next(new
|
|
40971
|
+
next(new import_nodejs_utils64.BadRequestError(error.message));
|
|
40763
40972
|
return;
|
|
40764
40973
|
}
|
|
40765
40974
|
const page = parseInt(req.query.page) ?? 1;
|
|
@@ -40791,23 +41000,23 @@ function usePersonnelController() {
|
|
|
40791
41000
|
}
|
|
40792
41001
|
async function getAllBySchool(req, res, next) {
|
|
40793
41002
|
const school = req.params.school;
|
|
40794
|
-
const schoolValidation =
|
|
41003
|
+
const schoolValidation = import_joi38.default.string().hex().required();
|
|
40795
41004
|
const { error: schoolError } = schoolValidation.validate(school);
|
|
40796
41005
|
if (schoolError) {
|
|
40797
|
-
next(new
|
|
41006
|
+
next(new import_nodejs_utils64.BadRequestError(schoolError.message));
|
|
40798
41007
|
return;
|
|
40799
41008
|
}
|
|
40800
41009
|
const query = req.query;
|
|
40801
|
-
const validation =
|
|
40802
|
-
page:
|
|
40803
|
-
limit:
|
|
40804
|
-
search:
|
|
40805
|
-
status:
|
|
40806
|
-
classification:
|
|
41010
|
+
const validation = import_joi38.default.object({
|
|
41011
|
+
page: import_joi38.default.number().min(1).optional().allow("", null),
|
|
41012
|
+
limit: import_joi38.default.number().min(1).optional().allow("", null),
|
|
41013
|
+
search: import_joi38.default.string().optional().allow("", null),
|
|
41014
|
+
status: import_joi38.default.string().optional().allow("", null),
|
|
41015
|
+
classification: import_joi38.default.string().optional().allow("", null)
|
|
40807
41016
|
});
|
|
40808
41017
|
const { error } = validation.validate(query);
|
|
40809
41018
|
if (error) {
|
|
40810
|
-
next(new
|
|
41019
|
+
next(new import_nodejs_utils64.BadRequestError(error.message));
|
|
40811
41020
|
return;
|
|
40812
41021
|
}
|
|
40813
41022
|
const page = parseInt(req.query.page) ?? 1;
|
|
@@ -40840,12 +41049,12 @@ function usePersonnelController() {
|
|
|
40840
41049
|
}
|
|
40841
41050
|
async function getById(req, res, next) {
|
|
40842
41051
|
const id = req.params.id;
|
|
40843
|
-
const validation =
|
|
40844
|
-
id:
|
|
41052
|
+
const validation = import_joi38.default.object({
|
|
41053
|
+
id: import_joi38.default.string().hex().required()
|
|
40845
41054
|
});
|
|
40846
41055
|
const { error } = validation.validate({ id });
|
|
40847
41056
|
if (error) {
|
|
40848
|
-
next(new
|
|
41057
|
+
next(new import_nodejs_utils64.BadRequestError(error.message));
|
|
40849
41058
|
return;
|
|
40850
41059
|
}
|
|
40851
41060
|
try {
|
|
@@ -40861,12 +41070,12 @@ function usePersonnelController() {
|
|
|
40861
41070
|
}
|
|
40862
41071
|
async function deleteById(req, res, next) {
|
|
40863
41072
|
const id = req.params.id;
|
|
40864
|
-
const validation =
|
|
40865
|
-
id:
|
|
41073
|
+
const validation = import_joi38.default.object({
|
|
41074
|
+
id: import_joi38.default.string().hex().required()
|
|
40866
41075
|
});
|
|
40867
41076
|
const { error } = validation.validate({ id });
|
|
40868
41077
|
if (error) {
|
|
40869
|
-
next(new
|
|
41078
|
+
next(new import_nodejs_utils64.BadRequestError(error.message));
|
|
40870
41079
|
return;
|
|
40871
41080
|
}
|
|
40872
41081
|
try {
|
|
@@ -40882,12 +41091,12 @@ function usePersonnelController() {
|
|
|
40882
41091
|
}
|
|
40883
41092
|
async function getByClassification(req, res, next) {
|
|
40884
41093
|
const classification = req.params.classification;
|
|
40885
|
-
const validation =
|
|
40886
|
-
classification:
|
|
41094
|
+
const validation = import_joi38.default.object({
|
|
41095
|
+
classification: import_joi38.default.string().required()
|
|
40887
41096
|
});
|
|
40888
41097
|
const { error } = validation.validate({ classification });
|
|
40889
41098
|
if (error) {
|
|
40890
|
-
next(new
|
|
41099
|
+
next(new import_nodejs_utils64.BadRequestError(error.message));
|
|
40891
41100
|
return;
|
|
40892
41101
|
}
|
|
40893
41102
|
try {
|
|
@@ -41000,6 +41209,7 @@ dotenv.config();
|
|
|
41000
41209
|
useSectionPresetController,
|
|
41001
41210
|
useSectionPresetRepo,
|
|
41002
41211
|
useSectionRepo,
|
|
41212
|
+
useSectionStudentController,
|
|
41003
41213
|
useSectionStudentRepo,
|
|
41004
41214
|
useSectionSubjectController,
|
|
41005
41215
|
useSectionSubjectRepo,
|