@eeplatform/basic-edu 1.10.7 → 1.10.8
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/dist/index.d.ts +9 -3
- package/dist/index.js +104 -34
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +104 -34
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -40788,7 +40788,7 @@ function useSectionRepo() {
|
|
|
40788
40788
|
school = "",
|
|
40789
40789
|
schoolYear = "",
|
|
40790
40790
|
gradeLevel = ""
|
|
40791
|
-
} = {}) {
|
|
40791
|
+
} = {}, session) {
|
|
40792
40792
|
page = page > 0 ? page - 1 : 0;
|
|
40793
40793
|
const query = {
|
|
40794
40794
|
deletedAt: { $in: ["", null] },
|
|
@@ -40835,12 +40835,15 @@ function useSectionRepo() {
|
|
|
40835
40835
|
});
|
|
40836
40836
|
return cached;
|
|
40837
40837
|
}
|
|
40838
|
-
const items = await collection.aggregate(
|
|
40839
|
-
|
|
40840
|
-
|
|
40841
|
-
|
|
40842
|
-
|
|
40843
|
-
|
|
40838
|
+
const items = await collection.aggregate(
|
|
40839
|
+
[
|
|
40840
|
+
{ $match: query },
|
|
40841
|
+
{ $sort: sort },
|
|
40842
|
+
{ $skip: page * limit },
|
|
40843
|
+
{ $limit: limit }
|
|
40844
|
+
],
|
|
40845
|
+
{ session }
|
|
40846
|
+
).toArray();
|
|
40844
40847
|
const length = await collection.countDocuments(query);
|
|
40845
40848
|
const data = paginate17(items, page, limit, length);
|
|
40846
40849
|
setCache(cacheKey, data, 600).then(() => {
|
|
@@ -40905,7 +40908,10 @@ function useSectionRepo() {
|
|
|
40905
40908
|
}
|
|
40906
40909
|
async function getSection(options) {
|
|
40907
40910
|
const query = {};
|
|
40908
|
-
const cacheKeyOptions = {
|
|
40911
|
+
const cacheKeyOptions = {
|
|
40912
|
+
tag: "getSection",
|
|
40913
|
+
status: "notDeleted"
|
|
40914
|
+
};
|
|
40909
40915
|
try {
|
|
40910
40916
|
query.school = new ObjectId34(options.school);
|
|
40911
40917
|
cacheKeyOptions.school = String(options.school);
|
|
@@ -41060,7 +41066,7 @@ function useSectionRepo() {
|
|
|
41060
41066
|
const updateValue = field === "adviser" ? new ObjectId34(value) : value;
|
|
41061
41067
|
await collection.updateOne(
|
|
41062
41068
|
{ _id, deletedAt: { $in: ["", null] } },
|
|
41063
|
-
{ $set: { [field]: updateValue, updatedAt:
|
|
41069
|
+
{ $set: { [field]: updateValue, updatedAt: /* @__PURE__ */ new Date() } },
|
|
41064
41070
|
{ session }
|
|
41065
41071
|
);
|
|
41066
41072
|
delCachedData();
|
|
@@ -41080,7 +41086,7 @@ function useSectionRepo() {
|
|
|
41080
41086
|
{ _id, deletedAt: { $in: ["", null] } },
|
|
41081
41087
|
{
|
|
41082
41088
|
$addToSet: { students: studentId },
|
|
41083
|
-
$set: { updatedAt:
|
|
41089
|
+
$set: { updatedAt: /* @__PURE__ */ new Date() }
|
|
41084
41090
|
},
|
|
41085
41091
|
{ session }
|
|
41086
41092
|
);
|
|
@@ -41102,7 +41108,7 @@ function useSectionRepo() {
|
|
|
41102
41108
|
{
|
|
41103
41109
|
// @ts-ignore
|
|
41104
41110
|
$pull: { students: studentId },
|
|
41105
|
-
$set: { updatedAt:
|
|
41111
|
+
$set: { updatedAt: /* @__PURE__ */ new Date() }
|
|
41106
41112
|
},
|
|
41107
41113
|
{ session }
|
|
41108
41114
|
);
|
|
@@ -41112,23 +41118,42 @@ function useSectionRepo() {
|
|
|
41112
41118
|
throw new InternalServerError16("Failed to remove student from section.");
|
|
41113
41119
|
}
|
|
41114
41120
|
}
|
|
41115
|
-
async function deleteById(_id) {
|
|
41121
|
+
async function deleteById(_id, session) {
|
|
41116
41122
|
try {
|
|
41117
41123
|
_id = new ObjectId34(_id);
|
|
41118
41124
|
} catch (error) {
|
|
41119
41125
|
throw new BadRequestError56(namespace_collection + " Invalid ID.");
|
|
41120
41126
|
}
|
|
41121
41127
|
try {
|
|
41122
|
-
await collection.
|
|
41123
|
-
{ _id },
|
|
41124
|
-
{ $set: { status: "deleted", deletedAt: (/* @__PURE__ */ new Date()).toISOString() } }
|
|
41125
|
-
);
|
|
41128
|
+
await collection.deleteOne({ _id }, { session });
|
|
41126
41129
|
delCachedData();
|
|
41127
41130
|
return "Successfully deleted section.";
|
|
41128
41131
|
} catch (error) {
|
|
41129
41132
|
throw new InternalServerError16("Failed to delete section.");
|
|
41130
41133
|
}
|
|
41131
41134
|
}
|
|
41135
|
+
async function deleteByIds(_id, session) {
|
|
41136
|
+
if (_id && Array.isArray(_id)) {
|
|
41137
|
+
_id = _id.map((id) => {
|
|
41138
|
+
try {
|
|
41139
|
+
return new ObjectId34(id);
|
|
41140
|
+
} catch (error) {
|
|
41141
|
+
throw new BadRequestError56(namespace_collection + " Invalid ID.");
|
|
41142
|
+
}
|
|
41143
|
+
});
|
|
41144
|
+
}
|
|
41145
|
+
try {
|
|
41146
|
+
await collection.updateOne(
|
|
41147
|
+
{ _id: { $in: _id } },
|
|
41148
|
+
{ $set: { status: "deleted", deletedAt: /* @__PURE__ */ new Date() } },
|
|
41149
|
+
{ session }
|
|
41150
|
+
);
|
|
41151
|
+
delCachedData();
|
|
41152
|
+
return "Successfully deleted sections.";
|
|
41153
|
+
} catch (error) {
|
|
41154
|
+
throw new InternalServerError16("Failed to delete sections.");
|
|
41155
|
+
}
|
|
41156
|
+
}
|
|
41132
41157
|
async function updateSizeById(_id, size, session) {
|
|
41133
41158
|
try {
|
|
41134
41159
|
_id = new ObjectId34(_id);
|
|
@@ -41138,7 +41163,7 @@ function useSectionRepo() {
|
|
|
41138
41163
|
try {
|
|
41139
41164
|
await collection.updateOne(
|
|
41140
41165
|
{ _id },
|
|
41141
|
-
{ $set: {
|
|
41166
|
+
{ $set: { students: size, updateAt: /* @__PURE__ */ new Date() } },
|
|
41142
41167
|
{ session }
|
|
41143
41168
|
);
|
|
41144
41169
|
delCachedData();
|
|
@@ -41148,6 +41173,7 @@ function useSectionRepo() {
|
|
|
41148
41173
|
}
|
|
41149
41174
|
}
|
|
41150
41175
|
return {
|
|
41176
|
+
delCachedData,
|
|
41151
41177
|
createIndexes,
|
|
41152
41178
|
add,
|
|
41153
41179
|
getAll,
|
|
@@ -41159,7 +41185,8 @@ function useSectionRepo() {
|
|
|
41159
41185
|
addStudentToSection,
|
|
41160
41186
|
removeStudentFromSection,
|
|
41161
41187
|
deleteById,
|
|
41162
|
-
updateSizeById
|
|
41188
|
+
updateSizeById,
|
|
41189
|
+
deleteByIds
|
|
41163
41190
|
};
|
|
41164
41191
|
}
|
|
41165
41192
|
|
|
@@ -41339,7 +41366,7 @@ function useSectionStudentRepo() {
|
|
|
41339
41366
|
gradeLevel = "",
|
|
41340
41367
|
section = "",
|
|
41341
41368
|
schoolYear = ""
|
|
41342
|
-
} = {}) {
|
|
41369
|
+
} = {}, session) {
|
|
41343
41370
|
const { error } = Joi37.object({
|
|
41344
41371
|
page: Joi37.number().min(1).default(1),
|
|
41345
41372
|
limit: Joi37.number().min(1).max(100).default(10),
|
|
@@ -41401,11 +41428,10 @@ function useSectionStudentRepo() {
|
|
|
41401
41428
|
return cachedData;
|
|
41402
41429
|
}
|
|
41403
41430
|
page = page > 0 ? page - 1 : 0;
|
|
41404
|
-
const items = await collection.aggregate(
|
|
41405
|
-
{ $match: query },
|
|
41406
|
-
{
|
|
41407
|
-
|
|
41408
|
-
]).toArray();
|
|
41431
|
+
const items = await collection.aggregate(
|
|
41432
|
+
[{ $match: query }, { $skip: page * limit }, { $limit: limit }],
|
|
41433
|
+
{ session }
|
|
41434
|
+
).toArray();
|
|
41409
41435
|
const length = await collection.countDocuments(query);
|
|
41410
41436
|
const data = paginate18(items, page, limit, length);
|
|
41411
41437
|
setCache(cacheKey, data, 600).then(() => {
|
|
@@ -41480,6 +41506,13 @@ function useSectionStudentRepo() {
|
|
|
41480
41506
|
} catch (error) {
|
|
41481
41507
|
throw new BadRequestError58("Invalid section student ID.");
|
|
41482
41508
|
}
|
|
41509
|
+
try {
|
|
41510
|
+
if (typeof options.section === "string") {
|
|
41511
|
+
options.section = new ObjectId36(options.section);
|
|
41512
|
+
}
|
|
41513
|
+
} catch (error) {
|
|
41514
|
+
throw new BadRequestError58("Invalid section ID.");
|
|
41515
|
+
}
|
|
41483
41516
|
try {
|
|
41484
41517
|
await collection.updateMany({ _id }, { $set: options }, { session });
|
|
41485
41518
|
delCachedData();
|
|
@@ -43390,11 +43423,20 @@ function usePersonnelController() {
|
|
|
43390
43423
|
function useSectionService() {
|
|
43391
43424
|
const { getCountByGradeLevel, getByGradeLevel: getLeanerByGradeLevel } = useLearnerRepo();
|
|
43392
43425
|
const { getByGradeLevel } = useGradeLevelRepo();
|
|
43393
|
-
const {
|
|
43426
|
+
const {
|
|
43427
|
+
add: createSection,
|
|
43428
|
+
getSection,
|
|
43429
|
+
updateSizeById,
|
|
43430
|
+
getAll: getAllSection,
|
|
43431
|
+
deleteById: deleteSectionById,
|
|
43432
|
+
delCachedData: delCachedSectionData
|
|
43433
|
+
} = useSectionRepo();
|
|
43394
43434
|
const {
|
|
43395
43435
|
add: assignStudent,
|
|
43396
43436
|
getStudent,
|
|
43397
|
-
updateSectionById
|
|
43437
|
+
updateSectionById,
|
|
43438
|
+
getAll: getAllStudents,
|
|
43439
|
+
delCachedData: delCachedSectionStudentData
|
|
43398
43440
|
} = useSectionStudentRepo();
|
|
43399
43441
|
const { getById: getSchoolById } = useSchoolRepo();
|
|
43400
43442
|
const { getAll: getAllPersonnel } = usePersonnelRepo();
|
|
@@ -43498,6 +43540,9 @@ function useSectionService() {
|
|
|
43498
43540
|
let studentSkipped = 0;
|
|
43499
43541
|
let subjectsAssigned = 0;
|
|
43500
43542
|
let subjectsSkipped = 0;
|
|
43543
|
+
await delCachedSectionData();
|
|
43544
|
+
await delCachedSectionStudentData();
|
|
43545
|
+
console.log("SECTION SIZES:", sectionSizes);
|
|
43501
43546
|
for (let i = 0; i < sectionSizes.length; i++) {
|
|
43502
43547
|
const size = sectionSizes[i];
|
|
43503
43548
|
const sectionName = String(i + 1);
|
|
@@ -43512,11 +43557,7 @@ function useSectionService() {
|
|
|
43512
43557
|
sectionId = existingSection._id?.toString() || "";
|
|
43513
43558
|
sectionsSkipped++;
|
|
43514
43559
|
if (size !== existingSection.students) {
|
|
43515
|
-
await updateSizeById(
|
|
43516
|
-
existingSection._id?.toString() || "",
|
|
43517
|
-
size,
|
|
43518
|
-
session
|
|
43519
|
-
);
|
|
43560
|
+
await updateSizeById(sectionId, size, session);
|
|
43520
43561
|
}
|
|
43521
43562
|
} else {
|
|
43522
43563
|
sectionId = await createSection(
|
|
@@ -43558,14 +43599,13 @@ function useSectionService() {
|
|
|
43558
43599
|
const existingStudent = await getStudent({
|
|
43559
43600
|
student: student._id.toString(),
|
|
43560
43601
|
schoolYear: value.schoolYear,
|
|
43561
|
-
section: sectionId,
|
|
43562
43602
|
gradeLevel: value.gradeLevel
|
|
43563
43603
|
});
|
|
43564
43604
|
if (existingStudent) {
|
|
43565
43605
|
studentSkipped++;
|
|
43566
|
-
if (existingStudent.section !== sectionId) {
|
|
43606
|
+
if (String(existingStudent.section) !== sectionId) {
|
|
43567
43607
|
await updateSectionById(
|
|
43568
|
-
|
|
43608
|
+
existingStudent._id?.toString() ?? "",
|
|
43569
43609
|
{ section: sectionId, sectionName },
|
|
43570
43610
|
session
|
|
43571
43611
|
);
|
|
@@ -43639,6 +43679,35 @@ function useSectionService() {
|
|
|
43639
43679
|
}
|
|
43640
43680
|
}
|
|
43641
43681
|
await session.commitTransaction();
|
|
43682
|
+
await session.startTransaction();
|
|
43683
|
+
await delCachedSectionData();
|
|
43684
|
+
await delCachedSectionStudentData();
|
|
43685
|
+
const sections = await getAllSection(
|
|
43686
|
+
{
|
|
43687
|
+
school: value.school,
|
|
43688
|
+
schoolYear: value.schoolYear,
|
|
43689
|
+
gradeLevel: value.gradeLevel
|
|
43690
|
+
},
|
|
43691
|
+
session
|
|
43692
|
+
);
|
|
43693
|
+
if (sections && sections.items && sections.items.length) {
|
|
43694
|
+
for (const section of sections.items) {
|
|
43695
|
+
const sectionId = section._id?.toString() || "";
|
|
43696
|
+
const students = await getAllStudents(
|
|
43697
|
+
{
|
|
43698
|
+
school: value.school,
|
|
43699
|
+
schoolYear: value.schoolYear,
|
|
43700
|
+
section: sectionId
|
|
43701
|
+
},
|
|
43702
|
+
session
|
|
43703
|
+
);
|
|
43704
|
+
if (students && students.items && students.items.length) {
|
|
43705
|
+
continue;
|
|
43706
|
+
}
|
|
43707
|
+
await deleteSectionById(sectionId, session);
|
|
43708
|
+
}
|
|
43709
|
+
}
|
|
43710
|
+
await session.commitTransaction();
|
|
43642
43711
|
return {
|
|
43643
43712
|
message: "Sections generated successfully.",
|
|
43644
43713
|
summary: {
|
|
@@ -43656,6 +43725,7 @@ function useSectionService() {
|
|
|
43656
43725
|
}
|
|
43657
43726
|
};
|
|
43658
43727
|
} catch (error2) {
|
|
43728
|
+
console.log(error2);
|
|
43659
43729
|
await session.abortTransaction();
|
|
43660
43730
|
if (error2 instanceof AppError26) {
|
|
43661
43731
|
throw error2;
|