@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.mjs
CHANGED
|
@@ -37891,7 +37891,7 @@ function useSectionRepo() {
|
|
|
37891
37891
|
|
|
37892
37892
|
// src/resources/section/section.controller.ts
|
|
37893
37893
|
import { BadRequestError as BadRequestError50 } from "@eeplatform/nodejs-utils";
|
|
37894
|
-
import
|
|
37894
|
+
import Joi32 from "joi";
|
|
37895
37895
|
|
|
37896
37896
|
// src/resources/section/section.service.ts
|
|
37897
37897
|
import {
|
|
@@ -37907,6 +37907,8 @@ import {
|
|
|
37907
37907
|
BadRequestError as BadRequestError45,
|
|
37908
37908
|
InternalServerError as InternalServerError13,
|
|
37909
37909
|
logger as logger26,
|
|
37910
|
+
makeCacheKey as makeCacheKey15,
|
|
37911
|
+
paginate as paginate14,
|
|
37910
37912
|
useAtlas as useAtlas21,
|
|
37911
37913
|
useCache as useCache15
|
|
37912
37914
|
} from "@eeplatform/nodejs-utils";
|
|
@@ -37923,9 +37925,15 @@ var allowedSectionStudentStatuses = [
|
|
|
37923
37925
|
];
|
|
37924
37926
|
var schemaSectionStudent = Joi28.object({
|
|
37925
37927
|
_id: Joi28.string().hex().optional().allow(null, ""),
|
|
37928
|
+
lrn: Joi28.string().required(),
|
|
37929
|
+
school: Joi28.string().hex().required(),
|
|
37930
|
+
schoolName: Joi28.string().optional().allow(null, ""),
|
|
37926
37931
|
section: Joi28.string().hex().required(),
|
|
37927
37932
|
student: Joi28.string().required(),
|
|
37928
37933
|
studentName: Joi28.string().required(),
|
|
37934
|
+
gradeLevel: Joi28.string().optional().allow(null, ""),
|
|
37935
|
+
educationLevel: Joi28.string().optional().allow(null, ""),
|
|
37936
|
+
schoolYear: Joi28.string().optional().allow(null, ""),
|
|
37929
37937
|
status: Joi28.string().valid(...allowedSectionStudentStatuses).optional().allow(null, ""),
|
|
37930
37938
|
assignedAt: Joi28.string().isoDate().optional().allow(null, ""),
|
|
37931
37939
|
updatedAt: Joi28.string().isoDate().optional().allow(null, "")
|
|
@@ -37949,11 +37957,24 @@ function modelSectionStudent(value) {
|
|
|
37949
37957
|
throw new Error("Invalid section ID.");
|
|
37950
37958
|
}
|
|
37951
37959
|
}
|
|
37960
|
+
if (value.school && typeof value.school === "string") {
|
|
37961
|
+
try {
|
|
37962
|
+
value.school = new ObjectId27(value.school);
|
|
37963
|
+
} catch (error2) {
|
|
37964
|
+
throw new Error("Invalid school ID.");
|
|
37965
|
+
}
|
|
37966
|
+
}
|
|
37952
37967
|
return {
|
|
37953
37968
|
_id: value._id,
|
|
37969
|
+
lrn: value.lrn,
|
|
37970
|
+
school: value.school,
|
|
37971
|
+
schoolName: value.schoolName,
|
|
37954
37972
|
section: value.section,
|
|
37955
37973
|
student: value.student,
|
|
37956
37974
|
studentName: value.studentName,
|
|
37975
|
+
gradeLevel: value.gradeLevel,
|
|
37976
|
+
educationLevel: value.educationLevel,
|
|
37977
|
+
schoolYear: value.schoolYear,
|
|
37957
37978
|
status: value.status ?? "active",
|
|
37958
37979
|
assignedAt: value.assignedAt ?? "",
|
|
37959
37980
|
updatedAt: value.updatedAt ?? ""
|
|
@@ -37961,6 +37982,8 @@ function modelSectionStudent(value) {
|
|
|
37961
37982
|
}
|
|
37962
37983
|
|
|
37963
37984
|
// src/resources/section-student/section.student.repository.ts
|
|
37985
|
+
import { ObjectId as ObjectId28 } from "mongodb";
|
|
37986
|
+
import Joi29 from "joi";
|
|
37964
37987
|
function useSectionStudentRepo() {
|
|
37965
37988
|
const db = useAtlas21.getDb();
|
|
37966
37989
|
if (!db) {
|
|
@@ -38024,48 +38047,140 @@ function useSectionStudentRepo() {
|
|
|
38024
38047
|
}
|
|
38025
38048
|
}
|
|
38026
38049
|
}
|
|
38050
|
+
async function getAll({
|
|
38051
|
+
page = 1,
|
|
38052
|
+
limit = 10,
|
|
38053
|
+
search = "",
|
|
38054
|
+
school = "",
|
|
38055
|
+
status = "",
|
|
38056
|
+
gradeLevel = "",
|
|
38057
|
+
section = "",
|
|
38058
|
+
schoolYear = ""
|
|
38059
|
+
} = {}) {
|
|
38060
|
+
const { error } = Joi29.object({
|
|
38061
|
+
page: Joi29.number().min(1).default(1),
|
|
38062
|
+
limit: Joi29.number().min(1).max(100).default(10),
|
|
38063
|
+
search: Joi29.string().allow("").default(""),
|
|
38064
|
+
status: Joi29.string().allow("").default(""),
|
|
38065
|
+
school: Joi29.string().hex().allow("").default(""),
|
|
38066
|
+
gradeLevel: Joi29.string().allow("").default(""),
|
|
38067
|
+
section: Joi29.string().hex().allow("").default(""),
|
|
38068
|
+
schoolYear: Joi29.string().allow("").default("")
|
|
38069
|
+
}).validate({ page, limit, search, status, school, gradeLevel, section });
|
|
38070
|
+
if (error) {
|
|
38071
|
+
throw new BadRequestError45(error.details[0].message);
|
|
38072
|
+
}
|
|
38073
|
+
const query = { status: { $ne: "deleted" } };
|
|
38074
|
+
const cacheKeyOptions = { page, limit };
|
|
38075
|
+
if (status) {
|
|
38076
|
+
query.status = status;
|
|
38077
|
+
cacheKeyOptions.status = status;
|
|
38078
|
+
}
|
|
38079
|
+
if (school && typeof school === "string") {
|
|
38080
|
+
try {
|
|
38081
|
+
query.school = new ObjectId28(school);
|
|
38082
|
+
} catch (error2) {
|
|
38083
|
+
throw new BadRequestError45("Invalid school ID format.");
|
|
38084
|
+
}
|
|
38085
|
+
cacheKeyOptions.school = school;
|
|
38086
|
+
}
|
|
38087
|
+
if (gradeLevel) {
|
|
38088
|
+
query.gradeLevel = gradeLevel;
|
|
38089
|
+
cacheKeyOptions.gradeLevel = gradeLevel;
|
|
38090
|
+
}
|
|
38091
|
+
if (search) {
|
|
38092
|
+
query.$text = { $search: search };
|
|
38093
|
+
cacheKeyOptions.search = search;
|
|
38094
|
+
}
|
|
38095
|
+
if (section && typeof section === "string") {
|
|
38096
|
+
try {
|
|
38097
|
+
query.section = new ObjectId28(section);
|
|
38098
|
+
} catch (error2) {
|
|
38099
|
+
throw new BadRequestError45("Invalid section ID format.");
|
|
38100
|
+
}
|
|
38101
|
+
cacheKeyOptions.section = section;
|
|
38102
|
+
}
|
|
38103
|
+
if (schoolYear) {
|
|
38104
|
+
query.schoolYear = schoolYear;
|
|
38105
|
+
cacheKeyOptions.schoolYear = schoolYear;
|
|
38106
|
+
}
|
|
38107
|
+
const cacheKey = makeCacheKey15(namespace_collection, cacheKeyOptions);
|
|
38108
|
+
logger26.log({
|
|
38109
|
+
level: "info",
|
|
38110
|
+
message: `Cache key for getAll sections: ${cacheKey}`
|
|
38111
|
+
});
|
|
38112
|
+
const cachedData = await getCache(cacheKey);
|
|
38113
|
+
if (cachedData) {
|
|
38114
|
+
logger26.log({
|
|
38115
|
+
level: "info",
|
|
38116
|
+
message: `Cache hit for getAll sections: ${cacheKey}`
|
|
38117
|
+
});
|
|
38118
|
+
return cachedData;
|
|
38119
|
+
}
|
|
38120
|
+
page = page > 0 ? page - 1 : 0;
|
|
38121
|
+
const items = await collection.aggregate([
|
|
38122
|
+
{ $match: query },
|
|
38123
|
+
{ $skip: page * limit },
|
|
38124
|
+
{ $limit: limit }
|
|
38125
|
+
]).toArray();
|
|
38126
|
+
const length = await collection.countDocuments(query);
|
|
38127
|
+
const data = paginate14(items, page, limit, length);
|
|
38128
|
+
setCache(cacheKey, data, 600).then(() => {
|
|
38129
|
+
logger26.log({
|
|
38130
|
+
level: "info",
|
|
38131
|
+
message: `Cache set for getAll section students: ${cacheKey}`
|
|
38132
|
+
});
|
|
38133
|
+
}).catch((err) => {
|
|
38134
|
+
logger26.log({
|
|
38135
|
+
level: "error",
|
|
38136
|
+
message: `Failed to set cache for getAll section students: ${err.message}`
|
|
38137
|
+
});
|
|
38138
|
+
});
|
|
38139
|
+
return data;
|
|
38140
|
+
}
|
|
38027
38141
|
return {
|
|
38028
38142
|
createIndexes,
|
|
38029
38143
|
delCachedData,
|
|
38030
|
-
add
|
|
38144
|
+
add,
|
|
38145
|
+
getAll
|
|
38031
38146
|
};
|
|
38032
38147
|
}
|
|
38033
38148
|
|
|
38034
38149
|
// src/resources/section-subject/section.subject.model.ts
|
|
38035
38150
|
import { BadRequestError as BadRequestError46 } from "@eeplatform/nodejs-utils";
|
|
38036
|
-
import
|
|
38037
|
-
import { ObjectId as
|
|
38038
|
-
var schemaSectionSubject =
|
|
38039
|
-
_id:
|
|
38040
|
-
school:
|
|
38041
|
-
schoolName:
|
|
38042
|
-
section:
|
|
38043
|
-
sectionName:
|
|
38044
|
-
gradeLevel:
|
|
38045
|
-
educationLevel:
|
|
38046
|
-
schoolYear:
|
|
38047
|
-
subjectCode:
|
|
38048
|
-
subjectName:
|
|
38049
|
-
teacher:
|
|
38050
|
-
teacherName:
|
|
38051
|
-
classroom:
|
|
38052
|
-
classroomName:
|
|
38053
|
-
daysOfWeek:
|
|
38054
|
-
schedule:
|
|
38055
|
-
sessionDuration:
|
|
38056
|
-
sessionFrequency:
|
|
38057
|
-
status:
|
|
38058
|
-
createdAt:
|
|
38059
|
-
updatedAt:
|
|
38060
|
-
deletedAt:
|
|
38151
|
+
import Joi30 from "joi";
|
|
38152
|
+
import { ObjectId as ObjectId29 } from "mongodb";
|
|
38153
|
+
var schemaSectionSubject = Joi30.object({
|
|
38154
|
+
_id: Joi30.string().hex().optional().allow(null, ""),
|
|
38155
|
+
school: Joi30.string().hex().required(),
|
|
38156
|
+
schoolName: Joi30.string().optional().allow(null, ""),
|
|
38157
|
+
section: Joi30.string().hex().required(),
|
|
38158
|
+
sectionName: Joi30.string().required(),
|
|
38159
|
+
gradeLevel: Joi30.string().required(),
|
|
38160
|
+
educationLevel: Joi30.string().required(),
|
|
38161
|
+
schoolYear: Joi30.string().required(),
|
|
38162
|
+
subjectCode: Joi30.string().required(),
|
|
38163
|
+
subjectName: Joi30.string().required(),
|
|
38164
|
+
teacher: Joi30.string().hex().optional().allow(null, ""),
|
|
38165
|
+
teacherName: Joi30.string().optional().allow(null, ""),
|
|
38166
|
+
classroom: Joi30.string().optional().allow(null, ""),
|
|
38167
|
+
classroomName: Joi30.string().optional().allow(null, ""),
|
|
38168
|
+
daysOfWeek: Joi30.array().items(Joi30.string()).optional().allow(null),
|
|
38169
|
+
schedule: Joi30.string().optional().allow(null, ""),
|
|
38170
|
+
sessionDuration: Joi30.number().optional().allow(null, 0),
|
|
38171
|
+
sessionFrequency: Joi30.number().optional().allow(null, 0),
|
|
38172
|
+
status: Joi30.string().valid("active", "draft").optional(),
|
|
38173
|
+
createdAt: Joi30.string().isoDate().optional().allow(null, ""),
|
|
38174
|
+
updatedAt: Joi30.string().isoDate().optional().allow(null, ""),
|
|
38175
|
+
deletedAt: Joi30.string().isoDate().optional().allow(null, "")
|
|
38061
38176
|
});
|
|
38062
|
-
var schemaSectionSubjectSetup =
|
|
38063
|
-
teacher:
|
|
38064
|
-
teacherName:
|
|
38065
|
-
classroom:
|
|
38066
|
-
classroomName:
|
|
38067
|
-
daysOfWeek:
|
|
38068
|
-
schedule:
|
|
38177
|
+
var schemaSectionSubjectSetup = Joi30.object({
|
|
38178
|
+
teacher: Joi30.string().hex().optional().allow(null, ""),
|
|
38179
|
+
teacherName: Joi30.string().optional().allow(null, ""),
|
|
38180
|
+
classroom: Joi30.string().optional().allow(null, ""),
|
|
38181
|
+
classroomName: Joi30.string().optional().allow(null, ""),
|
|
38182
|
+
daysOfWeek: Joi30.array().items(Joi30.string()).optional().allow(null),
|
|
38183
|
+
schedule: Joi30.string().optional().allow(null, "")
|
|
38069
38184
|
});
|
|
38070
38185
|
function modelSectionSubject(value) {
|
|
38071
38186
|
const { error } = schemaSectionSubject.validate(value);
|
|
@@ -38074,28 +38189,28 @@ function modelSectionSubject(value) {
|
|
|
38074
38189
|
}
|
|
38075
38190
|
if (value._id && typeof value._id === "string") {
|
|
38076
38191
|
try {
|
|
38077
|
-
value._id = new
|
|
38192
|
+
value._id = new ObjectId29(value._id);
|
|
38078
38193
|
} catch (error2) {
|
|
38079
38194
|
throw new Error("Invalid _id.");
|
|
38080
38195
|
}
|
|
38081
38196
|
}
|
|
38082
38197
|
if (value.school && typeof value.school === "string") {
|
|
38083
38198
|
try {
|
|
38084
|
-
value.school = new
|
|
38199
|
+
value.school = new ObjectId29(value.school);
|
|
38085
38200
|
} catch (error2) {
|
|
38086
38201
|
throw new Error("Invalid school ID.");
|
|
38087
38202
|
}
|
|
38088
38203
|
}
|
|
38089
38204
|
if (value.section && typeof value.section === "string") {
|
|
38090
38205
|
try {
|
|
38091
|
-
value.section = new
|
|
38206
|
+
value.section = new ObjectId29(value.section);
|
|
38092
38207
|
} catch (error2) {
|
|
38093
38208
|
throw new Error("Invalid section ID.");
|
|
38094
38209
|
}
|
|
38095
38210
|
}
|
|
38096
38211
|
if (value.teacher && typeof value.teacher === "string") {
|
|
38097
38212
|
try {
|
|
38098
|
-
value.teacher = new
|
|
38213
|
+
value.teacher = new ObjectId29(value.teacher);
|
|
38099
38214
|
} catch (error2) {
|
|
38100
38215
|
throw new Error("Invalid teacher ID.");
|
|
38101
38216
|
}
|
|
@@ -38132,12 +38247,12 @@ import {
|
|
|
38132
38247
|
BadRequestError as BadRequestError47,
|
|
38133
38248
|
InternalServerError as InternalServerError14,
|
|
38134
38249
|
logger as logger27,
|
|
38135
|
-
makeCacheKey as
|
|
38136
|
-
paginate as
|
|
38250
|
+
makeCacheKey as makeCacheKey16,
|
|
38251
|
+
paginate as paginate15,
|
|
38137
38252
|
useAtlas as useAtlas22,
|
|
38138
38253
|
useCache as useCache16
|
|
38139
38254
|
} from "@eeplatform/nodejs-utils";
|
|
38140
|
-
import { ObjectId as
|
|
38255
|
+
import { ObjectId as ObjectId30 } from "mongodb";
|
|
38141
38256
|
function useSectionSubjectRepo() {
|
|
38142
38257
|
const db = useAtlas22.getDb();
|
|
38143
38258
|
if (!db) {
|
|
@@ -38240,7 +38355,7 @@ function useSectionSubjectRepo() {
|
|
|
38240
38355
|
}
|
|
38241
38356
|
if (school) {
|
|
38242
38357
|
try {
|
|
38243
|
-
query.school = new
|
|
38358
|
+
query.school = new ObjectId30(school);
|
|
38244
38359
|
} catch (error) {
|
|
38245
38360
|
throw new BadRequestError47("Invalid school ID.");
|
|
38246
38361
|
}
|
|
@@ -38248,7 +38363,7 @@ function useSectionSubjectRepo() {
|
|
|
38248
38363
|
}
|
|
38249
38364
|
if (section) {
|
|
38250
38365
|
try {
|
|
38251
|
-
query.section = new
|
|
38366
|
+
query.section = new ObjectId30(section);
|
|
38252
38367
|
} catch (error) {
|
|
38253
38368
|
throw new BadRequestError47("Invalid section ID.");
|
|
38254
38369
|
}
|
|
@@ -38256,7 +38371,7 @@ function useSectionSubjectRepo() {
|
|
|
38256
38371
|
}
|
|
38257
38372
|
if (teacher) {
|
|
38258
38373
|
try {
|
|
38259
|
-
query.teacher = new
|
|
38374
|
+
query.teacher = new ObjectId30(teacher);
|
|
38260
38375
|
} catch (error) {
|
|
38261
38376
|
throw new BadRequestError47("Invalid teacher ID.");
|
|
38262
38377
|
}
|
|
@@ -38279,7 +38394,7 @@ function useSectionSubjectRepo() {
|
|
|
38279
38394
|
query.$text = { $search: search };
|
|
38280
38395
|
cacheKeyOptions.search = search;
|
|
38281
38396
|
}
|
|
38282
|
-
const cacheKey =
|
|
38397
|
+
const cacheKey = makeCacheKey16(namespace_collection, cacheKeyOptions);
|
|
38283
38398
|
logger27.log({
|
|
38284
38399
|
level: "info",
|
|
38285
38400
|
message: `Cache key for getAll section subjects: ${cacheKey}`
|
|
@@ -38300,7 +38415,7 @@ function useSectionSubjectRepo() {
|
|
|
38300
38415
|
{ $limit: limit }
|
|
38301
38416
|
]).toArray();
|
|
38302
38417
|
const length = await collection.countDocuments(query);
|
|
38303
|
-
const data =
|
|
38418
|
+
const data = paginate15(items, page, limit, length);
|
|
38304
38419
|
setCache(cacheKey, data, 600).then(() => {
|
|
38305
38420
|
logger27.log({
|
|
38306
38421
|
level: "info",
|
|
@@ -38320,11 +38435,11 @@ function useSectionSubjectRepo() {
|
|
|
38320
38435
|
}
|
|
38321
38436
|
async function getById(_id) {
|
|
38322
38437
|
try {
|
|
38323
|
-
_id = new
|
|
38438
|
+
_id = new ObjectId30(_id);
|
|
38324
38439
|
} catch (error) {
|
|
38325
38440
|
throw new BadRequestError47("Invalid ID.");
|
|
38326
38441
|
}
|
|
38327
|
-
const cacheKey =
|
|
38442
|
+
const cacheKey = makeCacheKey16(namespace_collection, { _id: String(_id) });
|
|
38328
38443
|
try {
|
|
38329
38444
|
const cached = await getCache(cacheKey);
|
|
38330
38445
|
if (cached) {
|
|
@@ -38363,11 +38478,11 @@ function useSectionSubjectRepo() {
|
|
|
38363
38478
|
}
|
|
38364
38479
|
async function getBySection(section) {
|
|
38365
38480
|
try {
|
|
38366
|
-
section = new
|
|
38481
|
+
section = new ObjectId30(section);
|
|
38367
38482
|
} catch (error) {
|
|
38368
38483
|
throw new BadRequestError47("Invalid section ID.");
|
|
38369
38484
|
}
|
|
38370
|
-
const cacheKey =
|
|
38485
|
+
const cacheKey = makeCacheKey16(namespace_collection, {
|
|
38371
38486
|
section: String(section)
|
|
38372
38487
|
});
|
|
38373
38488
|
try {
|
|
@@ -38407,11 +38522,11 @@ function useSectionSubjectRepo() {
|
|
|
38407
38522
|
}
|
|
38408
38523
|
async function getByTeacher(teacher) {
|
|
38409
38524
|
try {
|
|
38410
|
-
teacher = new
|
|
38525
|
+
teacher = new ObjectId30(teacher);
|
|
38411
38526
|
} catch (error) {
|
|
38412
38527
|
throw new BadRequestError47("Invalid teacher ID.");
|
|
38413
38528
|
}
|
|
38414
|
-
const cacheKey =
|
|
38529
|
+
const cacheKey = makeCacheKey16(namespace_collection, {
|
|
38415
38530
|
teacher: String(teacher)
|
|
38416
38531
|
});
|
|
38417
38532
|
try {
|
|
@@ -38451,11 +38566,11 @@ function useSectionSubjectRepo() {
|
|
|
38451
38566
|
}
|
|
38452
38567
|
async function getBySchool(school) {
|
|
38453
38568
|
try {
|
|
38454
|
-
school = new
|
|
38569
|
+
school = new ObjectId30(school);
|
|
38455
38570
|
} catch (error) {
|
|
38456
38571
|
throw new BadRequestError47("Invalid school ID.");
|
|
38457
38572
|
}
|
|
38458
|
-
const cacheKey =
|
|
38573
|
+
const cacheKey = makeCacheKey16(namespace_collection, {
|
|
38459
38574
|
school: String(school)
|
|
38460
38575
|
});
|
|
38461
38576
|
try {
|
|
@@ -38507,19 +38622,19 @@ function useSectionSubjectRepo() {
|
|
|
38507
38622
|
);
|
|
38508
38623
|
}
|
|
38509
38624
|
try {
|
|
38510
|
-
_id = new
|
|
38625
|
+
_id = new ObjectId30(_id);
|
|
38511
38626
|
} catch (error) {
|
|
38512
38627
|
throw new BadRequestError47("Invalid ID.");
|
|
38513
38628
|
}
|
|
38514
38629
|
if (field === "teacher" && value) {
|
|
38515
38630
|
try {
|
|
38516
|
-
value = new
|
|
38631
|
+
value = new ObjectId30(value).toString();
|
|
38517
38632
|
} catch (error) {
|
|
38518
38633
|
throw new BadRequestError47("Invalid teacher ID.");
|
|
38519
38634
|
}
|
|
38520
38635
|
}
|
|
38521
38636
|
try {
|
|
38522
|
-
const updateValue = field === "teacher" ? new
|
|
38637
|
+
const updateValue = field === "teacher" ? new ObjectId30(value) : value;
|
|
38523
38638
|
await collection.updateOne(
|
|
38524
38639
|
{ _id, deletedAt: { $in: ["", null] } },
|
|
38525
38640
|
{ $set: { [field]: updateValue, updatedAt: (/* @__PURE__ */ new Date()).toISOString() } },
|
|
@@ -38541,7 +38656,7 @@ function useSectionSubjectRepo() {
|
|
|
38541
38656
|
);
|
|
38542
38657
|
}
|
|
38543
38658
|
try {
|
|
38544
|
-
_id = new
|
|
38659
|
+
_id = new ObjectId30(_id);
|
|
38545
38660
|
} catch (error2) {
|
|
38546
38661
|
throw new BadRequestError47("Invalid ID.");
|
|
38547
38662
|
}
|
|
@@ -38559,7 +38674,7 @@ function useSectionSubjectRepo() {
|
|
|
38559
38674
|
}
|
|
38560
38675
|
async function deleteById(_id) {
|
|
38561
38676
|
try {
|
|
38562
|
-
_id = new
|
|
38677
|
+
_id = new ObjectId30(_id);
|
|
38563
38678
|
} catch (error) {
|
|
38564
38679
|
throw new BadRequestError47("Invalid ID.");
|
|
38565
38680
|
}
|
|
@@ -38624,7 +38739,7 @@ function useSectionSubjectService() {
|
|
|
38624
38739
|
|
|
38625
38740
|
// src/resources/section-subject/section.subject.controller.ts
|
|
38626
38741
|
import { BadRequestError as BadRequestError48 } from "@eeplatform/nodejs-utils";
|
|
38627
|
-
import
|
|
38742
|
+
import Joi31 from "joi";
|
|
38628
38743
|
function useSectionSubjectController() {
|
|
38629
38744
|
const {
|
|
38630
38745
|
getAll: _getAll,
|
|
@@ -38657,17 +38772,17 @@ function useSectionSubjectController() {
|
|
|
38657
38772
|
}
|
|
38658
38773
|
async function getAll(req, res, next) {
|
|
38659
38774
|
const query = req.query;
|
|
38660
|
-
const validation =
|
|
38661
|
-
page:
|
|
38662
|
-
limit:
|
|
38663
|
-
search:
|
|
38664
|
-
status:
|
|
38665
|
-
school:
|
|
38666
|
-
section:
|
|
38667
|
-
teacher:
|
|
38668
|
-
schoolYear:
|
|
38669
|
-
gradeLevel:
|
|
38670
|
-
subjectCode:
|
|
38775
|
+
const validation = Joi31.object({
|
|
38776
|
+
page: Joi31.number().min(1).optional().allow("", null),
|
|
38777
|
+
limit: Joi31.number().min(1).optional().allow("", null),
|
|
38778
|
+
search: Joi31.string().optional().allow("", null),
|
|
38779
|
+
status: Joi31.string().optional().allow("", null),
|
|
38780
|
+
school: Joi31.string().hex().optional().allow("", null),
|
|
38781
|
+
section: Joi31.string().hex().optional().allow("", null),
|
|
38782
|
+
teacher: Joi31.string().hex().optional().allow("", null),
|
|
38783
|
+
schoolYear: Joi31.string().optional().allow("", null),
|
|
38784
|
+
gradeLevel: Joi31.string().optional().allow("", null),
|
|
38785
|
+
subjectCode: Joi31.string().optional().allow("", null)
|
|
38671
38786
|
});
|
|
38672
38787
|
const { error } = validation.validate(query);
|
|
38673
38788
|
const page = typeof req.query.page === "string" ? Number(req.query.page) : 1;
|
|
@@ -38715,8 +38830,8 @@ function useSectionSubjectController() {
|
|
|
38715
38830
|
}
|
|
38716
38831
|
async function getById(req, res, next) {
|
|
38717
38832
|
const id = req.params.id;
|
|
38718
|
-
const validation =
|
|
38719
|
-
id:
|
|
38833
|
+
const validation = Joi31.object({
|
|
38834
|
+
id: Joi31.string().hex().required()
|
|
38720
38835
|
});
|
|
38721
38836
|
const { error } = validation.validate({ id });
|
|
38722
38837
|
if (error) {
|
|
@@ -38736,8 +38851,8 @@ function useSectionSubjectController() {
|
|
|
38736
38851
|
}
|
|
38737
38852
|
async function getBySection(req, res, next) {
|
|
38738
38853
|
const section = req.params.section;
|
|
38739
|
-
const validation =
|
|
38740
|
-
section:
|
|
38854
|
+
const validation = Joi31.object({
|
|
38855
|
+
section: Joi31.string().hex().required()
|
|
38741
38856
|
});
|
|
38742
38857
|
const { error } = validation.validate({ section });
|
|
38743
38858
|
if (error) {
|
|
@@ -38757,8 +38872,8 @@ function useSectionSubjectController() {
|
|
|
38757
38872
|
}
|
|
38758
38873
|
async function getByTeacher(req, res, next) {
|
|
38759
38874
|
const teacher = req.params.teacher;
|
|
38760
|
-
const validation =
|
|
38761
|
-
teacher:
|
|
38875
|
+
const validation = Joi31.object({
|
|
38876
|
+
teacher: Joi31.string().hex().required()
|
|
38762
38877
|
});
|
|
38763
38878
|
const { error } = validation.validate({ teacher });
|
|
38764
38879
|
if (error) {
|
|
@@ -38778,8 +38893,8 @@ function useSectionSubjectController() {
|
|
|
38778
38893
|
}
|
|
38779
38894
|
async function getBySchool(req, res, next) {
|
|
38780
38895
|
const school = req.params.school;
|
|
38781
|
-
const validation =
|
|
38782
|
-
school:
|
|
38896
|
+
const validation = Joi31.object({
|
|
38897
|
+
school: Joi31.string().hex().required()
|
|
38783
38898
|
});
|
|
38784
38899
|
const { error } = validation.validate({ school });
|
|
38785
38900
|
if (error) {
|
|
@@ -38800,9 +38915,9 @@ function useSectionSubjectController() {
|
|
|
38800
38915
|
async function updateField(req, res, next) {
|
|
38801
38916
|
const _id = req.params.id;
|
|
38802
38917
|
const { field, value } = req.body;
|
|
38803
|
-
const validation =
|
|
38804
|
-
_id:
|
|
38805
|
-
field:
|
|
38918
|
+
const validation = Joi31.object({
|
|
38919
|
+
_id: Joi31.string().hex().required(),
|
|
38920
|
+
field: Joi31.string().valid(
|
|
38806
38921
|
"subjectCode",
|
|
38807
38922
|
"subjectName",
|
|
38808
38923
|
"teacher",
|
|
@@ -38810,7 +38925,7 @@ function useSectionSubjectController() {
|
|
|
38810
38925
|
"classroom",
|
|
38811
38926
|
"schedule"
|
|
38812
38927
|
).required(),
|
|
38813
|
-
value:
|
|
38928
|
+
value: Joi31.string().required()
|
|
38814
38929
|
});
|
|
38815
38930
|
const { error } = validation.validate({ _id, field, value });
|
|
38816
38931
|
if (error) {
|
|
@@ -38843,8 +38958,8 @@ function useSectionSubjectController() {
|
|
|
38843
38958
|
}
|
|
38844
38959
|
async function deleteById(req, res, next) {
|
|
38845
38960
|
const _id = req.params.id;
|
|
38846
|
-
const validation =
|
|
38847
|
-
_id:
|
|
38961
|
+
const validation = Joi31.object({
|
|
38962
|
+
_id: Joi31.string().hex().required()
|
|
38848
38963
|
});
|
|
38849
38964
|
const { error } = validation.validate({ _id });
|
|
38850
38965
|
if (error) {
|
|
@@ -38880,6 +38995,7 @@ function useSectionService() {
|
|
|
38880
38995
|
const { add: assignStudent } = useSectionStudentRepo();
|
|
38881
38996
|
const { getAll: getAllCurriculumSubjects } = useCurriculumSubjectRepo();
|
|
38882
38997
|
const { add: addSectionSubject } = useSectionSubjectRepo();
|
|
38998
|
+
const { getById: getSchoolById } = useSchoolRepo();
|
|
38883
38999
|
function distributeStudents(total, minPer, maxPer) {
|
|
38884
39000
|
if (total <= 0)
|
|
38885
39001
|
return [];
|
|
@@ -38963,6 +39079,10 @@ function useSectionService() {
|
|
|
38963
39079
|
if (sectionSizes.length === 0) {
|
|
38964
39080
|
throw new BadRequestError49("Unable to compute section sizes.");
|
|
38965
39081
|
}
|
|
39082
|
+
const schoolData = await getSchoolById(value.school);
|
|
39083
|
+
if (!schoolData) {
|
|
39084
|
+
throw new BadRequestError49("School not found.");
|
|
39085
|
+
}
|
|
38966
39086
|
let totalStudentsProcessed = 0;
|
|
38967
39087
|
for (let i = 0; i < sectionSizes.length; i++) {
|
|
38968
39088
|
const size = sectionSizes[i];
|
|
@@ -38995,11 +39115,20 @@ function useSectionService() {
|
|
|
38995
39115
|
if (!student._id) {
|
|
38996
39116
|
throw new BadRequestError49("Learner ID is missing.");
|
|
38997
39117
|
}
|
|
39118
|
+
if (!student.learnerInfo.lrn) {
|
|
39119
|
+
throw new BadRequestError49("Learner LRN is missing.");
|
|
39120
|
+
}
|
|
38998
39121
|
await assignStudent(
|
|
38999
39122
|
{
|
|
39000
39123
|
section: section.toString(),
|
|
39124
|
+
lrn: student.learnerInfo.lrn,
|
|
39001
39125
|
student: student._id?.toString(),
|
|
39002
39126
|
studentName: `${student.learnerInfo.firstName} ${student.learnerInfo.lastName}`,
|
|
39127
|
+
school: value.school,
|
|
39128
|
+
schoolName: schoolData.name,
|
|
39129
|
+
gradeLevel: value.gradeLevel,
|
|
39130
|
+
educationLevel: gradeLevelData.educationLevel,
|
|
39131
|
+
schoolYear: value.schoolYear,
|
|
39003
39132
|
status: "active"
|
|
39004
39133
|
},
|
|
39005
39134
|
session
|
|
@@ -39014,7 +39143,7 @@ function useSectionService() {
|
|
|
39014
39143
|
await addSectionSubject(
|
|
39015
39144
|
{
|
|
39016
39145
|
school: value.school,
|
|
39017
|
-
schoolName:
|
|
39146
|
+
schoolName: schoolData.name,
|
|
39018
39147
|
gradeLevel: value.gradeLevel,
|
|
39019
39148
|
educationLevel: gradeLevelData.educationLevel,
|
|
39020
39149
|
schoolYear: value.schoolYear,
|
|
@@ -39104,14 +39233,14 @@ function useSectionController() {
|
|
|
39104
39233
|
}
|
|
39105
39234
|
async function getAll(req, res, next) {
|
|
39106
39235
|
const query = req.query;
|
|
39107
|
-
const validation =
|
|
39108
|
-
page:
|
|
39109
|
-
limit:
|
|
39110
|
-
search:
|
|
39111
|
-
status:
|
|
39112
|
-
school:
|
|
39113
|
-
schoolYear:
|
|
39114
|
-
gradeLevel:
|
|
39236
|
+
const validation = Joi32.object({
|
|
39237
|
+
page: Joi32.number().min(1).optional().allow("", null),
|
|
39238
|
+
limit: Joi32.number().min(1).optional().allow("", null),
|
|
39239
|
+
search: Joi32.string().optional().allow("", null),
|
|
39240
|
+
status: Joi32.string().optional().allow("", null),
|
|
39241
|
+
school: Joi32.string().hex().optional().allow("", null),
|
|
39242
|
+
schoolYear: Joi32.string().optional().allow("", null),
|
|
39243
|
+
gradeLevel: Joi32.string().optional().allow("", null)
|
|
39115
39244
|
});
|
|
39116
39245
|
const { error } = validation.validate(query);
|
|
39117
39246
|
const page = typeof req.query.page === "string" ? Number(req.query.page) : 1;
|
|
@@ -39153,8 +39282,8 @@ function useSectionController() {
|
|
|
39153
39282
|
}
|
|
39154
39283
|
async function getById(req, res, next) {
|
|
39155
39284
|
const id = req.params.id;
|
|
39156
|
-
const validation =
|
|
39157
|
-
id:
|
|
39285
|
+
const validation = Joi32.object({
|
|
39286
|
+
id: Joi32.string().hex().required()
|
|
39158
39287
|
});
|
|
39159
39288
|
const { error } = validation.validate({ id });
|
|
39160
39289
|
if (error) {
|
|
@@ -39171,8 +39300,8 @@ function useSectionController() {
|
|
|
39171
39300
|
}
|
|
39172
39301
|
async function getByName(req, res, next) {
|
|
39173
39302
|
const name = req.params.name;
|
|
39174
|
-
const validation =
|
|
39175
|
-
name:
|
|
39303
|
+
const validation = Joi32.object({
|
|
39304
|
+
name: Joi32.string().required()
|
|
39176
39305
|
});
|
|
39177
39306
|
const { error } = validation.validate({ name });
|
|
39178
39307
|
if (error) {
|
|
@@ -39192,8 +39321,8 @@ function useSectionController() {
|
|
|
39192
39321
|
}
|
|
39193
39322
|
async function getBySchool(req, res, next) {
|
|
39194
39323
|
const school = req.params.school;
|
|
39195
|
-
const validation =
|
|
39196
|
-
school:
|
|
39324
|
+
const validation = Joi32.object({
|
|
39325
|
+
school: Joi32.string().hex().required()
|
|
39197
39326
|
});
|
|
39198
39327
|
const { error } = validation.validate({ school });
|
|
39199
39328
|
if (error) {
|
|
@@ -39214,10 +39343,10 @@ function useSectionController() {
|
|
|
39214
39343
|
async function updateField(req, res, next) {
|
|
39215
39344
|
const _id = req.params.id;
|
|
39216
39345
|
const { field, value } = req.body;
|
|
39217
|
-
const validation =
|
|
39218
|
-
_id:
|
|
39219
|
-
field:
|
|
39220
|
-
value:
|
|
39346
|
+
const validation = Joi32.object({
|
|
39347
|
+
_id: Joi32.string().hex().required(),
|
|
39348
|
+
field: Joi32.string().valid("name", "schoolYear", "gradeLevel", "adviser", "adviserName").required(),
|
|
39349
|
+
value: Joi32.string().required()
|
|
39221
39350
|
});
|
|
39222
39351
|
const { error } = validation.validate({ _id, field, value });
|
|
39223
39352
|
if (error) {
|
|
@@ -39235,9 +39364,9 @@ function useSectionController() {
|
|
|
39235
39364
|
async function addStudent(req, res, next) {
|
|
39236
39365
|
const _id = req.params.id;
|
|
39237
39366
|
const { studentId } = req.body;
|
|
39238
|
-
const validation =
|
|
39239
|
-
_id:
|
|
39240
|
-
studentId:
|
|
39367
|
+
const validation = Joi32.object({
|
|
39368
|
+
_id: Joi32.string().hex().required(),
|
|
39369
|
+
studentId: Joi32.string().required()
|
|
39241
39370
|
});
|
|
39242
39371
|
const { error } = validation.validate({ _id, studentId });
|
|
39243
39372
|
if (error) {
|
|
@@ -39255,9 +39384,9 @@ function useSectionController() {
|
|
|
39255
39384
|
async function removeStudent(req, res, next) {
|
|
39256
39385
|
const _id = req.params.id;
|
|
39257
39386
|
const { studentId } = req.body;
|
|
39258
|
-
const validation =
|
|
39259
|
-
_id:
|
|
39260
|
-
studentId:
|
|
39387
|
+
const validation = Joi32.object({
|
|
39388
|
+
_id: Joi32.string().hex().required(),
|
|
39389
|
+
studentId: Joi32.string().required()
|
|
39261
39390
|
});
|
|
39262
39391
|
const { error } = validation.validate({ _id, studentId });
|
|
39263
39392
|
if (error) {
|
|
@@ -39274,8 +39403,8 @@ function useSectionController() {
|
|
|
39274
39403
|
}
|
|
39275
39404
|
async function deleteById(req, res, next) {
|
|
39276
39405
|
const _id = req.params.id;
|
|
39277
|
-
const validation =
|
|
39278
|
-
_id:
|
|
39406
|
+
const validation = Joi32.object({
|
|
39407
|
+
_id: Joi32.string().hex().required()
|
|
39279
39408
|
});
|
|
39280
39409
|
const { error } = validation.validate({ _id });
|
|
39281
39410
|
if (error) {
|
|
@@ -39304,65 +39433,146 @@ function useSectionController() {
|
|
|
39304
39433
|
};
|
|
39305
39434
|
}
|
|
39306
39435
|
|
|
39436
|
+
// src/resources/section-student/section.student.controller.ts
|
|
39437
|
+
import { BadRequestError as BadRequestError51 } from "@eeplatform/nodejs-utils";
|
|
39438
|
+
import Joi33 from "joi";
|
|
39439
|
+
function useSectionStudentController() {
|
|
39440
|
+
const { add: _add, getAll: _getAll } = useSectionStudentRepo();
|
|
39441
|
+
async function add(req, res, next) {
|
|
39442
|
+
const value = req.body;
|
|
39443
|
+
const { error } = schemaSectionStudent.validate(value);
|
|
39444
|
+
if (error) {
|
|
39445
|
+
next(new BadRequestError51(error.message));
|
|
39446
|
+
return;
|
|
39447
|
+
}
|
|
39448
|
+
try {
|
|
39449
|
+
const data = await _add(value);
|
|
39450
|
+
res.json({
|
|
39451
|
+
message: "Successfully created section student.",
|
|
39452
|
+
data
|
|
39453
|
+
});
|
|
39454
|
+
return;
|
|
39455
|
+
} catch (error2) {
|
|
39456
|
+
next(error2);
|
|
39457
|
+
}
|
|
39458
|
+
}
|
|
39459
|
+
async function getAll(req, res, next) {
|
|
39460
|
+
const query = req.query;
|
|
39461
|
+
const validation = Joi33.object({
|
|
39462
|
+
page: Joi33.number().min(1).optional().allow("", null),
|
|
39463
|
+
limit: Joi33.number().min(1).optional().allow("", null),
|
|
39464
|
+
search: Joi33.string().optional().allow("", null),
|
|
39465
|
+
status: Joi33.string().optional().allow("", null),
|
|
39466
|
+
school: Joi33.string().optional().allow("", null),
|
|
39467
|
+
gradeLevel: Joi33.string().optional().allow("", null),
|
|
39468
|
+
section: Joi33.string().optional().allow("", null),
|
|
39469
|
+
schoolYear: Joi33.string().optional().allow("", null)
|
|
39470
|
+
});
|
|
39471
|
+
const { error } = validation.validate(query);
|
|
39472
|
+
const page = typeof req.query.page === "string" ? Number(req.query.page) : 1;
|
|
39473
|
+
const limit = typeof req.query.limit === "string" ? Number(req.query.limit) : 10;
|
|
39474
|
+
const search = req.query.search ?? "";
|
|
39475
|
+
const status = req.query.status ?? "active";
|
|
39476
|
+
const school = req.query.school ?? "";
|
|
39477
|
+
const gradeLevel = req.query.gradeLevel ?? "";
|
|
39478
|
+
const section = req.query.section ?? "";
|
|
39479
|
+
const schoolYear = req.query.schoolYear ?? "";
|
|
39480
|
+
const isPageNumber = isFinite(page);
|
|
39481
|
+
if (!isPageNumber) {
|
|
39482
|
+
next(new BadRequestError51("Invalid page number."));
|
|
39483
|
+
return;
|
|
39484
|
+
}
|
|
39485
|
+
const isLimitNumber = isFinite(limit);
|
|
39486
|
+
if (!isLimitNumber) {
|
|
39487
|
+
next(new BadRequestError51("Invalid limit number."));
|
|
39488
|
+
return;
|
|
39489
|
+
}
|
|
39490
|
+
if (error) {
|
|
39491
|
+
next(new BadRequestError51(error.message));
|
|
39492
|
+
return;
|
|
39493
|
+
}
|
|
39494
|
+
try {
|
|
39495
|
+
const data = await _getAll({
|
|
39496
|
+
page,
|
|
39497
|
+
limit,
|
|
39498
|
+
search,
|
|
39499
|
+
status,
|
|
39500
|
+
school,
|
|
39501
|
+
gradeLevel,
|
|
39502
|
+
section,
|
|
39503
|
+
schoolYear
|
|
39504
|
+
});
|
|
39505
|
+
res.json(data);
|
|
39506
|
+
return;
|
|
39507
|
+
} catch (error2) {
|
|
39508
|
+
next(error2);
|
|
39509
|
+
}
|
|
39510
|
+
}
|
|
39511
|
+
return {
|
|
39512
|
+
add,
|
|
39513
|
+
getAll
|
|
39514
|
+
};
|
|
39515
|
+
}
|
|
39516
|
+
|
|
39307
39517
|
// src/resources/building/building.model.ts
|
|
39308
|
-
import { BadRequestError as
|
|
39309
|
-
import
|
|
39310
|
-
import { ObjectId as
|
|
39311
|
-
var schemaBuilding =
|
|
39312
|
-
_id:
|
|
39313
|
-
school:
|
|
39314
|
-
serial:
|
|
39315
|
-
name:
|
|
39316
|
-
levels:
|
|
39317
|
-
createdAt:
|
|
39318
|
-
updatedAt:
|
|
39319
|
-
deletedAt:
|
|
39320
|
-
status:
|
|
39518
|
+
import { BadRequestError as BadRequestError52, logger as logger28 } from "@eeplatform/nodejs-utils";
|
|
39519
|
+
import Joi34 from "joi";
|
|
39520
|
+
import { ObjectId as ObjectId31 } from "mongodb";
|
|
39521
|
+
var schemaBuilding = Joi34.object({
|
|
39522
|
+
_id: Joi34.string().hex().optional(),
|
|
39523
|
+
school: Joi34.string().hex().required(),
|
|
39524
|
+
serial: Joi34.string().optional().allow("", null),
|
|
39525
|
+
name: Joi34.string().required(),
|
|
39526
|
+
levels: Joi34.number().integer().min(1).required(),
|
|
39527
|
+
createdAt: Joi34.date().optional().allow("", null),
|
|
39528
|
+
updatedAt: Joi34.date().optional().allow("", null),
|
|
39529
|
+
deletedAt: Joi34.date().optional().allow("", null),
|
|
39530
|
+
status: Joi34.string().optional().allow("", null)
|
|
39321
39531
|
});
|
|
39322
|
-
var schemaBuildingUnit =
|
|
39323
|
-
_id:
|
|
39324
|
-
school:
|
|
39325
|
-
name:
|
|
39326
|
-
building:
|
|
39327
|
-
buildingName:
|
|
39328
|
-
level:
|
|
39329
|
-
category:
|
|
39330
|
-
type:
|
|
39331
|
-
seating_capacity:
|
|
39332
|
-
standing_capacity:
|
|
39333
|
-
description:
|
|
39334
|
-
unit_of_measurement:
|
|
39335
|
-
area:
|
|
39336
|
-
status:
|
|
39532
|
+
var schemaBuildingUnit = Joi34.object({
|
|
39533
|
+
_id: Joi34.string().hex().optional(),
|
|
39534
|
+
school: Joi34.string().hex().required(),
|
|
39535
|
+
name: Joi34.string().optional().allow("", null),
|
|
39536
|
+
building: Joi34.string().hex().required(),
|
|
39537
|
+
buildingName: Joi34.string().optional().allow("", null),
|
|
39538
|
+
level: Joi34.number().integer().min(1).required(),
|
|
39539
|
+
category: Joi34.string().required(),
|
|
39540
|
+
type: Joi34.string().required(),
|
|
39541
|
+
seating_capacity: Joi34.number().integer().min(0).required(),
|
|
39542
|
+
standing_capacity: Joi34.number().integer().min(0).required(),
|
|
39543
|
+
description: Joi34.string().optional().allow("", null),
|
|
39544
|
+
unit_of_measurement: Joi34.string().valid("sqm").required(),
|
|
39545
|
+
area: Joi34.number().positive().required(),
|
|
39546
|
+
status: Joi34.string().optional().allow("", null)
|
|
39337
39547
|
});
|
|
39338
|
-
var schemaUpdateOptions =
|
|
39339
|
-
name:
|
|
39340
|
-
building:
|
|
39341
|
-
buildingName:
|
|
39342
|
-
level:
|
|
39343
|
-
category:
|
|
39344
|
-
type:
|
|
39345
|
-
seating_capacity:
|
|
39346
|
-
standing_capacity:
|
|
39347
|
-
area:
|
|
39548
|
+
var schemaUpdateOptions = Joi34.object({
|
|
39549
|
+
name: Joi34.string().optional().allow("", null),
|
|
39550
|
+
building: Joi34.string().hex().optional().allow("", null),
|
|
39551
|
+
buildingName: Joi34.string().optional().allow("", null),
|
|
39552
|
+
level: Joi34.number().integer().min(1).optional().allow("", null),
|
|
39553
|
+
category: Joi34.string().optional().allow("", null),
|
|
39554
|
+
type: Joi34.string().optional().allow("", null),
|
|
39555
|
+
seating_capacity: Joi34.number().integer().min(0).optional().allow("", null),
|
|
39556
|
+
standing_capacity: Joi34.number().integer().min(0).optional().allow("", null),
|
|
39557
|
+
area: Joi34.number().positive().optional().allow("", null)
|
|
39348
39558
|
});
|
|
39349
39559
|
function MBuilding(value) {
|
|
39350
39560
|
const { error } = schemaBuilding.validate(value);
|
|
39351
39561
|
if (error) {
|
|
39352
39562
|
logger28.info(`Building Model: ${error.message}`);
|
|
39353
|
-
throw new
|
|
39563
|
+
throw new BadRequestError52(error.message);
|
|
39354
39564
|
}
|
|
39355
39565
|
if (value._id && typeof value._id === "string") {
|
|
39356
39566
|
try {
|
|
39357
|
-
value._id = new
|
|
39567
|
+
value._id = new ObjectId31(value._id);
|
|
39358
39568
|
} catch (error2) {
|
|
39359
|
-
throw new
|
|
39569
|
+
throw new BadRequestError52("Invalid _id format");
|
|
39360
39570
|
}
|
|
39361
39571
|
}
|
|
39362
39572
|
try {
|
|
39363
|
-
value.school = new
|
|
39573
|
+
value.school = new ObjectId31(value.school);
|
|
39364
39574
|
} catch (error2) {
|
|
39365
|
-
throw new
|
|
39575
|
+
throw new BadRequestError52("Invalid school format");
|
|
39366
39576
|
}
|
|
39367
39577
|
return {
|
|
39368
39578
|
_id: value._id ?? void 0,
|
|
@@ -39380,24 +39590,24 @@ function MBuildingUnit(value) {
|
|
|
39380
39590
|
const { error } = schemaBuildingUnit.validate(value);
|
|
39381
39591
|
if (error) {
|
|
39382
39592
|
logger28.info(`Building Unit Model: ${error.message}`);
|
|
39383
|
-
throw new
|
|
39593
|
+
throw new BadRequestError52(error.message);
|
|
39384
39594
|
}
|
|
39385
39595
|
if (value._id && typeof value._id === "string") {
|
|
39386
39596
|
try {
|
|
39387
|
-
value._id = new
|
|
39597
|
+
value._id = new ObjectId31(value._id);
|
|
39388
39598
|
} catch (error2) {
|
|
39389
|
-
throw new
|
|
39599
|
+
throw new BadRequestError52("Invalid ID");
|
|
39390
39600
|
}
|
|
39391
39601
|
}
|
|
39392
39602
|
try {
|
|
39393
|
-
value.school = new
|
|
39603
|
+
value.school = new ObjectId31(value.school);
|
|
39394
39604
|
} catch (error2) {
|
|
39395
|
-
throw new
|
|
39605
|
+
throw new BadRequestError52("Invalid school ID");
|
|
39396
39606
|
}
|
|
39397
39607
|
try {
|
|
39398
|
-
value.building = new
|
|
39608
|
+
value.building = new ObjectId31(value.building);
|
|
39399
39609
|
} catch (error2) {
|
|
39400
|
-
throw new
|
|
39610
|
+
throw new BadRequestError52("Invalid building ID");
|
|
39401
39611
|
}
|
|
39402
39612
|
return {
|
|
39403
39613
|
_id: value._id ?? void 0,
|
|
@@ -39423,15 +39633,15 @@ function MBuildingUnit(value) {
|
|
|
39423
39633
|
// src/resources/building/building.repository.ts
|
|
39424
39634
|
import {
|
|
39425
39635
|
AppError as AppError19,
|
|
39426
|
-
BadRequestError as
|
|
39636
|
+
BadRequestError as BadRequestError53,
|
|
39427
39637
|
InternalServerError as InternalServerError17,
|
|
39428
39638
|
logger as logger29,
|
|
39429
|
-
makeCacheKey as
|
|
39430
|
-
paginate as
|
|
39639
|
+
makeCacheKey as makeCacheKey17,
|
|
39640
|
+
paginate as paginate16,
|
|
39431
39641
|
useAtlas as useAtlas24,
|
|
39432
39642
|
useCache as useCache17
|
|
39433
39643
|
} from "@eeplatform/nodejs-utils";
|
|
39434
|
-
import { ObjectId as
|
|
39644
|
+
import { ObjectId as ObjectId32 } from "mongodb";
|
|
39435
39645
|
function useBuildingRepo() {
|
|
39436
39646
|
const db = useAtlas24.getDb();
|
|
39437
39647
|
if (!db) {
|
|
@@ -39467,7 +39677,7 @@ function useBuildingRepo() {
|
|
|
39467
39677
|
} else {
|
|
39468
39678
|
const isDuplicated = error.message.includes("duplicate");
|
|
39469
39679
|
if (isDuplicated) {
|
|
39470
|
-
throw new
|
|
39680
|
+
throw new BadRequestError53("Building already exists.");
|
|
39471
39681
|
}
|
|
39472
39682
|
throw new Error("Failed to create building.");
|
|
39473
39683
|
}
|
|
@@ -39475,9 +39685,9 @@ function useBuildingRepo() {
|
|
|
39475
39685
|
}
|
|
39476
39686
|
async function updateById(_id, value, session) {
|
|
39477
39687
|
try {
|
|
39478
|
-
_id = new
|
|
39688
|
+
_id = new ObjectId32(_id);
|
|
39479
39689
|
} catch (error) {
|
|
39480
|
-
throw new
|
|
39690
|
+
throw new BadRequestError53("Invalid ID.");
|
|
39481
39691
|
}
|
|
39482
39692
|
try {
|
|
39483
39693
|
const res = await collection.updateOne(
|
|
@@ -39517,9 +39727,9 @@ function useBuildingRepo() {
|
|
|
39517
39727
|
}
|
|
39518
39728
|
if (school) {
|
|
39519
39729
|
try {
|
|
39520
|
-
query.school = new
|
|
39730
|
+
query.school = new ObjectId32(school);
|
|
39521
39731
|
} catch (error) {
|
|
39522
|
-
throw new
|
|
39732
|
+
throw new BadRequestError53("Invalid school ID.");
|
|
39523
39733
|
}
|
|
39524
39734
|
}
|
|
39525
39735
|
const cacheParams = {
|
|
@@ -39533,7 +39743,7 @@ function useBuildingRepo() {
|
|
|
39533
39743
|
cacheParams.school = school;
|
|
39534
39744
|
if (status !== "active")
|
|
39535
39745
|
cacheParams.status = status;
|
|
39536
|
-
const cacheKey =
|
|
39746
|
+
const cacheKey = makeCacheKey17(namespace_collection, cacheParams);
|
|
39537
39747
|
logger29.log({
|
|
39538
39748
|
level: "info",
|
|
39539
39749
|
message: `Cache key for getAll buildings: ${cacheKey}`
|
|
@@ -39554,7 +39764,7 @@ function useBuildingRepo() {
|
|
|
39554
39764
|
{ $limit: limit }
|
|
39555
39765
|
]).toArray();
|
|
39556
39766
|
const length = await collection.countDocuments(query);
|
|
39557
|
-
const data =
|
|
39767
|
+
const data = paginate16(items, page, limit, length);
|
|
39558
39768
|
setCache(cacheKey, data, 600).then(() => {
|
|
39559
39769
|
logger29.log({
|
|
39560
39770
|
level: "info",
|
|
@@ -39574,11 +39784,11 @@ function useBuildingRepo() {
|
|
|
39574
39784
|
}
|
|
39575
39785
|
async function getById(_id) {
|
|
39576
39786
|
try {
|
|
39577
|
-
_id = new
|
|
39787
|
+
_id = new ObjectId32(_id);
|
|
39578
39788
|
} catch (error) {
|
|
39579
|
-
throw new
|
|
39789
|
+
throw new BadRequestError53("Invalid ID.");
|
|
39580
39790
|
}
|
|
39581
|
-
const cacheKey =
|
|
39791
|
+
const cacheKey = makeCacheKey17(namespace_collection, { _id: String(_id) });
|
|
39582
39792
|
try {
|
|
39583
39793
|
const cached = await getCache(cacheKey);
|
|
39584
39794
|
if (cached) {
|
|
@@ -39613,9 +39823,9 @@ function useBuildingRepo() {
|
|
|
39613
39823
|
}
|
|
39614
39824
|
async function deleteById(_id, session) {
|
|
39615
39825
|
try {
|
|
39616
|
-
_id = new
|
|
39826
|
+
_id = new ObjectId32(_id);
|
|
39617
39827
|
} catch (error) {
|
|
39618
|
-
throw new
|
|
39828
|
+
throw new BadRequestError53("Invalid ID.");
|
|
39619
39829
|
}
|
|
39620
39830
|
try {
|
|
39621
39831
|
const res = await collection.updateOne(
|
|
@@ -39661,7 +39871,7 @@ function useBuildingRepo() {
|
|
|
39661
39871
|
|
|
39662
39872
|
// src/resources/building/building.service.ts
|
|
39663
39873
|
import {
|
|
39664
|
-
BadRequestError as
|
|
39874
|
+
BadRequestError as BadRequestError55,
|
|
39665
39875
|
NotFoundError as NotFoundError3,
|
|
39666
39876
|
useAtlas as useAtlas26
|
|
39667
39877
|
} from "@eeplatform/nodejs-utils";
|
|
@@ -39669,15 +39879,15 @@ import {
|
|
|
39669
39879
|
// src/resources/building/building-unit.repository.ts
|
|
39670
39880
|
import {
|
|
39671
39881
|
AppError as AppError20,
|
|
39672
|
-
BadRequestError as
|
|
39882
|
+
BadRequestError as BadRequestError54,
|
|
39673
39883
|
InternalServerError as InternalServerError18,
|
|
39674
39884
|
logger as logger30,
|
|
39675
|
-
makeCacheKey as
|
|
39676
|
-
paginate as
|
|
39885
|
+
makeCacheKey as makeCacheKey18,
|
|
39886
|
+
paginate as paginate17,
|
|
39677
39887
|
useAtlas as useAtlas25,
|
|
39678
39888
|
useCache as useCache18
|
|
39679
39889
|
} from "@eeplatform/nodejs-utils";
|
|
39680
|
-
import { ObjectId as
|
|
39890
|
+
import { ObjectId as ObjectId33 } from "mongodb";
|
|
39681
39891
|
function useBuildingUnitRepo() {
|
|
39682
39892
|
const db = useAtlas25.getDb();
|
|
39683
39893
|
if (!db) {
|
|
@@ -39745,12 +39955,12 @@ function useBuildingUnitRepo() {
|
|
|
39745
39955
|
async function updateById(_id, value, session) {
|
|
39746
39956
|
const { error } = schemaUpdateOptions.validate(value);
|
|
39747
39957
|
if (error) {
|
|
39748
|
-
throw new
|
|
39958
|
+
throw new BadRequestError54(error.message);
|
|
39749
39959
|
}
|
|
39750
39960
|
try {
|
|
39751
|
-
_id = new
|
|
39961
|
+
_id = new ObjectId33(_id);
|
|
39752
39962
|
} catch (error2) {
|
|
39753
|
-
throw new
|
|
39963
|
+
throw new BadRequestError54("Invalid ID.");
|
|
39754
39964
|
}
|
|
39755
39965
|
try {
|
|
39756
39966
|
const res = await collection.updateOne(
|
|
@@ -39775,12 +39985,12 @@ function useBuildingUnitRepo() {
|
|
|
39775
39985
|
async function updateByBuildingId(building, value, session) {
|
|
39776
39986
|
const { error } = schemaUpdateOptions.validate(value);
|
|
39777
39987
|
if (error) {
|
|
39778
|
-
throw new
|
|
39988
|
+
throw new BadRequestError54(error.message);
|
|
39779
39989
|
}
|
|
39780
39990
|
try {
|
|
39781
|
-
building = new
|
|
39991
|
+
building = new ObjectId33(building);
|
|
39782
39992
|
} catch (error2) {
|
|
39783
|
-
throw new
|
|
39993
|
+
throw new BadRequestError54("Invalid building ID.");
|
|
39784
39994
|
}
|
|
39785
39995
|
try {
|
|
39786
39996
|
const res = await collection.updateMany(
|
|
@@ -39822,16 +40032,16 @@ function useBuildingUnitRepo() {
|
|
|
39822
40032
|
}
|
|
39823
40033
|
if (school) {
|
|
39824
40034
|
try {
|
|
39825
|
-
query.school = new
|
|
40035
|
+
query.school = new ObjectId33(school);
|
|
39826
40036
|
} catch (error) {
|
|
39827
|
-
throw new
|
|
40037
|
+
throw new BadRequestError54("Invalid school ID.");
|
|
39828
40038
|
}
|
|
39829
40039
|
}
|
|
39830
40040
|
if (building) {
|
|
39831
40041
|
try {
|
|
39832
|
-
query.building = new
|
|
40042
|
+
query.building = new ObjectId33(building);
|
|
39833
40043
|
} catch (error) {
|
|
39834
|
-
throw new
|
|
40044
|
+
throw new BadRequestError54("Invalid building ID.");
|
|
39835
40045
|
}
|
|
39836
40046
|
}
|
|
39837
40047
|
const cacheParams = {
|
|
@@ -39847,7 +40057,7 @@ function useBuildingUnitRepo() {
|
|
|
39847
40057
|
cacheParams.building = building;
|
|
39848
40058
|
if (status !== "active")
|
|
39849
40059
|
cacheParams.status = status;
|
|
39850
|
-
const cacheKey =
|
|
40060
|
+
const cacheKey = makeCacheKey18(namespace_collection, cacheParams);
|
|
39851
40061
|
logger30.log({
|
|
39852
40062
|
level: "info",
|
|
39853
40063
|
message: `Cache key for getAll building units: ${cacheKey}`
|
|
@@ -39868,7 +40078,7 @@ function useBuildingUnitRepo() {
|
|
|
39868
40078
|
{ $limit: limit }
|
|
39869
40079
|
]).toArray();
|
|
39870
40080
|
const length = await collection.countDocuments(query);
|
|
39871
|
-
const data =
|
|
40081
|
+
const data = paginate17(items, page, limit, length);
|
|
39872
40082
|
setCache(cacheKey, data, 600).then(() => {
|
|
39873
40083
|
logger30.log({
|
|
39874
40084
|
level: "info",
|
|
@@ -39888,11 +40098,11 @@ function useBuildingUnitRepo() {
|
|
|
39888
40098
|
}
|
|
39889
40099
|
async function getById(_id) {
|
|
39890
40100
|
try {
|
|
39891
|
-
_id = new
|
|
40101
|
+
_id = new ObjectId33(_id);
|
|
39892
40102
|
} catch (error) {
|
|
39893
|
-
throw new
|
|
40103
|
+
throw new BadRequestError54("Invalid ID.");
|
|
39894
40104
|
}
|
|
39895
|
-
const cacheKey =
|
|
40105
|
+
const cacheKey = makeCacheKey18(namespace_collection, { _id: String(_id) });
|
|
39896
40106
|
try {
|
|
39897
40107
|
const cached = await getCache(cacheKey);
|
|
39898
40108
|
if (cached) {
|
|
@@ -39907,7 +40117,7 @@ function useBuildingUnitRepo() {
|
|
|
39907
40117
|
deletedAt: { $in: ["", null] }
|
|
39908
40118
|
});
|
|
39909
40119
|
if (!result) {
|
|
39910
|
-
throw new
|
|
40120
|
+
throw new BadRequestError54("Building unit not found.");
|
|
39911
40121
|
}
|
|
39912
40122
|
setCache(cacheKey, result, 300).then(() => {
|
|
39913
40123
|
logger30.log({
|
|
@@ -39931,11 +40141,11 @@ function useBuildingUnitRepo() {
|
|
|
39931
40141
|
}
|
|
39932
40142
|
async function getByBuildingLevel(building, level) {
|
|
39933
40143
|
try {
|
|
39934
|
-
building = new
|
|
40144
|
+
building = new ObjectId33(building);
|
|
39935
40145
|
} catch (error) {
|
|
39936
|
-
throw new
|
|
40146
|
+
throw new BadRequestError54("Invalid building ID.");
|
|
39937
40147
|
}
|
|
39938
|
-
const cacheKey =
|
|
40148
|
+
const cacheKey = makeCacheKey18(namespace_collection, {
|
|
39939
40149
|
building: String(building),
|
|
39940
40150
|
level
|
|
39941
40151
|
});
|
|
@@ -39975,11 +40185,11 @@ function useBuildingUnitRepo() {
|
|
|
39975
40185
|
}
|
|
39976
40186
|
async function getByBuilding(building) {
|
|
39977
40187
|
try {
|
|
39978
|
-
building = new
|
|
40188
|
+
building = new ObjectId33(building);
|
|
39979
40189
|
} catch (error) {
|
|
39980
|
-
throw new
|
|
40190
|
+
throw new BadRequestError54("Invalid building ID.");
|
|
39981
40191
|
}
|
|
39982
|
-
const cacheKey =
|
|
40192
|
+
const cacheKey = makeCacheKey18(namespace_collection, {
|
|
39983
40193
|
building: String(building)
|
|
39984
40194
|
});
|
|
39985
40195
|
try {
|
|
@@ -40017,9 +40227,9 @@ function useBuildingUnitRepo() {
|
|
|
40017
40227
|
}
|
|
40018
40228
|
async function deleteById(_id, session) {
|
|
40019
40229
|
try {
|
|
40020
|
-
_id = new
|
|
40230
|
+
_id = new ObjectId33(_id);
|
|
40021
40231
|
} catch (error) {
|
|
40022
|
-
throw new
|
|
40232
|
+
throw new BadRequestError54("Invalid ID.");
|
|
40023
40233
|
}
|
|
40024
40234
|
try {
|
|
40025
40235
|
const res = await collection.updateOne(
|
|
@@ -40073,7 +40283,7 @@ function useBuildingService() {
|
|
|
40073
40283
|
if (data.levels < building.levels) {
|
|
40074
40284
|
const unit = await getByBuildingLevel(id, building.levels);
|
|
40075
40285
|
if (unit) {
|
|
40076
|
-
throw new
|
|
40286
|
+
throw new BadRequestError55(
|
|
40077
40287
|
"Cannot reduce floors, there are existing building units at higher floors."
|
|
40078
40288
|
);
|
|
40079
40289
|
}
|
|
@@ -40095,7 +40305,7 @@ function useBuildingService() {
|
|
|
40095
40305
|
async function deleteById(id) {
|
|
40096
40306
|
const building = await getByBuilding(id);
|
|
40097
40307
|
if (building) {
|
|
40098
|
-
throw new
|
|
40308
|
+
throw new BadRequestError55(
|
|
40099
40309
|
"Cannot delete building with existing room/facility. Please delete room/facility first."
|
|
40100
40310
|
);
|
|
40101
40311
|
}
|
|
@@ -40113,23 +40323,23 @@ function useBuildingService() {
|
|
|
40113
40323
|
}
|
|
40114
40324
|
|
|
40115
40325
|
// src/resources/building/building.controller.ts
|
|
40116
|
-
import { BadRequestError as
|
|
40117
|
-
import
|
|
40326
|
+
import { BadRequestError as BadRequestError56, logger as logger31 } from "@eeplatform/nodejs-utils";
|
|
40327
|
+
import Joi35 from "joi";
|
|
40118
40328
|
function useBuildingController() {
|
|
40119
40329
|
const { getAll: _getAll, getById: _getById, add: _add } = useBuildingRepo();
|
|
40120
40330
|
const { updateById: _updateById, deleteById: _deleteById } = useBuildingService();
|
|
40121
40331
|
async function createBuilding(req, res, next) {
|
|
40122
40332
|
const value = req.body;
|
|
40123
|
-
const validation =
|
|
40124
|
-
name:
|
|
40125
|
-
school:
|
|
40126
|
-
levels:
|
|
40127
|
-
serial:
|
|
40128
|
-
status:
|
|
40333
|
+
const validation = Joi35.object({
|
|
40334
|
+
name: Joi35.string().required(),
|
|
40335
|
+
school: Joi35.string().hex().required(),
|
|
40336
|
+
levels: Joi35.number().integer().min(1).required(),
|
|
40337
|
+
serial: Joi35.string().optional().allow("", null),
|
|
40338
|
+
status: Joi35.string().optional().allow("", null)
|
|
40129
40339
|
});
|
|
40130
40340
|
const { error } = validation.validate(value);
|
|
40131
40341
|
if (error) {
|
|
40132
|
-
next(new
|
|
40342
|
+
next(new BadRequestError56(error.message));
|
|
40133
40343
|
logger31.info(`Controller: ${error.message}`);
|
|
40134
40344
|
return;
|
|
40135
40345
|
}
|
|
@@ -40144,17 +40354,17 @@ function useBuildingController() {
|
|
|
40144
40354
|
async function updateById(req, res, next) {
|
|
40145
40355
|
const value = req.body;
|
|
40146
40356
|
const id = req.params.id ?? "";
|
|
40147
|
-
const validation =
|
|
40148
|
-
id:
|
|
40149
|
-
value:
|
|
40150
|
-
name:
|
|
40151
|
-
serial:
|
|
40152
|
-
levels:
|
|
40357
|
+
const validation = Joi35.object({
|
|
40358
|
+
id: Joi35.string().hex().required(),
|
|
40359
|
+
value: Joi35.object({
|
|
40360
|
+
name: Joi35.string().required(),
|
|
40361
|
+
serial: Joi35.string().optional().allow("", null),
|
|
40362
|
+
levels: Joi35.number().integer().min(1).required()
|
|
40153
40363
|
})
|
|
40154
40364
|
});
|
|
40155
40365
|
const { error } = validation.validate({ id, value });
|
|
40156
40366
|
if (error) {
|
|
40157
|
-
next(new
|
|
40367
|
+
next(new BadRequestError56(error.message));
|
|
40158
40368
|
logger31.info(`Controller: ${error.message}`);
|
|
40159
40369
|
return;
|
|
40160
40370
|
}
|
|
@@ -40168,16 +40378,16 @@ function useBuildingController() {
|
|
|
40168
40378
|
}
|
|
40169
40379
|
async function getAll(req, res, next) {
|
|
40170
40380
|
const query = req.query;
|
|
40171
|
-
const validation =
|
|
40172
|
-
page:
|
|
40173
|
-
limit:
|
|
40174
|
-
search:
|
|
40175
|
-
school:
|
|
40176
|
-
status:
|
|
40381
|
+
const validation = Joi35.object({
|
|
40382
|
+
page: Joi35.number().min(1).optional().allow("", null),
|
|
40383
|
+
limit: Joi35.number().min(1).optional().allow("", null),
|
|
40384
|
+
search: Joi35.string().optional().allow("", null),
|
|
40385
|
+
school: Joi35.string().hex().optional().allow("", null),
|
|
40386
|
+
status: Joi35.string().optional().allow("", null)
|
|
40177
40387
|
});
|
|
40178
40388
|
const { error } = validation.validate(query);
|
|
40179
40389
|
if (error) {
|
|
40180
|
-
next(new
|
|
40390
|
+
next(new BadRequestError56(error.message));
|
|
40181
40391
|
return;
|
|
40182
40392
|
}
|
|
40183
40393
|
const page = parseInt(req.query.page) ?? 1;
|
|
@@ -40211,12 +40421,12 @@ function useBuildingController() {
|
|
|
40211
40421
|
}
|
|
40212
40422
|
async function getById(req, res, next) {
|
|
40213
40423
|
const id = req.params.id;
|
|
40214
|
-
const validation =
|
|
40215
|
-
id:
|
|
40424
|
+
const validation = Joi35.object({
|
|
40425
|
+
id: Joi35.string().hex().required()
|
|
40216
40426
|
});
|
|
40217
40427
|
const { error } = validation.validate({ id });
|
|
40218
40428
|
if (error) {
|
|
40219
|
-
next(new
|
|
40429
|
+
next(new BadRequestError56(error.message));
|
|
40220
40430
|
return;
|
|
40221
40431
|
}
|
|
40222
40432
|
try {
|
|
@@ -40232,12 +40442,12 @@ function useBuildingController() {
|
|
|
40232
40442
|
}
|
|
40233
40443
|
async function deleteById(req, res, next) {
|
|
40234
40444
|
const id = req.params.id;
|
|
40235
|
-
const validation =
|
|
40236
|
-
id:
|
|
40445
|
+
const validation = Joi35.object({
|
|
40446
|
+
id: Joi35.string().hex().required()
|
|
40237
40447
|
});
|
|
40238
40448
|
const { error } = validation.validate({ id });
|
|
40239
40449
|
if (error) {
|
|
40240
|
-
next(new
|
|
40450
|
+
next(new BadRequestError56(error.message));
|
|
40241
40451
|
return;
|
|
40242
40452
|
}
|
|
40243
40453
|
try {
|
|
@@ -40289,8 +40499,8 @@ function useBuildingUnitService() {
|
|
|
40289
40499
|
}
|
|
40290
40500
|
|
|
40291
40501
|
// src/resources/building/building-unit.controller.ts
|
|
40292
|
-
import { BadRequestError as
|
|
40293
|
-
import
|
|
40502
|
+
import { BadRequestError as BadRequestError57 } from "@eeplatform/nodejs-utils";
|
|
40503
|
+
import Joi36 from "joi";
|
|
40294
40504
|
function useBuildingUnitController() {
|
|
40295
40505
|
const {
|
|
40296
40506
|
getAll: _getAll,
|
|
@@ -40301,27 +40511,27 @@ function useBuildingUnitController() {
|
|
|
40301
40511
|
const { add: _add } = useBuildingUnitService();
|
|
40302
40512
|
async function add(req, res, next) {
|
|
40303
40513
|
const data = req.body;
|
|
40304
|
-
const validation =
|
|
40305
|
-
building:
|
|
40306
|
-
school:
|
|
40307
|
-
name:
|
|
40308
|
-
building:
|
|
40309
|
-
buildingName:
|
|
40310
|
-
level:
|
|
40311
|
-
category:
|
|
40312
|
-
type:
|
|
40313
|
-
seating_capacity:
|
|
40314
|
-
standing_capacity:
|
|
40315
|
-
description:
|
|
40316
|
-
unit_of_measurement:
|
|
40317
|
-
area:
|
|
40318
|
-
status:
|
|
40514
|
+
const validation = Joi36.object({
|
|
40515
|
+
building: Joi36.object({
|
|
40516
|
+
school: Joi36.string().hex().required(),
|
|
40517
|
+
name: Joi36.string().optional().allow("", null),
|
|
40518
|
+
building: Joi36.string().hex().required(),
|
|
40519
|
+
buildingName: Joi36.string().optional().allow("", null),
|
|
40520
|
+
level: Joi36.number().integer().min(1).required(),
|
|
40521
|
+
category: Joi36.string().required(),
|
|
40522
|
+
type: Joi36.string().required(),
|
|
40523
|
+
seating_capacity: Joi36.number().integer().min(0).required(),
|
|
40524
|
+
standing_capacity: Joi36.number().integer().min(0).required(),
|
|
40525
|
+
description: Joi36.string().optional().allow("", null),
|
|
40526
|
+
unit_of_measurement: Joi36.string().valid("sqm").required(),
|
|
40527
|
+
area: Joi36.number().positive().required(),
|
|
40528
|
+
status: Joi36.string().optional().allow("", null)
|
|
40319
40529
|
}),
|
|
40320
|
-
qty:
|
|
40530
|
+
qty: Joi36.number().integer().min(1).max(20).optional().default(1)
|
|
40321
40531
|
});
|
|
40322
40532
|
const { error } = validation.validate(data);
|
|
40323
40533
|
if (error) {
|
|
40324
|
-
next(new
|
|
40534
|
+
next(new BadRequestError57(error.message));
|
|
40325
40535
|
return;
|
|
40326
40536
|
}
|
|
40327
40537
|
try {
|
|
@@ -40337,13 +40547,13 @@ function useBuildingUnitController() {
|
|
|
40337
40547
|
async function updateById(req, res, next) {
|
|
40338
40548
|
const data = req.body;
|
|
40339
40549
|
const id = req.params.id ?? "";
|
|
40340
|
-
const validation =
|
|
40341
|
-
id:
|
|
40550
|
+
const validation = Joi36.object({
|
|
40551
|
+
id: Joi36.string().hex().required(),
|
|
40342
40552
|
value: schemaUpdateOptions
|
|
40343
40553
|
});
|
|
40344
40554
|
const { error } = validation.validate({ id, value: data });
|
|
40345
40555
|
if (error) {
|
|
40346
|
-
next(new
|
|
40556
|
+
next(new BadRequestError57(error.message));
|
|
40347
40557
|
return;
|
|
40348
40558
|
}
|
|
40349
40559
|
try {
|
|
@@ -40358,17 +40568,17 @@ function useBuildingUnitController() {
|
|
|
40358
40568
|
}
|
|
40359
40569
|
async function getAll(req, res, next) {
|
|
40360
40570
|
const query = req.query;
|
|
40361
|
-
const validation =
|
|
40362
|
-
page:
|
|
40363
|
-
limit:
|
|
40364
|
-
search:
|
|
40365
|
-
school:
|
|
40366
|
-
building:
|
|
40367
|
-
status:
|
|
40571
|
+
const validation = Joi36.object({
|
|
40572
|
+
page: Joi36.number().min(1).optional().allow("", null),
|
|
40573
|
+
limit: Joi36.number().min(1).optional().allow("", null),
|
|
40574
|
+
search: Joi36.string().optional().allow("", null),
|
|
40575
|
+
school: Joi36.string().hex().optional().allow("", null),
|
|
40576
|
+
building: Joi36.string().hex().optional().allow("", null),
|
|
40577
|
+
status: Joi36.string().optional().allow("", null)
|
|
40368
40578
|
});
|
|
40369
40579
|
const { error } = validation.validate(query);
|
|
40370
40580
|
if (error) {
|
|
40371
|
-
next(new
|
|
40581
|
+
next(new BadRequestError57(error.message));
|
|
40372
40582
|
return;
|
|
40373
40583
|
}
|
|
40374
40584
|
const page = parseInt(req.query.page) ?? 1;
|
|
@@ -40404,12 +40614,12 @@ function useBuildingUnitController() {
|
|
|
40404
40614
|
}
|
|
40405
40615
|
async function getById(req, res, next) {
|
|
40406
40616
|
const id = req.params.id;
|
|
40407
|
-
const validation =
|
|
40408
|
-
id:
|
|
40617
|
+
const validation = Joi36.object({
|
|
40618
|
+
id: Joi36.string().hex().required()
|
|
40409
40619
|
});
|
|
40410
40620
|
const { error } = validation.validate({ id });
|
|
40411
40621
|
if (error) {
|
|
40412
|
-
next(new
|
|
40622
|
+
next(new BadRequestError57(error.message));
|
|
40413
40623
|
return;
|
|
40414
40624
|
}
|
|
40415
40625
|
try {
|
|
@@ -40425,12 +40635,12 @@ function useBuildingUnitController() {
|
|
|
40425
40635
|
}
|
|
40426
40636
|
async function deleteById(req, res, next) {
|
|
40427
40637
|
const id = req.params.id;
|
|
40428
|
-
const validation =
|
|
40429
|
-
id:
|
|
40638
|
+
const validation = Joi36.object({
|
|
40639
|
+
id: Joi36.string().hex().required()
|
|
40430
40640
|
});
|
|
40431
40641
|
const { error } = validation.validate({ id });
|
|
40432
40642
|
if (error) {
|
|
40433
|
-
next(new
|
|
40643
|
+
next(new BadRequestError57(error.message));
|
|
40434
40644
|
return;
|
|
40435
40645
|
}
|
|
40436
40646
|
try {
|
|
@@ -40451,42 +40661,42 @@ function useBuildingUnitController() {
|
|
|
40451
40661
|
}
|
|
40452
40662
|
|
|
40453
40663
|
// src/resources/personnel/personnel.model.ts
|
|
40454
|
-
import { BadRequestError as
|
|
40455
|
-
import
|
|
40456
|
-
import { ObjectId as
|
|
40457
|
-
var schemaPersonnel =
|
|
40458
|
-
_id:
|
|
40459
|
-
school:
|
|
40460
|
-
schoolName:
|
|
40461
|
-
firstName:
|
|
40462
|
-
lastName:
|
|
40463
|
-
middleName:
|
|
40464
|
-
suffix:
|
|
40465
|
-
title:
|
|
40466
|
-
classification:
|
|
40467
|
-
status:
|
|
40468
|
-
createdAt:
|
|
40469
|
-
updatedAt:
|
|
40470
|
-
deletedAt:
|
|
40664
|
+
import { BadRequestError as BadRequestError58, logger as logger32 } from "@eeplatform/nodejs-utils";
|
|
40665
|
+
import Joi37 from "joi";
|
|
40666
|
+
import { ObjectId as ObjectId34 } from "mongodb";
|
|
40667
|
+
var schemaPersonnel = Joi37.object({
|
|
40668
|
+
_id: Joi37.string().hex().optional().allow("", null),
|
|
40669
|
+
school: Joi37.string().hex().required(),
|
|
40670
|
+
schoolName: Joi37.string().optional().allow("", null),
|
|
40671
|
+
firstName: Joi37.string().required(),
|
|
40672
|
+
lastName: Joi37.string().required(),
|
|
40673
|
+
middleName: Joi37.string().optional().allow("", null),
|
|
40674
|
+
suffix: Joi37.string().optional().allow("", null),
|
|
40675
|
+
title: Joi37.string().optional().allow("", null),
|
|
40676
|
+
classification: Joi37.string().required(),
|
|
40677
|
+
status: Joi37.string().optional().allow("", null),
|
|
40678
|
+
createdAt: Joi37.date().optional().allow("", null),
|
|
40679
|
+
updatedAt: Joi37.date().optional().allow("", null),
|
|
40680
|
+
deletedAt: Joi37.date().optional().allow("", null)
|
|
40471
40681
|
});
|
|
40472
40682
|
function MPersonnel(value) {
|
|
40473
40683
|
const { error } = schemaPersonnel.validate(value);
|
|
40474
40684
|
if (error) {
|
|
40475
40685
|
logger32.info(`Personnel Model: ${error.message}`);
|
|
40476
|
-
throw new
|
|
40686
|
+
throw new BadRequestError58(error.message);
|
|
40477
40687
|
}
|
|
40478
40688
|
if (value._id && typeof value._id === "string") {
|
|
40479
40689
|
try {
|
|
40480
|
-
value._id = new
|
|
40690
|
+
value._id = new ObjectId34(value._id);
|
|
40481
40691
|
} catch (error2) {
|
|
40482
|
-
throw new
|
|
40692
|
+
throw new BadRequestError58("Invalid _id format");
|
|
40483
40693
|
}
|
|
40484
40694
|
}
|
|
40485
40695
|
if (value.school && typeof value.school === "string") {
|
|
40486
40696
|
try {
|
|
40487
|
-
value.school = new
|
|
40697
|
+
value.school = new ObjectId34(value.school);
|
|
40488
40698
|
} catch (error2) {
|
|
40489
|
-
throw new
|
|
40699
|
+
throw new BadRequestError58("Invalid school format");
|
|
40490
40700
|
}
|
|
40491
40701
|
}
|
|
40492
40702
|
if (!value.status) {
|
|
@@ -40512,15 +40722,15 @@ function MPersonnel(value) {
|
|
|
40512
40722
|
// src/resources/personnel/personnel.repository.ts
|
|
40513
40723
|
import {
|
|
40514
40724
|
AppError as AppError21,
|
|
40515
|
-
BadRequestError as
|
|
40725
|
+
BadRequestError as BadRequestError59,
|
|
40516
40726
|
InternalServerError as InternalServerError19,
|
|
40517
40727
|
logger as logger33,
|
|
40518
|
-
makeCacheKey as
|
|
40519
|
-
paginate as
|
|
40728
|
+
makeCacheKey as makeCacheKey19,
|
|
40729
|
+
paginate as paginate18,
|
|
40520
40730
|
useAtlas as useAtlas28,
|
|
40521
40731
|
useCache as useCache19
|
|
40522
40732
|
} from "@eeplatform/nodejs-utils";
|
|
40523
|
-
import { ObjectId as
|
|
40733
|
+
import { ObjectId as ObjectId35 } from "mongodb";
|
|
40524
40734
|
function usePersonnelRepo() {
|
|
40525
40735
|
const db = useAtlas28.getDb();
|
|
40526
40736
|
if (!db) {
|
|
@@ -40569,9 +40779,9 @@ function usePersonnelRepo() {
|
|
|
40569
40779
|
}
|
|
40570
40780
|
async function updateById(_id, value, session) {
|
|
40571
40781
|
try {
|
|
40572
|
-
_id = new
|
|
40782
|
+
_id = new ObjectId35(_id);
|
|
40573
40783
|
} catch (error) {
|
|
40574
|
-
throw new
|
|
40784
|
+
throw new BadRequestError59("Invalid ID.");
|
|
40575
40785
|
}
|
|
40576
40786
|
try {
|
|
40577
40787
|
const res = await collection.updateOne(
|
|
@@ -40617,13 +40827,13 @@ function usePersonnelRepo() {
|
|
|
40617
40827
|
}
|
|
40618
40828
|
if (school) {
|
|
40619
40829
|
try {
|
|
40620
|
-
query.school = new
|
|
40830
|
+
query.school = new ObjectId35(school);
|
|
40621
40831
|
} catch (error) {
|
|
40622
|
-
throw new
|
|
40832
|
+
throw new BadRequestError59("Invalid school ID.");
|
|
40623
40833
|
}
|
|
40624
40834
|
cacheParams.school = school;
|
|
40625
40835
|
}
|
|
40626
|
-
const cacheKey =
|
|
40836
|
+
const cacheKey = makeCacheKey19(namespace_collection, cacheParams);
|
|
40627
40837
|
logger33.log({
|
|
40628
40838
|
level: "info",
|
|
40629
40839
|
message: `Cache key for getAll personnel: ${cacheKey}`
|
|
@@ -40644,7 +40854,7 @@ function usePersonnelRepo() {
|
|
|
40644
40854
|
{ $limit: limit }
|
|
40645
40855
|
]).toArray();
|
|
40646
40856
|
const length = await collection.countDocuments(query);
|
|
40647
|
-
const data =
|
|
40857
|
+
const data = paginate18(items, page, limit, length);
|
|
40648
40858
|
setCache(cacheKey, data, 600).then(() => {
|
|
40649
40859
|
logger33.log({
|
|
40650
40860
|
level: "info",
|
|
@@ -40664,11 +40874,11 @@ function usePersonnelRepo() {
|
|
|
40664
40874
|
}
|
|
40665
40875
|
async function getById(_id) {
|
|
40666
40876
|
try {
|
|
40667
|
-
_id = new
|
|
40877
|
+
_id = new ObjectId35(_id);
|
|
40668
40878
|
} catch (error) {
|
|
40669
|
-
throw new
|
|
40879
|
+
throw new BadRequestError59("Invalid ID.");
|
|
40670
40880
|
}
|
|
40671
|
-
const cacheKey =
|
|
40881
|
+
const cacheKey = makeCacheKey19(namespace_collection, { _id: String(_id) });
|
|
40672
40882
|
try {
|
|
40673
40883
|
const cached = await getCache(cacheKey);
|
|
40674
40884
|
if (cached) {
|
|
@@ -40703,9 +40913,9 @@ function usePersonnelRepo() {
|
|
|
40703
40913
|
}
|
|
40704
40914
|
async function deleteById(_id, session) {
|
|
40705
40915
|
try {
|
|
40706
|
-
_id = new
|
|
40916
|
+
_id = new ObjectId35(_id);
|
|
40707
40917
|
} catch (error) {
|
|
40708
|
-
throw new
|
|
40918
|
+
throw new BadRequestError59("Invalid ID.");
|
|
40709
40919
|
}
|
|
40710
40920
|
try {
|
|
40711
40921
|
const res = await collection.updateOne(
|
|
@@ -40731,7 +40941,7 @@ function usePersonnelRepo() {
|
|
|
40731
40941
|
classification,
|
|
40732
40942
|
status: "active"
|
|
40733
40943
|
};
|
|
40734
|
-
const cacheKey =
|
|
40944
|
+
const cacheKey = makeCacheKey19(namespace_collection, { classification });
|
|
40735
40945
|
try {
|
|
40736
40946
|
const cached = await getCache(cacheKey);
|
|
40737
40947
|
if (cached) {
|
|
@@ -40790,8 +41000,8 @@ function usePersonnelRepo() {
|
|
|
40790
41000
|
}
|
|
40791
41001
|
|
|
40792
41002
|
// src/resources/personnel/personnel.controller.ts
|
|
40793
|
-
import { BadRequestError as
|
|
40794
|
-
import
|
|
41003
|
+
import { BadRequestError as BadRequestError60, logger as logger34 } from "@eeplatform/nodejs-utils";
|
|
41004
|
+
import Joi38 from "joi";
|
|
40795
41005
|
function usePersonnelController() {
|
|
40796
41006
|
const {
|
|
40797
41007
|
getAll: _getAll,
|
|
@@ -40805,7 +41015,7 @@ function usePersonnelController() {
|
|
|
40805
41015
|
const value = req.body;
|
|
40806
41016
|
const { error } = schemaPersonnel.validate(value);
|
|
40807
41017
|
if (error) {
|
|
40808
|
-
next(new
|
|
41018
|
+
next(new BadRequestError60(error.message));
|
|
40809
41019
|
logger34.info(`Controller: ${error.message}`);
|
|
40810
41020
|
return;
|
|
40811
41021
|
}
|
|
@@ -40820,19 +41030,19 @@ function usePersonnelController() {
|
|
|
40820
41030
|
async function updateById(req, res, next) {
|
|
40821
41031
|
const value = req.body;
|
|
40822
41032
|
const id = req.params.id ?? "";
|
|
40823
|
-
const validation =
|
|
40824
|
-
id:
|
|
40825
|
-
value:
|
|
40826
|
-
firstName:
|
|
40827
|
-
lastName:
|
|
40828
|
-
middleName:
|
|
40829
|
-
classification:
|
|
40830
|
-
status:
|
|
41033
|
+
const validation = Joi38.object({
|
|
41034
|
+
id: Joi38.string().hex().required(),
|
|
41035
|
+
value: Joi38.object({
|
|
41036
|
+
firstName: Joi38.string().optional(),
|
|
41037
|
+
lastName: Joi38.string().optional(),
|
|
41038
|
+
middleName: Joi38.string().optional().allow("", null),
|
|
41039
|
+
classification: Joi38.string().optional(),
|
|
41040
|
+
status: Joi38.string().optional()
|
|
40831
41041
|
}).min(1)
|
|
40832
41042
|
});
|
|
40833
41043
|
const { error } = validation.validate({ id, value });
|
|
40834
41044
|
if (error) {
|
|
40835
|
-
next(new
|
|
41045
|
+
next(new BadRequestError60(error.message));
|
|
40836
41046
|
logger34.info(`Controller: ${error.message}`);
|
|
40837
41047
|
return;
|
|
40838
41048
|
}
|
|
@@ -40846,16 +41056,16 @@ function usePersonnelController() {
|
|
|
40846
41056
|
}
|
|
40847
41057
|
async function getAll(req, res, next) {
|
|
40848
41058
|
const query = req.query;
|
|
40849
|
-
const validation =
|
|
40850
|
-
page:
|
|
40851
|
-
limit:
|
|
40852
|
-
search:
|
|
40853
|
-
status:
|
|
40854
|
-
classification:
|
|
41059
|
+
const validation = Joi38.object({
|
|
41060
|
+
page: Joi38.number().min(1).optional().allow("", null),
|
|
41061
|
+
limit: Joi38.number().min(1).optional().allow("", null),
|
|
41062
|
+
search: Joi38.string().optional().allow("", null),
|
|
41063
|
+
status: Joi38.string().optional().allow("", null),
|
|
41064
|
+
classification: Joi38.string().optional().allow("", null)
|
|
40855
41065
|
});
|
|
40856
41066
|
const { error } = validation.validate(query);
|
|
40857
41067
|
if (error) {
|
|
40858
|
-
next(new
|
|
41068
|
+
next(new BadRequestError60(error.message));
|
|
40859
41069
|
return;
|
|
40860
41070
|
}
|
|
40861
41071
|
const page = parseInt(req.query.page) ?? 1;
|
|
@@ -40887,23 +41097,23 @@ function usePersonnelController() {
|
|
|
40887
41097
|
}
|
|
40888
41098
|
async function getAllBySchool(req, res, next) {
|
|
40889
41099
|
const school = req.params.school;
|
|
40890
|
-
const schoolValidation =
|
|
41100
|
+
const schoolValidation = Joi38.string().hex().required();
|
|
40891
41101
|
const { error: schoolError } = schoolValidation.validate(school);
|
|
40892
41102
|
if (schoolError) {
|
|
40893
|
-
next(new
|
|
41103
|
+
next(new BadRequestError60(schoolError.message));
|
|
40894
41104
|
return;
|
|
40895
41105
|
}
|
|
40896
41106
|
const query = req.query;
|
|
40897
|
-
const validation =
|
|
40898
|
-
page:
|
|
40899
|
-
limit:
|
|
40900
|
-
search:
|
|
40901
|
-
status:
|
|
40902
|
-
classification:
|
|
41107
|
+
const validation = Joi38.object({
|
|
41108
|
+
page: Joi38.number().min(1).optional().allow("", null),
|
|
41109
|
+
limit: Joi38.number().min(1).optional().allow("", null),
|
|
41110
|
+
search: Joi38.string().optional().allow("", null),
|
|
41111
|
+
status: Joi38.string().optional().allow("", null),
|
|
41112
|
+
classification: Joi38.string().optional().allow("", null)
|
|
40903
41113
|
});
|
|
40904
41114
|
const { error } = validation.validate(query);
|
|
40905
41115
|
if (error) {
|
|
40906
|
-
next(new
|
|
41116
|
+
next(new BadRequestError60(error.message));
|
|
40907
41117
|
return;
|
|
40908
41118
|
}
|
|
40909
41119
|
const page = parseInt(req.query.page) ?? 1;
|
|
@@ -40936,12 +41146,12 @@ function usePersonnelController() {
|
|
|
40936
41146
|
}
|
|
40937
41147
|
async function getById(req, res, next) {
|
|
40938
41148
|
const id = req.params.id;
|
|
40939
|
-
const validation =
|
|
40940
|
-
id:
|
|
41149
|
+
const validation = Joi38.object({
|
|
41150
|
+
id: Joi38.string().hex().required()
|
|
40941
41151
|
});
|
|
40942
41152
|
const { error } = validation.validate({ id });
|
|
40943
41153
|
if (error) {
|
|
40944
|
-
next(new
|
|
41154
|
+
next(new BadRequestError60(error.message));
|
|
40945
41155
|
return;
|
|
40946
41156
|
}
|
|
40947
41157
|
try {
|
|
@@ -40957,12 +41167,12 @@ function usePersonnelController() {
|
|
|
40957
41167
|
}
|
|
40958
41168
|
async function deleteById(req, res, next) {
|
|
40959
41169
|
const id = req.params.id;
|
|
40960
|
-
const validation =
|
|
40961
|
-
id:
|
|
41170
|
+
const validation = Joi38.object({
|
|
41171
|
+
id: Joi38.string().hex().required()
|
|
40962
41172
|
});
|
|
40963
41173
|
const { error } = validation.validate({ id });
|
|
40964
41174
|
if (error) {
|
|
40965
|
-
next(new
|
|
41175
|
+
next(new BadRequestError60(error.message));
|
|
40966
41176
|
return;
|
|
40967
41177
|
}
|
|
40968
41178
|
try {
|
|
@@ -40978,12 +41188,12 @@ function usePersonnelController() {
|
|
|
40978
41188
|
}
|
|
40979
41189
|
async function getByClassification(req, res, next) {
|
|
40980
41190
|
const classification = req.params.classification;
|
|
40981
|
-
const validation =
|
|
40982
|
-
classification:
|
|
41191
|
+
const validation = Joi38.object({
|
|
41192
|
+
classification: Joi38.string().required()
|
|
40983
41193
|
});
|
|
40984
41194
|
const { error } = validation.validate({ classification });
|
|
40985
41195
|
if (error) {
|
|
40986
|
-
next(new
|
|
41196
|
+
next(new BadRequestError60(error.message));
|
|
40987
41197
|
return;
|
|
40988
41198
|
}
|
|
40989
41199
|
try {
|
|
@@ -41095,6 +41305,7 @@ export {
|
|
|
41095
41305
|
useSectionPresetController,
|
|
41096
41306
|
useSectionPresetRepo,
|
|
41097
41307
|
useSectionRepo,
|
|
41308
|
+
useSectionStudentController,
|
|
41098
41309
|
useSectionStudentRepo,
|
|
41099
41310
|
useSectionSubjectController,
|
|
41100
41311
|
useSectionSubjectRepo,
|