@eeplatform/core 1.5.0 → 1.5.2
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 +12 -0
- package/dist/index.d.ts +89 -25
- package/dist/index.js +645 -62
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +650 -62
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -11349,6 +11349,7 @@ __export(src_exports, {
|
|
|
11349
11349
|
MDivision: () => MDivision,
|
|
11350
11350
|
MEntity: () => MEntity,
|
|
11351
11351
|
MFile: () => MFile,
|
|
11352
|
+
MGradeLevel: () => MGradeLevel,
|
|
11352
11353
|
MMember: () => MMember,
|
|
11353
11354
|
MONGO_DB: () => MONGO_DB,
|
|
11354
11355
|
MONGO_URI: () => MONGO_URI,
|
|
@@ -11395,6 +11396,7 @@ __export(src_exports, {
|
|
|
11395
11396
|
schemaBuildingUnit: () => schemaBuildingUnit,
|
|
11396
11397
|
schemaCurriculum: () => schemaCurriculum,
|
|
11397
11398
|
schemaDivision: () => schemaDivision,
|
|
11399
|
+
schemaGradeLevel: () => schemaGradeLevel,
|
|
11398
11400
|
schemaOffice: () => schemaOffice,
|
|
11399
11401
|
schemaPlantilla: () => schemaPlantilla,
|
|
11400
11402
|
schemaRegion: () => schemaRegion,
|
|
@@ -11424,6 +11426,8 @@ __export(src_exports, {
|
|
|
11424
11426
|
useFileRepo: () => useFileRepo,
|
|
11425
11427
|
useFileService: () => useFileService,
|
|
11426
11428
|
useGitHubService: () => useGitHubService,
|
|
11429
|
+
useGradeLevelController: () => useGradeLevelController,
|
|
11430
|
+
useGradeLevelRepo: () => useGradeLevelRepo,
|
|
11427
11431
|
useInvoiceController: () => useInvoiceController,
|
|
11428
11432
|
useInvoiceModel: () => useInvoiceModel,
|
|
11429
11433
|
useInvoiceRepo: () => useInvoiceRepo,
|
|
@@ -31179,14 +31183,20 @@ var schemaCurriculum = import_joi45.default.object({
|
|
|
31179
31183
|
_id: import_joi45.default.string().hex().optional(),
|
|
31180
31184
|
school: import_joi45.default.string().hex().required(),
|
|
31181
31185
|
code: import_joi45.default.string().required(),
|
|
31182
|
-
|
|
31183
|
-
|
|
31184
|
-
|
|
31185
|
-
|
|
31186
|
-
|
|
31187
|
-
|
|
31188
|
-
|
|
31189
|
-
|
|
31186
|
+
effectiveSchoolYear: import_joi45.default.string().required(),
|
|
31187
|
+
maxTeachingHoursPerDay: import_joi45.default.number().integer().min(1).required(),
|
|
31188
|
+
subjects: import_joi45.default.array().items(
|
|
31189
|
+
import_joi45.default.object({
|
|
31190
|
+
educationLevel: import_joi45.default.string().required(),
|
|
31191
|
+
gradeLevel: import_joi45.default.string().required(),
|
|
31192
|
+
subjectCode: import_joi45.default.string().required(),
|
|
31193
|
+
subjectName: import_joi45.default.string().required(),
|
|
31194
|
+
subjectType: import_joi45.default.string().required(),
|
|
31195
|
+
sessionFrequency: import_joi45.default.number().integer().min(0).required(),
|
|
31196
|
+
sessionDuration: import_joi45.default.number().integer().min(0).required(),
|
|
31197
|
+
totalMinutesPerWeek: import_joi45.default.number().integer().min(0).required()
|
|
31198
|
+
})
|
|
31199
|
+
),
|
|
31190
31200
|
curriculumMemoRef: import_joi45.default.string().optional().allow("", null),
|
|
31191
31201
|
status: import_joi45.default.string().optional().allow("", null),
|
|
31192
31202
|
createdAt: import_joi45.default.date().optional().allow("", null),
|
|
@@ -31213,14 +31223,9 @@ function MCurriculum(value) {
|
|
|
31213
31223
|
_id: value._id ?? void 0,
|
|
31214
31224
|
school: value.school ?? "",
|
|
31215
31225
|
code: value.code ?? "",
|
|
31216
|
-
|
|
31217
|
-
|
|
31218
|
-
|
|
31219
|
-
subjectName: value.subjectName ?? "",
|
|
31220
|
-
subjectType: value.subjectType ?? "",
|
|
31221
|
-
sessionFrequency: value.sessionFrequency ?? 0,
|
|
31222
|
-
sessionDuration: value.sessionDuration ?? 0,
|
|
31223
|
-
totalMinutesPerWeek: value.totalMinutesPerWeek ?? 0,
|
|
31226
|
+
effectiveSchoolYear: value.effectiveSchoolYear ?? "",
|
|
31227
|
+
maxTeachingHoursPerDay: value.maxTeachingHoursPerDay ?? 0,
|
|
31228
|
+
subjects: value.subjects ?? [],
|
|
31224
31229
|
curriculumMemoRef: value.curriculumMemoRef ?? "",
|
|
31225
31230
|
status: value.status ?? "active",
|
|
31226
31231
|
createdAt: value.createdAt ?? /* @__PURE__ */ new Date(),
|
|
@@ -31246,10 +31251,16 @@ function useCurriculumRepo() {
|
|
|
31246
31251
|
async function createIndexes() {
|
|
31247
31252
|
try {
|
|
31248
31253
|
await collection.createIndexes([
|
|
31249
|
-
{
|
|
31250
|
-
|
|
31251
|
-
|
|
31252
|
-
|
|
31254
|
+
{
|
|
31255
|
+
key: {
|
|
31256
|
+
school: 1,
|
|
31257
|
+
code: 1,
|
|
31258
|
+
status: 1
|
|
31259
|
+
},
|
|
31260
|
+
unique: true,
|
|
31261
|
+
partialFilterExpression: { status: "active" },
|
|
31262
|
+
name: "unique_code_index"
|
|
31263
|
+
},
|
|
31253
31264
|
{ key: { status: 1 } }
|
|
31254
31265
|
]);
|
|
31255
31266
|
} catch (error) {
|
|
@@ -31309,9 +31320,6 @@ function useCurriculumRepo() {
|
|
|
31309
31320
|
page = 1,
|
|
31310
31321
|
limit = 10,
|
|
31311
31322
|
sort = {},
|
|
31312
|
-
educationLevel = "",
|
|
31313
|
-
gradeLevel = "",
|
|
31314
|
-
subjectCode = "",
|
|
31315
31323
|
status = "active"
|
|
31316
31324
|
} = {}) {
|
|
31317
31325
|
page = page > 0 ? page - 1 : 0;
|
|
@@ -31326,15 +31334,6 @@ function useCurriculumRepo() {
|
|
|
31326
31334
|
{ subjectCode: { $regex: search, $options: "i" } }
|
|
31327
31335
|
];
|
|
31328
31336
|
}
|
|
31329
|
-
if (educationLevel) {
|
|
31330
|
-
query.educationLevel = educationLevel;
|
|
31331
|
-
}
|
|
31332
|
-
if (gradeLevel) {
|
|
31333
|
-
query.gradeLevel = gradeLevel;
|
|
31334
|
-
}
|
|
31335
|
-
if (subjectCode) {
|
|
31336
|
-
query.subjectCode = subjectCode;
|
|
31337
|
-
}
|
|
31338
31337
|
const cacheParams = {
|
|
31339
31338
|
page,
|
|
31340
31339
|
limit,
|
|
@@ -31342,12 +31341,6 @@ function useCurriculumRepo() {
|
|
|
31342
31341
|
};
|
|
31343
31342
|
if (search)
|
|
31344
31343
|
cacheParams.search = search;
|
|
31345
|
-
if (educationLevel)
|
|
31346
|
-
cacheParams.educationLevel = educationLevel;
|
|
31347
|
-
if (gradeLevel)
|
|
31348
|
-
cacheParams.gradeLevel = gradeLevel;
|
|
31349
|
-
if (subjectCode)
|
|
31350
|
-
cacheParams.subjectCode = subjectCode;
|
|
31351
31344
|
if (status !== "active")
|
|
31352
31345
|
cacheParams.status = status;
|
|
31353
31346
|
const cacheKey = (0, import_nodejs_utils91.makeCacheKey)(namespace_collection, cacheParams);
|
|
@@ -31489,21 +31482,7 @@ function useCurriculumController() {
|
|
|
31489
31482
|
} = useCurriculumRepo();
|
|
31490
31483
|
async function add(req, res, next) {
|
|
31491
31484
|
const value = req.body;
|
|
31492
|
-
const
|
|
31493
|
-
code: import_joi46.default.string().required(),
|
|
31494
|
-
school: import_joi46.default.string().hex().required(),
|
|
31495
|
-
educationLevel: import_joi46.default.string().required(),
|
|
31496
|
-
gradeLevel: import_joi46.default.string().required(),
|
|
31497
|
-
subjectCode: import_joi46.default.string().required(),
|
|
31498
|
-
subjectName: import_joi46.default.string().required(),
|
|
31499
|
-
subjectType: import_joi46.default.string().required(),
|
|
31500
|
-
sessionFrequency: import_joi46.default.number().integer().min(0).required(),
|
|
31501
|
-
sessionDuration: import_joi46.default.number().integer().min(0).required(),
|
|
31502
|
-
totalMinutesPerWeek: import_joi46.default.number().integer().min(0).required(),
|
|
31503
|
-
curriculumMemoRef: import_joi46.default.string().optional().allow("", null),
|
|
31504
|
-
status: import_joi46.default.string().optional().allow("", null)
|
|
31505
|
-
});
|
|
31506
|
-
const { error } = validation.validate(value);
|
|
31485
|
+
const { error } = schemaCurriculum.validate(value);
|
|
31507
31486
|
if (error) {
|
|
31508
31487
|
next(new import_nodejs_utils92.BadRequestError(error.message));
|
|
31509
31488
|
import_nodejs_utils92.logger.info(`Controller: ${error.message}`);
|
|
@@ -31555,9 +31534,6 @@ function useCurriculumController() {
|
|
|
31555
31534
|
page: import_joi46.default.number().min(1).optional().allow("", null),
|
|
31556
31535
|
limit: import_joi46.default.number().min(1).optional().allow("", null),
|
|
31557
31536
|
search: import_joi46.default.string().optional().allow("", null),
|
|
31558
|
-
educationLevel: import_joi46.default.string().optional().allow("", null),
|
|
31559
|
-
gradeLevel: import_joi46.default.string().optional().allow("", null),
|
|
31560
|
-
subjectCode: import_joi46.default.string().optional().allow("", null),
|
|
31561
31537
|
status: import_joi46.default.string().optional().allow("", null)
|
|
31562
31538
|
});
|
|
31563
31539
|
const { error } = validation.validate(query);
|
|
@@ -31577,9 +31553,6 @@ function useCurriculumController() {
|
|
|
31577
31553
|
});
|
|
31578
31554
|
}
|
|
31579
31555
|
const status = req.query.status ?? "active";
|
|
31580
|
-
const educationLevel = req.query.educationLevel ?? "";
|
|
31581
|
-
const gradeLevel = req.query.gradeLevel ?? "";
|
|
31582
|
-
const subjectCode = req.query.subjectCode ?? "";
|
|
31583
31556
|
const search = req.query.search ?? "";
|
|
31584
31557
|
try {
|
|
31585
31558
|
const curriculums = await _getAll({
|
|
@@ -31587,9 +31560,6 @@ function useCurriculumController() {
|
|
|
31587
31560
|
limit,
|
|
31588
31561
|
sort: sortObj,
|
|
31589
31562
|
status,
|
|
31590
|
-
educationLevel,
|
|
31591
|
-
gradeLevel,
|
|
31592
|
-
subjectCode,
|
|
31593
31563
|
search
|
|
31594
31564
|
});
|
|
31595
31565
|
res.json(curriculums);
|
|
@@ -31648,6 +31618,615 @@ function useCurriculumController() {
|
|
|
31648
31618
|
deleteById
|
|
31649
31619
|
};
|
|
31650
31620
|
}
|
|
31621
|
+
|
|
31622
|
+
// src/models/grade-level.model.ts
|
|
31623
|
+
var import_nodejs_utils93 = require("@eeplatform/nodejs-utils");
|
|
31624
|
+
var import_joi47 = __toESM(require("joi"));
|
|
31625
|
+
var import_mongodb52 = require("mongodb");
|
|
31626
|
+
var schemaGradeLevel = import_joi47.default.object({
|
|
31627
|
+
_id: import_joi47.default.string().hex().optional(),
|
|
31628
|
+
school: import_joi47.default.string().hex().optional(),
|
|
31629
|
+
educationLevel: import_joi47.default.string().required(),
|
|
31630
|
+
gradeLevel: import_joi47.default.string().required(),
|
|
31631
|
+
teachingStyle: import_joi47.default.string().required(),
|
|
31632
|
+
maxNumberOfLearners: import_joi47.default.number().required(),
|
|
31633
|
+
defaultStartTime: import_joi47.default.string().optional().allow("", null),
|
|
31634
|
+
defaultEndTime: import_joi47.default.string().optional().allow("", null),
|
|
31635
|
+
status: import_joi47.default.string().optional().allow("", null),
|
|
31636
|
+
createdAt: import_joi47.default.date().optional().allow("", null),
|
|
31637
|
+
updatedAt: import_joi47.default.date().optional().allow("", null),
|
|
31638
|
+
deletedAt: import_joi47.default.date().optional().allow("", null),
|
|
31639
|
+
createdBy: import_joi47.default.string().optional().allow("", null),
|
|
31640
|
+
updatedBy: import_joi47.default.string().optional().allow("", null),
|
|
31641
|
+
deletedBy: import_joi47.default.string().optional().allow("", null)
|
|
31642
|
+
});
|
|
31643
|
+
function MGradeLevel(value) {
|
|
31644
|
+
const { error } = schemaGradeLevel.validate(value);
|
|
31645
|
+
if (error) {
|
|
31646
|
+
import_nodejs_utils93.logger.info(`Grade Level Model: ${error.message}`);
|
|
31647
|
+
throw new import_nodejs_utils93.BadRequestError(error.message);
|
|
31648
|
+
}
|
|
31649
|
+
if (value._id && typeof value._id === "string") {
|
|
31650
|
+
try {
|
|
31651
|
+
value._id = new import_mongodb52.ObjectId(value._id);
|
|
31652
|
+
} catch (error2) {
|
|
31653
|
+
throw new import_nodejs_utils93.BadRequestError("Invalid _id format");
|
|
31654
|
+
}
|
|
31655
|
+
}
|
|
31656
|
+
if (value.school && typeof value.school === "string") {
|
|
31657
|
+
try {
|
|
31658
|
+
value.school = new import_mongodb52.ObjectId(value.school);
|
|
31659
|
+
} catch (error2) {
|
|
31660
|
+
throw new import_nodejs_utils93.BadRequestError("Invalid school format");
|
|
31661
|
+
}
|
|
31662
|
+
}
|
|
31663
|
+
return {
|
|
31664
|
+
_id: value._id ?? void 0,
|
|
31665
|
+
school: value.school ?? void 0,
|
|
31666
|
+
educationLevel: value.educationLevel ?? "",
|
|
31667
|
+
gradeLevel: value.gradeLevel ?? "",
|
|
31668
|
+
teachingStyle: value.teachingStyle ?? "",
|
|
31669
|
+
maxNumberOfLearners: value.maxNumberOfLearners ?? 0,
|
|
31670
|
+
defaultStartTime: value.defaultStartTime ?? "",
|
|
31671
|
+
defaultEndTime: value.defaultEndTime ?? "",
|
|
31672
|
+
status: value.status ?? "active",
|
|
31673
|
+
createdAt: value.createdAt ?? /* @__PURE__ */ new Date(),
|
|
31674
|
+
updatedAt: value.updatedAt ?? "",
|
|
31675
|
+
deletedAt: value.deletedAt ?? "",
|
|
31676
|
+
createdBy: value.createdBy ?? "",
|
|
31677
|
+
updatedBy: value.updatedBy ?? "",
|
|
31678
|
+
deletedBy: value.deletedBy ?? ""
|
|
31679
|
+
};
|
|
31680
|
+
}
|
|
31681
|
+
|
|
31682
|
+
// src/repositories/grade-level.repository.ts
|
|
31683
|
+
var import_nodejs_utils94 = require("@eeplatform/nodejs-utils");
|
|
31684
|
+
var import_mongodb53 = require("mongodb");
|
|
31685
|
+
function useGradeLevelRepo() {
|
|
31686
|
+
const db = import_nodejs_utils94.useAtlas.getDb();
|
|
31687
|
+
if (!db) {
|
|
31688
|
+
throw new Error("Unable to connect to server.");
|
|
31689
|
+
}
|
|
31690
|
+
const namespace_collection = "school.grade-levels";
|
|
31691
|
+
const collection = db.collection(namespace_collection);
|
|
31692
|
+
const { getCache, setCache, delNamespace } = (0, import_nodejs_utils94.useCache)(namespace_collection);
|
|
31693
|
+
async function createIndexes() {
|
|
31694
|
+
try {
|
|
31695
|
+
await collection.createIndexes([
|
|
31696
|
+
{ key: { educationLevel: 1 } },
|
|
31697
|
+
{ key: { gradeLevel: 1 } },
|
|
31698
|
+
{ key: { teachingStyle: 1 } },
|
|
31699
|
+
{ key: { school: 1 } },
|
|
31700
|
+
{ key: { status: 1 } },
|
|
31701
|
+
{
|
|
31702
|
+
key: { educationLevel: 1, gradeLevel: 1, school: 1 },
|
|
31703
|
+
unique: true,
|
|
31704
|
+
partialFilterExpression: { status: { $in: ["active", "suspended"] } },
|
|
31705
|
+
name: "unique_grade_level_per_school_index"
|
|
31706
|
+
}
|
|
31707
|
+
]);
|
|
31708
|
+
} catch (error) {
|
|
31709
|
+
throw new Error("Failed to create index on grade levels.");
|
|
31710
|
+
}
|
|
31711
|
+
}
|
|
31712
|
+
async function add(value, session) {
|
|
31713
|
+
try {
|
|
31714
|
+
value = MGradeLevel(value);
|
|
31715
|
+
const res = await collection.insertOne(value, { session });
|
|
31716
|
+
delCachedData();
|
|
31717
|
+
return res.insertedId;
|
|
31718
|
+
} catch (error) {
|
|
31719
|
+
import_nodejs_utils94.logger.log({
|
|
31720
|
+
level: "error",
|
|
31721
|
+
message: error.message
|
|
31722
|
+
});
|
|
31723
|
+
if (error instanceof import_nodejs_utils94.AppError) {
|
|
31724
|
+
throw error;
|
|
31725
|
+
} else {
|
|
31726
|
+
const isDuplicated = error.message.includes("duplicate");
|
|
31727
|
+
if (isDuplicated) {
|
|
31728
|
+
throw new import_nodejs_utils94.BadRequestError(
|
|
31729
|
+
"Grade level already exists for this education level and school."
|
|
31730
|
+
);
|
|
31731
|
+
}
|
|
31732
|
+
throw new Error("Failed to create grade level.");
|
|
31733
|
+
}
|
|
31734
|
+
}
|
|
31735
|
+
}
|
|
31736
|
+
async function updateById(_id, value, session) {
|
|
31737
|
+
try {
|
|
31738
|
+
_id = new import_mongodb53.ObjectId(_id);
|
|
31739
|
+
} catch (error) {
|
|
31740
|
+
throw new import_nodejs_utils94.BadRequestError("Invalid ID.");
|
|
31741
|
+
}
|
|
31742
|
+
if (value.school && typeof value.school === "string") {
|
|
31743
|
+
try {
|
|
31744
|
+
value.school = new import_mongodb53.ObjectId(value.school);
|
|
31745
|
+
} catch (error) {
|
|
31746
|
+
throw new import_nodejs_utils94.BadRequestError("Invalid school ID format.");
|
|
31747
|
+
}
|
|
31748
|
+
}
|
|
31749
|
+
try {
|
|
31750
|
+
const res = await collection.updateOne(
|
|
31751
|
+
{ _id },
|
|
31752
|
+
{ $set: { ...value, updatedAt: /* @__PURE__ */ new Date() } },
|
|
31753
|
+
{ session }
|
|
31754
|
+
);
|
|
31755
|
+
delCachedData();
|
|
31756
|
+
return res;
|
|
31757
|
+
} catch (error) {
|
|
31758
|
+
import_nodejs_utils94.logger.log({
|
|
31759
|
+
level: "error",
|
|
31760
|
+
message: error.message
|
|
31761
|
+
});
|
|
31762
|
+
if (error instanceof import_nodejs_utils94.AppError) {
|
|
31763
|
+
throw error;
|
|
31764
|
+
} else {
|
|
31765
|
+
const isDuplicated = error.message.includes("duplicate");
|
|
31766
|
+
if (isDuplicated) {
|
|
31767
|
+
throw new import_nodejs_utils94.BadRequestError(
|
|
31768
|
+
"Grade level already exists for this education level and school."
|
|
31769
|
+
);
|
|
31770
|
+
}
|
|
31771
|
+
throw new Error("Failed to update grade level.");
|
|
31772
|
+
}
|
|
31773
|
+
}
|
|
31774
|
+
}
|
|
31775
|
+
async function getAll({
|
|
31776
|
+
search = "",
|
|
31777
|
+
page = 1,
|
|
31778
|
+
limit = 10,
|
|
31779
|
+
sort = {},
|
|
31780
|
+
educationLevel = "",
|
|
31781
|
+
gradeLevel = "",
|
|
31782
|
+
teachingStyle = "",
|
|
31783
|
+
school = "",
|
|
31784
|
+
status = "active"
|
|
31785
|
+
} = {}) {
|
|
31786
|
+
page = page > 0 ? page - 1 : 0;
|
|
31787
|
+
const query = {
|
|
31788
|
+
status
|
|
31789
|
+
};
|
|
31790
|
+
sort = Object.keys(sort).length > 0 ? sort : { _id: -1 };
|
|
31791
|
+
if (search) {
|
|
31792
|
+
query.$or = [
|
|
31793
|
+
{ educationLevel: { $regex: search, $options: "i" } },
|
|
31794
|
+
{ gradeLevel: { $regex: search, $options: "i" } },
|
|
31795
|
+
{ teachingStyle: { $regex: search, $options: "i" } }
|
|
31796
|
+
];
|
|
31797
|
+
}
|
|
31798
|
+
if (educationLevel) {
|
|
31799
|
+
query.educationLevel = educationLevel;
|
|
31800
|
+
}
|
|
31801
|
+
if (gradeLevel) {
|
|
31802
|
+
query.gradeLevel = gradeLevel;
|
|
31803
|
+
}
|
|
31804
|
+
if (teachingStyle) {
|
|
31805
|
+
query.teachingStyle = teachingStyle;
|
|
31806
|
+
}
|
|
31807
|
+
if (school) {
|
|
31808
|
+
try {
|
|
31809
|
+
query.school = new import_mongodb53.ObjectId(school);
|
|
31810
|
+
} catch (error) {
|
|
31811
|
+
throw new import_nodejs_utils94.BadRequestError("Invalid school ID format.");
|
|
31812
|
+
}
|
|
31813
|
+
}
|
|
31814
|
+
const cacheParams = {
|
|
31815
|
+
page,
|
|
31816
|
+
limit,
|
|
31817
|
+
sort: JSON.stringify(sort)
|
|
31818
|
+
};
|
|
31819
|
+
if (search)
|
|
31820
|
+
cacheParams.search = search;
|
|
31821
|
+
if (educationLevel)
|
|
31822
|
+
cacheParams.educationLevel = educationLevel;
|
|
31823
|
+
if (gradeLevel)
|
|
31824
|
+
cacheParams.gradeLevel = gradeLevel;
|
|
31825
|
+
if (teachingStyle)
|
|
31826
|
+
cacheParams.teachingStyle = teachingStyle;
|
|
31827
|
+
if (school)
|
|
31828
|
+
cacheParams.school = school;
|
|
31829
|
+
if (status !== "active")
|
|
31830
|
+
cacheParams.status = status;
|
|
31831
|
+
const cacheKey = (0, import_nodejs_utils94.makeCacheKey)(namespace_collection, cacheParams);
|
|
31832
|
+
import_nodejs_utils94.logger.log({
|
|
31833
|
+
level: "info",
|
|
31834
|
+
message: `Cache key for getAll grade levels: ${cacheKey}`
|
|
31835
|
+
});
|
|
31836
|
+
try {
|
|
31837
|
+
const cached = await getCache(cacheKey);
|
|
31838
|
+
if (cached) {
|
|
31839
|
+
import_nodejs_utils94.logger.log({
|
|
31840
|
+
level: "info",
|
|
31841
|
+
message: `Cache hit for getAll grade levels: ${cacheKey}`
|
|
31842
|
+
});
|
|
31843
|
+
return cached;
|
|
31844
|
+
}
|
|
31845
|
+
const items = await collection.aggregate([
|
|
31846
|
+
{ $match: query },
|
|
31847
|
+
{ $sort: sort },
|
|
31848
|
+
{ $skip: page * limit },
|
|
31849
|
+
{ $limit: limit },
|
|
31850
|
+
{
|
|
31851
|
+
$lookup: {
|
|
31852
|
+
from: "school.schools",
|
|
31853
|
+
localField: "school",
|
|
31854
|
+
foreignField: "_id",
|
|
31855
|
+
as: "schoolDetails"
|
|
31856
|
+
}
|
|
31857
|
+
},
|
|
31858
|
+
{
|
|
31859
|
+
$addFields: {
|
|
31860
|
+
schoolName: { $arrayElemAt: ["$schoolDetails.name", 0] }
|
|
31861
|
+
}
|
|
31862
|
+
},
|
|
31863
|
+
{
|
|
31864
|
+
$project: {
|
|
31865
|
+
schoolDetails: 0
|
|
31866
|
+
}
|
|
31867
|
+
}
|
|
31868
|
+
]).toArray();
|
|
31869
|
+
const length = await collection.countDocuments(query);
|
|
31870
|
+
const data = (0, import_nodejs_utils94.paginate)(items, page, limit, length);
|
|
31871
|
+
setCache(cacheKey, data, 600).then(() => {
|
|
31872
|
+
import_nodejs_utils94.logger.log({
|
|
31873
|
+
level: "info",
|
|
31874
|
+
message: `Cache set for getAll grade levels: ${cacheKey}`
|
|
31875
|
+
});
|
|
31876
|
+
}).catch((err) => {
|
|
31877
|
+
import_nodejs_utils94.logger.log({
|
|
31878
|
+
level: "error",
|
|
31879
|
+
message: `Failed to set cache for getAll grade levels: ${err.message}`
|
|
31880
|
+
});
|
|
31881
|
+
});
|
|
31882
|
+
return data;
|
|
31883
|
+
} catch (error) {
|
|
31884
|
+
import_nodejs_utils94.logger.log({ level: "error", message: `${error}` });
|
|
31885
|
+
throw error;
|
|
31886
|
+
}
|
|
31887
|
+
}
|
|
31888
|
+
async function getById(_id) {
|
|
31889
|
+
try {
|
|
31890
|
+
_id = new import_mongodb53.ObjectId(_id);
|
|
31891
|
+
} catch (error) {
|
|
31892
|
+
throw new import_nodejs_utils94.BadRequestError("Invalid ID.");
|
|
31893
|
+
}
|
|
31894
|
+
const cacheKey = (0, import_nodejs_utils94.makeCacheKey)(namespace_collection, { _id: String(_id) });
|
|
31895
|
+
try {
|
|
31896
|
+
const cached = await getCache(cacheKey);
|
|
31897
|
+
if (cached) {
|
|
31898
|
+
import_nodejs_utils94.logger.log({
|
|
31899
|
+
level: "info",
|
|
31900
|
+
message: `Cache hit for getById grade level: ${cacheKey}`
|
|
31901
|
+
});
|
|
31902
|
+
return cached;
|
|
31903
|
+
}
|
|
31904
|
+
const result = await collection.aggregate([
|
|
31905
|
+
{ $match: { _id } },
|
|
31906
|
+
{
|
|
31907
|
+
$lookup: {
|
|
31908
|
+
from: "school.schools",
|
|
31909
|
+
localField: "school",
|
|
31910
|
+
foreignField: "_id",
|
|
31911
|
+
as: "schoolDetails"
|
|
31912
|
+
}
|
|
31913
|
+
},
|
|
31914
|
+
{
|
|
31915
|
+
$addFields: {
|
|
31916
|
+
schoolName: { $arrayElemAt: ["$schoolDetails.name", 0] }
|
|
31917
|
+
}
|
|
31918
|
+
},
|
|
31919
|
+
{
|
|
31920
|
+
$project: {
|
|
31921
|
+
schoolDetails: 0
|
|
31922
|
+
}
|
|
31923
|
+
}
|
|
31924
|
+
]).toArray();
|
|
31925
|
+
const gradeLevel = result[0] || null;
|
|
31926
|
+
setCache(cacheKey, gradeLevel, 300).then(() => {
|
|
31927
|
+
import_nodejs_utils94.logger.log({
|
|
31928
|
+
level: "info",
|
|
31929
|
+
message: `Cache set for grade level by id: ${cacheKey}`
|
|
31930
|
+
});
|
|
31931
|
+
}).catch((err) => {
|
|
31932
|
+
import_nodejs_utils94.logger.log({
|
|
31933
|
+
level: "error",
|
|
31934
|
+
message: `Failed to set cache for grade level by id: ${err.message}`
|
|
31935
|
+
});
|
|
31936
|
+
});
|
|
31937
|
+
return gradeLevel;
|
|
31938
|
+
} catch (error) {
|
|
31939
|
+
if (error instanceof import_nodejs_utils94.AppError) {
|
|
31940
|
+
throw error;
|
|
31941
|
+
} else {
|
|
31942
|
+
throw new import_nodejs_utils94.InternalServerError("Failed to get grade level.");
|
|
31943
|
+
}
|
|
31944
|
+
}
|
|
31945
|
+
}
|
|
31946
|
+
async function deleteById(_id, session) {
|
|
31947
|
+
try {
|
|
31948
|
+
_id = new import_mongodb53.ObjectId(_id);
|
|
31949
|
+
} catch (error) {
|
|
31950
|
+
throw new import_nodejs_utils94.BadRequestError("Invalid ID.");
|
|
31951
|
+
}
|
|
31952
|
+
try {
|
|
31953
|
+
const res = await collection.updateOne(
|
|
31954
|
+
{ _id },
|
|
31955
|
+
{ $set: { status: "deleted", deletedAt: /* @__PURE__ */ new Date() } },
|
|
31956
|
+
{ session }
|
|
31957
|
+
);
|
|
31958
|
+
delCachedData();
|
|
31959
|
+
return res;
|
|
31960
|
+
} catch (error) {
|
|
31961
|
+
import_nodejs_utils94.logger.log({
|
|
31962
|
+
level: "error",
|
|
31963
|
+
message: error.message
|
|
31964
|
+
});
|
|
31965
|
+
if (error instanceof import_nodejs_utils94.AppError) {
|
|
31966
|
+
throw error;
|
|
31967
|
+
} else {
|
|
31968
|
+
throw new import_nodejs_utils94.InternalServerError("Failed to delete grade level.");
|
|
31969
|
+
}
|
|
31970
|
+
}
|
|
31971
|
+
}
|
|
31972
|
+
async function getByEducationLevel(educationLevel, school) {
|
|
31973
|
+
const query = {
|
|
31974
|
+
educationLevel,
|
|
31975
|
+
status: "active"
|
|
31976
|
+
};
|
|
31977
|
+
if (school) {
|
|
31978
|
+
try {
|
|
31979
|
+
query.school = new import_mongodb53.ObjectId(school);
|
|
31980
|
+
} catch (error) {
|
|
31981
|
+
throw new import_nodejs_utils94.BadRequestError("Invalid school ID format.");
|
|
31982
|
+
}
|
|
31983
|
+
}
|
|
31984
|
+
const cacheKey = (0, import_nodejs_utils94.makeCacheKey)(namespace_collection, {
|
|
31985
|
+
educationLevel,
|
|
31986
|
+
school: school || "all",
|
|
31987
|
+
method: "getByEducationLevel"
|
|
31988
|
+
});
|
|
31989
|
+
try {
|
|
31990
|
+
const cached = await getCache(cacheKey);
|
|
31991
|
+
if (cached) {
|
|
31992
|
+
import_nodejs_utils94.logger.log({
|
|
31993
|
+
level: "info",
|
|
31994
|
+
message: `Cache hit for getByEducationLevel: ${cacheKey}`
|
|
31995
|
+
});
|
|
31996
|
+
return cached;
|
|
31997
|
+
}
|
|
31998
|
+
const result = await collection.find(query).sort({ gradeLevel: 1 }).toArray();
|
|
31999
|
+
setCache(cacheKey, result, 300).then(() => {
|
|
32000
|
+
import_nodejs_utils94.logger.log({
|
|
32001
|
+
level: "info",
|
|
32002
|
+
message: `Cache set for getByEducationLevel: ${cacheKey}`
|
|
32003
|
+
});
|
|
32004
|
+
}).catch((err) => {
|
|
32005
|
+
import_nodejs_utils94.logger.log({
|
|
32006
|
+
level: "error",
|
|
32007
|
+
message: `Failed to set cache for getByEducationLevel: ${err.message}`
|
|
32008
|
+
});
|
|
32009
|
+
});
|
|
32010
|
+
return result;
|
|
32011
|
+
} catch (error) {
|
|
32012
|
+
import_nodejs_utils94.logger.log({ level: "error", message: `${error}` });
|
|
32013
|
+
throw error;
|
|
32014
|
+
}
|
|
32015
|
+
}
|
|
32016
|
+
function delCachedData() {
|
|
32017
|
+
delNamespace().then(() => {
|
|
32018
|
+
import_nodejs_utils94.logger.log({
|
|
32019
|
+
level: "info",
|
|
32020
|
+
message: `Cache namespace cleared for ${namespace_collection}`
|
|
32021
|
+
});
|
|
32022
|
+
}).catch((err) => {
|
|
32023
|
+
import_nodejs_utils94.logger.log({
|
|
32024
|
+
level: "error",
|
|
32025
|
+
message: `Failed to clear cache namespace for ${namespace_collection}: ${err.message}`
|
|
32026
|
+
});
|
|
32027
|
+
});
|
|
32028
|
+
}
|
|
32029
|
+
return {
|
|
32030
|
+
createIndexes,
|
|
32031
|
+
add,
|
|
32032
|
+
getAll,
|
|
32033
|
+
getById,
|
|
32034
|
+
updateById,
|
|
32035
|
+
deleteById,
|
|
32036
|
+
getByEducationLevel
|
|
32037
|
+
};
|
|
32038
|
+
}
|
|
32039
|
+
|
|
32040
|
+
// src/controllers/grade-level.controller.ts
|
|
32041
|
+
var import_nodejs_utils95 = require("@eeplatform/nodejs-utils");
|
|
32042
|
+
var import_joi48 = __toESM(require("joi"));
|
|
32043
|
+
function useGradeLevelController() {
|
|
32044
|
+
const {
|
|
32045
|
+
getAll: _getAll,
|
|
32046
|
+
getById: _getById,
|
|
32047
|
+
add: _add,
|
|
32048
|
+
updateById: _updateById,
|
|
32049
|
+
deleteById: _deleteById,
|
|
32050
|
+
getByEducationLevel: _getByEducationLevel
|
|
32051
|
+
} = useGradeLevelRepo();
|
|
32052
|
+
async function add(req, res, next) {
|
|
32053
|
+
const value = req.body;
|
|
32054
|
+
const { error } = schemaGradeLevel.validate(value);
|
|
32055
|
+
if (error) {
|
|
32056
|
+
next(new import_nodejs_utils95.BadRequestError(error.message));
|
|
32057
|
+
import_nodejs_utils95.logger.info(`Controller: ${error.message}`);
|
|
32058
|
+
return;
|
|
32059
|
+
}
|
|
32060
|
+
try {
|
|
32061
|
+
const result = await _add(value);
|
|
32062
|
+
res.json({
|
|
32063
|
+
message: "Successfully created grade level.",
|
|
32064
|
+
data: { _id: result }
|
|
32065
|
+
});
|
|
32066
|
+
return;
|
|
32067
|
+
} catch (error2) {
|
|
32068
|
+
next(error2);
|
|
32069
|
+
}
|
|
32070
|
+
}
|
|
32071
|
+
async function updateById(req, res, next) {
|
|
32072
|
+
const value = req.body;
|
|
32073
|
+
const id = req.params.id ?? "";
|
|
32074
|
+
const validation = import_joi48.default.object({
|
|
32075
|
+
id: import_joi48.default.string().hex().required(),
|
|
32076
|
+
value: import_joi48.default.object({
|
|
32077
|
+
school: import_joi48.default.string().hex().optional(),
|
|
32078
|
+
educationLevel: import_joi48.default.string().optional(),
|
|
32079
|
+
gradeLevel: import_joi48.default.string().optional(),
|
|
32080
|
+
teachingStyle: import_joi48.default.string().optional(),
|
|
32081
|
+
maxTeachingHoursPerDay: import_joi48.default.number().integer().min(0).optional(),
|
|
32082
|
+
maxTeachingHoursPerWeek: import_joi48.default.number().integer().min(0).optional(),
|
|
32083
|
+
defaultStartTime: import_joi48.default.string().optional().allow("", null),
|
|
32084
|
+
defaultEndTime: import_joi48.default.string().optional().allow("", null)
|
|
32085
|
+
}).min(1)
|
|
32086
|
+
});
|
|
32087
|
+
const { error } = validation.validate({ id, value });
|
|
32088
|
+
if (error) {
|
|
32089
|
+
next(new import_nodejs_utils95.BadRequestError(error.message));
|
|
32090
|
+
import_nodejs_utils95.logger.info(`Controller: ${error.message}`);
|
|
32091
|
+
return;
|
|
32092
|
+
}
|
|
32093
|
+
try {
|
|
32094
|
+
const result = await _updateById(id, value);
|
|
32095
|
+
res.json({
|
|
32096
|
+
message: "Successfully updated grade level.",
|
|
32097
|
+
data: result
|
|
32098
|
+
});
|
|
32099
|
+
return;
|
|
32100
|
+
} catch (error2) {
|
|
32101
|
+
next(error2);
|
|
32102
|
+
}
|
|
32103
|
+
}
|
|
32104
|
+
async function getAll(req, res, next) {
|
|
32105
|
+
const query = req.query;
|
|
32106
|
+
const validation = import_joi48.default.object({
|
|
32107
|
+
page: import_joi48.default.number().min(1).optional().allow("", null),
|
|
32108
|
+
limit: import_joi48.default.number().min(1).optional().allow("", null),
|
|
32109
|
+
search: import_joi48.default.string().optional().allow("", null),
|
|
32110
|
+
educationLevel: import_joi48.default.string().optional().allow("", null),
|
|
32111
|
+
gradeLevel: import_joi48.default.string().optional().allow("", null),
|
|
32112
|
+
teachingStyle: import_joi48.default.string().optional().allow("", null),
|
|
32113
|
+
school: import_joi48.default.string().hex().optional().allow("", null),
|
|
32114
|
+
status: import_joi48.default.string().optional().allow("", null)
|
|
32115
|
+
});
|
|
32116
|
+
const { error } = validation.validate(query);
|
|
32117
|
+
if (error) {
|
|
32118
|
+
next(new import_nodejs_utils95.BadRequestError(error.message));
|
|
32119
|
+
return;
|
|
32120
|
+
}
|
|
32121
|
+
const page = parseInt(req.query.page) ?? 1;
|
|
32122
|
+
let limit = parseInt(req.query.limit) ?? 20;
|
|
32123
|
+
limit = isNaN(limit) ? 20 : limit;
|
|
32124
|
+
const sort = req.query.sort ? String(req.query.sort).split(",") : "";
|
|
32125
|
+
const sortOrder = req.query.sortOrder ? String(req.query.sortOrder).split(",") : "";
|
|
32126
|
+
const sortObj = {};
|
|
32127
|
+
if (sort && Array.isArray(sort) && sort.length && sortOrder && Array.isArray(sortOrder) && sortOrder.length) {
|
|
32128
|
+
sort.forEach((field, index) => {
|
|
32129
|
+
sortObj[field] = sortOrder[index] === "desc" ? -1 : 1;
|
|
32130
|
+
});
|
|
32131
|
+
}
|
|
32132
|
+
const status = req.query.status ?? "active";
|
|
32133
|
+
const educationLevel = req.query.educationLevel ?? "";
|
|
32134
|
+
const gradeLevel = req.query.gradeLevel ?? "";
|
|
32135
|
+
const teachingStyle = req.query.teachingStyle ?? "";
|
|
32136
|
+
const school = req.query.school ?? "";
|
|
32137
|
+
const search = req.query.search ?? "";
|
|
32138
|
+
try {
|
|
32139
|
+
const gradeLevels = await _getAll({
|
|
32140
|
+
page,
|
|
32141
|
+
limit,
|
|
32142
|
+
sort: sortObj,
|
|
32143
|
+
status,
|
|
32144
|
+
educationLevel,
|
|
32145
|
+
gradeLevel,
|
|
32146
|
+
teachingStyle,
|
|
32147
|
+
school,
|
|
32148
|
+
search
|
|
32149
|
+
});
|
|
32150
|
+
res.json(gradeLevels);
|
|
32151
|
+
return;
|
|
32152
|
+
} catch (error2) {
|
|
32153
|
+
next(error2);
|
|
32154
|
+
}
|
|
32155
|
+
}
|
|
32156
|
+
async function getById(req, res, next) {
|
|
32157
|
+
const id = req.params.id;
|
|
32158
|
+
const validation = import_joi48.default.object({
|
|
32159
|
+
id: import_joi48.default.string().hex().required()
|
|
32160
|
+
});
|
|
32161
|
+
const { error } = validation.validate({ id });
|
|
32162
|
+
if (error) {
|
|
32163
|
+
next(new import_nodejs_utils95.BadRequestError(error.message));
|
|
32164
|
+
return;
|
|
32165
|
+
}
|
|
32166
|
+
try {
|
|
32167
|
+
const gradeLevel = await _getById(id);
|
|
32168
|
+
res.json({
|
|
32169
|
+
message: "Successfully retrieved grade level.",
|
|
32170
|
+
data: { gradeLevel }
|
|
32171
|
+
});
|
|
32172
|
+
return;
|
|
32173
|
+
} catch (error2) {
|
|
32174
|
+
next(error2);
|
|
32175
|
+
}
|
|
32176
|
+
}
|
|
32177
|
+
async function deleteById(req, res, next) {
|
|
32178
|
+
const id = req.params.id;
|
|
32179
|
+
const validation = import_joi48.default.object({
|
|
32180
|
+
id: import_joi48.default.string().hex().required()
|
|
32181
|
+
});
|
|
32182
|
+
const { error } = validation.validate({ id });
|
|
32183
|
+
if (error) {
|
|
32184
|
+
next(new import_nodejs_utils95.BadRequestError(error.message));
|
|
32185
|
+
return;
|
|
32186
|
+
}
|
|
32187
|
+
try {
|
|
32188
|
+
const result = await _deleteById(id);
|
|
32189
|
+
res.json({
|
|
32190
|
+
message: "Successfully deleted grade level.",
|
|
32191
|
+
data: result
|
|
32192
|
+
});
|
|
32193
|
+
return;
|
|
32194
|
+
} catch (error2) {
|
|
32195
|
+
next(error2);
|
|
32196
|
+
}
|
|
32197
|
+
}
|
|
32198
|
+
async function getByEducationLevel(req, res, next) {
|
|
32199
|
+
const educationLevel = req.params.educationLevel;
|
|
32200
|
+
const school = req.query.school;
|
|
32201
|
+
const validation = import_joi48.default.object({
|
|
32202
|
+
educationLevel: import_joi48.default.string().required(),
|
|
32203
|
+
school: import_joi48.default.string().hex().optional().allow("", null)
|
|
32204
|
+
});
|
|
32205
|
+
const { error } = validation.validate({ educationLevel, school });
|
|
32206
|
+
if (error) {
|
|
32207
|
+
next(new import_nodejs_utils95.BadRequestError(error.message));
|
|
32208
|
+
return;
|
|
32209
|
+
}
|
|
32210
|
+
try {
|
|
32211
|
+
const gradeLevels = await _getByEducationLevel(educationLevel, school);
|
|
32212
|
+
res.json({
|
|
32213
|
+
message: "Successfully retrieved grade levels by education level.",
|
|
32214
|
+
data: { gradeLevels }
|
|
32215
|
+
});
|
|
32216
|
+
return;
|
|
32217
|
+
} catch (error2) {
|
|
32218
|
+
next(error2);
|
|
32219
|
+
}
|
|
32220
|
+
}
|
|
32221
|
+
return {
|
|
32222
|
+
add,
|
|
32223
|
+
getAll,
|
|
32224
|
+
getById,
|
|
32225
|
+
updateById,
|
|
32226
|
+
deleteById,
|
|
32227
|
+
getByEducationLevel
|
|
32228
|
+
};
|
|
32229
|
+
}
|
|
31651
32230
|
// Annotate the CommonJS export names for ESM import in node:
|
|
31652
32231
|
0 && (module.exports = {
|
|
31653
32232
|
ACCESS_TOKEN_EXPIRY,
|
|
@@ -31674,6 +32253,7 @@ function useCurriculumController() {
|
|
|
31674
32253
|
MDivision,
|
|
31675
32254
|
MEntity,
|
|
31676
32255
|
MFile,
|
|
32256
|
+
MGradeLevel,
|
|
31677
32257
|
MMember,
|
|
31678
32258
|
MONGO_DB,
|
|
31679
32259
|
MONGO_URI,
|
|
@@ -31720,6 +32300,7 @@ function useCurriculumController() {
|
|
|
31720
32300
|
schemaBuildingUnit,
|
|
31721
32301
|
schemaCurriculum,
|
|
31722
32302
|
schemaDivision,
|
|
32303
|
+
schemaGradeLevel,
|
|
31723
32304
|
schemaOffice,
|
|
31724
32305
|
schemaPlantilla,
|
|
31725
32306
|
schemaRegion,
|
|
@@ -31749,6 +32330,8 @@ function useCurriculumController() {
|
|
|
31749
32330
|
useFileRepo,
|
|
31750
32331
|
useFileService,
|
|
31751
32332
|
useGitHubService,
|
|
32333
|
+
useGradeLevelController,
|
|
32334
|
+
useGradeLevelRepo,
|
|
31752
32335
|
useInvoiceController,
|
|
31753
32336
|
useInvoiceModel,
|
|
31754
32337
|
useInvoiceRepo,
|