@eeplatform/basic-edu 1.10.7 → 1.10.9
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 +20 -6
- package/dist/index.js +253 -53
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +253 -53
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @eeplatform/basic-edu
|
|
2
2
|
|
|
3
|
+
## 1.10.9
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 113f487: Section management - fix section generation
|
|
8
|
+
|
|
9
|
+
## 1.10.8
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- cf34525: Section management - fix section generation
|
|
14
|
+
|
|
3
15
|
## 1.10.7
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/dist/index.d.ts
CHANGED
|
@@ -80,7 +80,7 @@ declare function useCurriculumController(): {
|
|
|
80
80
|
|
|
81
81
|
type TSubject = {
|
|
82
82
|
_id?: ObjectId;
|
|
83
|
-
school
|
|
83
|
+
school: string | ObjectId;
|
|
84
84
|
schoolName?: string;
|
|
85
85
|
curriculum: ObjectId | string;
|
|
86
86
|
curriculumName: string;
|
|
@@ -110,7 +110,7 @@ declare const schemaSubject: Joi.ObjectSchema<any>;
|
|
|
110
110
|
declare const schemaSubjectAdd: Joi.ObjectSchema<any>;
|
|
111
111
|
declare function modelSubject(value: TSubject): {
|
|
112
112
|
_id: ObjectId | undefined;
|
|
113
|
-
school: ObjectId
|
|
113
|
+
school: ObjectId;
|
|
114
114
|
schoolName: string;
|
|
115
115
|
curriculum: ObjectId;
|
|
116
116
|
curriculumName: string;
|
|
@@ -140,7 +140,8 @@ declare function modelSubject(value: TSubject): {
|
|
|
140
140
|
declare function useSubjectRepo(): {
|
|
141
141
|
createIndexes: () => Promise<void>;
|
|
142
142
|
add: (value: TSubject, session?: ClientSession) => Promise<ObjectId>;
|
|
143
|
-
getAll: ({ search, page, limit, sort, status, curriculum, educationLevel, gradeLevel,
|
|
143
|
+
getAll: ({ school, search, page, limit, sort, status, curriculum, educationLevel, gradeLevel, }?: {
|
|
144
|
+
school?: string | ObjectId;
|
|
144
145
|
search?: string;
|
|
145
146
|
page?: number;
|
|
146
147
|
limit?: number;
|
|
@@ -166,6 +167,8 @@ declare function useSubjectRepo(): {
|
|
|
166
167
|
declare function useSubjectController(): {
|
|
167
168
|
add: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
168
169
|
addMany: (value: {
|
|
170
|
+
school: string;
|
|
171
|
+
schoolName?: string;
|
|
169
172
|
curriculum: string;
|
|
170
173
|
curriculumName: string;
|
|
171
174
|
effectiveSchoolYear?: number[];
|
|
@@ -178,6 +181,7 @@ declare function useSubjectController(): {
|
|
|
178
181
|
sessionDuration: number;
|
|
179
182
|
totalMinutesPerWeek: number;
|
|
180
183
|
}) => Promise<string>;
|
|
184
|
+
getBySchool: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
181
185
|
getAll: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
182
186
|
getById: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
183
187
|
getByCurriculum: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
@@ -189,6 +193,8 @@ declare function useSubjectController(): {
|
|
|
189
193
|
|
|
190
194
|
declare function useSubjectService(): {
|
|
191
195
|
addMany: (value: {
|
|
196
|
+
school: string;
|
|
197
|
+
schoolName?: string;
|
|
192
198
|
curriculum: string;
|
|
193
199
|
curriculumName: string;
|
|
194
200
|
effectiveSchoolYear?: number[];
|
|
@@ -1012,6 +1018,7 @@ declare const schemaGenerateSections: Joi.ObjectSchema<any>;
|
|
|
1012
1018
|
declare function modelSection(value: TSection): TSection;
|
|
1013
1019
|
|
|
1014
1020
|
declare function useSectionRepo(): {
|
|
1021
|
+
delCachedData: () => void;
|
|
1015
1022
|
createIndexes: () => Promise<void>;
|
|
1016
1023
|
add: (value: TSection, session?: ClientSession) => Promise<string>;
|
|
1017
1024
|
getAll: ({ search, page, limit, sort, status, school, schoolYear, gradeLevel, }?: {
|
|
@@ -1023,7 +1030,7 @@ declare function useSectionRepo(): {
|
|
|
1023
1030
|
school?: string | undefined;
|
|
1024
1031
|
schoolYear?: string | undefined;
|
|
1025
1032
|
gradeLevel?: string | undefined;
|
|
1026
|
-
}) => Promise<Record<string, any> | {
|
|
1033
|
+
}, session?: ClientSession) => Promise<Record<string, any> | {
|
|
1027
1034
|
items: any[];
|
|
1028
1035
|
pages: number;
|
|
1029
1036
|
pageRange: string;
|
|
@@ -1044,8 +1051,9 @@ declare function useSectionRepo(): {
|
|
|
1044
1051
|
}, session?: ClientSession) => Promise<string>;
|
|
1045
1052
|
addStudentToSection: (_id: string | ObjectId, studentId: string, session?: ClientSession) => Promise<string>;
|
|
1046
1053
|
removeStudentFromSection: (_id: string | ObjectId, studentId: string, session?: ClientSession) => Promise<string>;
|
|
1047
|
-
deleteById: (_id: string | ObjectId) => Promise<string>;
|
|
1054
|
+
deleteById: (_id: string | ObjectId, session?: ClientSession) => Promise<string>;
|
|
1048
1055
|
updateSizeById: (_id: string | ObjectId, size: number, session?: ClientSession) => Promise<string>;
|
|
1056
|
+
deleteByIds: (_id: string[] | ObjectId[], session?: ClientSession) => Promise<string>;
|
|
1049
1057
|
};
|
|
1050
1058
|
|
|
1051
1059
|
declare function useSectionController(): {
|
|
@@ -1095,7 +1103,11 @@ declare function useSectionStudentRepo(): {
|
|
|
1095
1103
|
gradeLevel?: string;
|
|
1096
1104
|
section?: string | ObjectId;
|
|
1097
1105
|
schoolYear?: string;
|
|
1098
|
-
}) => Promise<{
|
|
1106
|
+
}, session?: ClientSession) => Promise<{
|
|
1107
|
+
items: any[];
|
|
1108
|
+
pages: number;
|
|
1109
|
+
pageRange: string;
|
|
1110
|
+
}>;
|
|
1099
1111
|
getStudent: (options: {
|
|
1100
1112
|
schoolYear?: string;
|
|
1101
1113
|
section?: string | ObjectId;
|
|
@@ -1578,6 +1590,7 @@ declare function useTeachingLoadSlotRepo(): {
|
|
|
1578
1590
|
getById: (_id: string | ObjectId) => Promise<TTeachingLoadSlot | null>;
|
|
1579
1591
|
deleteById: (_id: string | ObjectId, session?: ClientSession) => Promise<mongodb.UpdateResult<bson.Document>>;
|
|
1580
1592
|
delCachedData: () => void;
|
|
1593
|
+
deleteBySection: (section: string | ObjectId, session?: ClientSession) => Promise<mongodb.UpdateResult<bson.Document>>;
|
|
1581
1594
|
};
|
|
1582
1595
|
|
|
1583
1596
|
declare function useTeachingLoadSlotController(): {
|
|
@@ -1588,6 +1601,7 @@ declare function useTeachingLoadSlotController(): {
|
|
|
1588
1601
|
deleteById: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
1589
1602
|
getByTeachingLoad: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
1590
1603
|
getByTeacher: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
1604
|
+
getBySection: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
1591
1605
|
};
|
|
1592
1606
|
|
|
1593
1607
|
type TProgram = {
|
package/dist/index.js
CHANGED
|
@@ -2163,7 +2163,7 @@ var import_joi3 = __toESM(require("joi"));
|
|
|
2163
2163
|
var import_mongodb3 = require("mongodb");
|
|
2164
2164
|
var schemaSubject = import_joi3.default.object({
|
|
2165
2165
|
_id: import_joi3.default.string().hex().optional(),
|
|
2166
|
-
school: import_joi3.default.string().hex().
|
|
2166
|
+
school: import_joi3.default.string().hex().required(),
|
|
2167
2167
|
schoolName: import_joi3.default.string().optional().allow("", null),
|
|
2168
2168
|
curriculum: import_joi3.default.string().hex().required(),
|
|
2169
2169
|
curriculumName: import_joi3.default.string().required(),
|
|
@@ -2190,6 +2190,8 @@ var schemaSubject = import_joi3.default.object({
|
|
|
2190
2190
|
deletedBy: import_joi3.default.string().optional().allow("", null)
|
|
2191
2191
|
});
|
|
2192
2192
|
var schemaSubjectAdd = import_joi3.default.object({
|
|
2193
|
+
school: import_joi3.default.string().hex().required(),
|
|
2194
|
+
schoolName: import_joi3.default.string().optional().allow("", null),
|
|
2193
2195
|
curriculum: import_joi3.default.string().hex().required(),
|
|
2194
2196
|
curriculumName: import_joi3.default.string().required(),
|
|
2195
2197
|
effectiveSchoolYear: import_joi3.default.array().items(import_joi3.default.number().integer().min(1900)).optional(),
|
|
@@ -2213,6 +2215,11 @@ function modelSubject(value) {
|
|
|
2213
2215
|
import_nodejs_utils4.logger.info(`Subject Model: ${error.message}`);
|
|
2214
2216
|
throw new import_nodejs_utils4.BadRequestError(error.message);
|
|
2215
2217
|
}
|
|
2218
|
+
try {
|
|
2219
|
+
value.school = new import_mongodb3.ObjectId(value.school);
|
|
2220
|
+
} catch (error2) {
|
|
2221
|
+
throw new import_nodejs_utils4.BadRequestError("Invalid school ID format");
|
|
2222
|
+
}
|
|
2216
2223
|
if (value._id && typeof value._id === "string") {
|
|
2217
2224
|
try {
|
|
2218
2225
|
value._id = new import_mongodb3.ObjectId(value._id);
|
|
@@ -2227,13 +2234,6 @@ function modelSubject(value) {
|
|
|
2227
2234
|
throw new import_nodejs_utils4.BadRequestError("Invalid curriculum ID format");
|
|
2228
2235
|
}
|
|
2229
2236
|
}
|
|
2230
|
-
if (value.school && typeof value.school === "string") {
|
|
2231
|
-
try {
|
|
2232
|
-
value.school = new import_mongodb3.ObjectId(value.school);
|
|
2233
|
-
} catch (error2) {
|
|
2234
|
-
throw new import_nodejs_utils4.BadRequestError("Invalid school ID format");
|
|
2235
|
-
}
|
|
2236
|
-
}
|
|
2237
2237
|
if (value.program && typeof value.program === "string") {
|
|
2238
2238
|
try {
|
|
2239
2239
|
value.program = new import_mongodb3.ObjectId(value.program);
|
|
@@ -2353,6 +2353,7 @@ function useSubjectRepo() {
|
|
|
2353
2353
|
}
|
|
2354
2354
|
}
|
|
2355
2355
|
async function getAll({
|
|
2356
|
+
school = "",
|
|
2356
2357
|
search = "",
|
|
2357
2358
|
page = 1,
|
|
2358
2359
|
limit = 10,
|
|
@@ -2360,18 +2361,27 @@ function useSubjectRepo() {
|
|
|
2360
2361
|
status = "active",
|
|
2361
2362
|
curriculum,
|
|
2362
2363
|
educationLevel,
|
|
2363
|
-
gradeLevel
|
|
2364
|
-
schoolYear = 0
|
|
2364
|
+
gradeLevel
|
|
2365
2365
|
} = {}) {
|
|
2366
2366
|
page = page > 0 ? page - 1 : 0;
|
|
2367
|
-
const query = {
|
|
2368
|
-
status
|
|
2369
|
-
};
|
|
2367
|
+
const query = {};
|
|
2370
2368
|
const cacheParams = {
|
|
2371
2369
|
page,
|
|
2372
2370
|
limit,
|
|
2373
2371
|
sort: JSON.stringify(sort)
|
|
2374
2372
|
};
|
|
2373
|
+
if (status) {
|
|
2374
|
+
query.status = status;
|
|
2375
|
+
cacheParams.status = status;
|
|
2376
|
+
}
|
|
2377
|
+
if (school) {
|
|
2378
|
+
try {
|
|
2379
|
+
query.school = new import_mongodb4.ObjectId(school);
|
|
2380
|
+
} catch (error) {
|
|
2381
|
+
throw new import_nodejs_utils5.BadRequestError("Invalid school ID format.");
|
|
2382
|
+
}
|
|
2383
|
+
cacheParams.school = school;
|
|
2384
|
+
}
|
|
2375
2385
|
if (curriculum) {
|
|
2376
2386
|
try {
|
|
2377
2387
|
query.curriculum = new import_mongodb4.ObjectId(curriculum);
|
|
@@ -2388,10 +2398,6 @@ function useSubjectRepo() {
|
|
|
2388
2398
|
query.gradeLevel = gradeLevel;
|
|
2389
2399
|
cacheParams.gradeLevel = gradeLevel;
|
|
2390
2400
|
}
|
|
2391
|
-
if (schoolYear) {
|
|
2392
|
-
query.effectiveSchoolYear = schoolYear;
|
|
2393
|
-
cacheParams.schoolYear = schoolYear;
|
|
2394
|
-
}
|
|
2395
2401
|
sort = Object.keys(sort).length > 0 ? sort : { _id: -1 };
|
|
2396
2402
|
if (search) {
|
|
2397
2403
|
query.$or = [
|
|
@@ -2699,6 +2705,8 @@ function useSubjectService() {
|
|
|
2699
2705
|
const gradeLevel = value.gradeLevel[index];
|
|
2700
2706
|
await add(
|
|
2701
2707
|
{
|
|
2708
|
+
school: value.school,
|
|
2709
|
+
schoolName: value.schoolName,
|
|
2702
2710
|
curriculum: value.curriculum,
|
|
2703
2711
|
curriculumName: value.curriculumName,
|
|
2704
2712
|
effectiveSchoolYear: value.effectiveSchoolYear,
|
|
@@ -2850,6 +2858,62 @@ function useSubjectController() {
|
|
|
2850
2858
|
next(error2);
|
|
2851
2859
|
}
|
|
2852
2860
|
}
|
|
2861
|
+
async function getBySchool(req, res, next) {
|
|
2862
|
+
const school = req.params.school ?? "";
|
|
2863
|
+
const { error: errorSchool } = import_joi4.default.string().hex().required().validate(school);
|
|
2864
|
+
if (errorSchool) {
|
|
2865
|
+
next(new import_nodejs_utils7.BadRequestError(errorSchool.message));
|
|
2866
|
+
return;
|
|
2867
|
+
}
|
|
2868
|
+
const query = req.query;
|
|
2869
|
+
const validation = import_joi4.default.object({
|
|
2870
|
+
page: import_joi4.default.number().min(1).optional().allow("", null),
|
|
2871
|
+
limit: import_joi4.default.number().min(1).optional().allow("", null),
|
|
2872
|
+
search: import_joi4.default.string().optional().allow("", null),
|
|
2873
|
+
status: import_joi4.default.string().optional().allow("", null),
|
|
2874
|
+
curriculum: import_joi4.default.string().hex().optional().allow("", null),
|
|
2875
|
+
educationLevel: import_joi4.default.string().optional().allow("", null),
|
|
2876
|
+
gradeLevel: import_joi4.default.string().optional().allow("", null)
|
|
2877
|
+
});
|
|
2878
|
+
const { error } = validation.validate(query);
|
|
2879
|
+
if (error) {
|
|
2880
|
+
next(new import_nodejs_utils7.BadRequestError(error.message));
|
|
2881
|
+
return;
|
|
2882
|
+
}
|
|
2883
|
+
const page = parseInt(req.query.page) ?? 1;
|
|
2884
|
+
let limit = parseInt(req.query.limit) ?? 20;
|
|
2885
|
+
limit = isNaN(limit) ? 20 : limit;
|
|
2886
|
+
const sort = req.query.sort ? String(req.query.sort).split(",") : "";
|
|
2887
|
+
const sortOrder = req.query.sortOrder ? String(req.query.sortOrder).split(",") : "";
|
|
2888
|
+
const sortObj = {};
|
|
2889
|
+
if (sort && Array.isArray(sort) && sort.length && sortOrder && Array.isArray(sortOrder) && sortOrder.length) {
|
|
2890
|
+
sort.forEach((field, index) => {
|
|
2891
|
+
sortObj[field] = sortOrder[index] === "desc" ? -1 : 1;
|
|
2892
|
+
});
|
|
2893
|
+
}
|
|
2894
|
+
const status = req.query.status ?? "active";
|
|
2895
|
+
const search = req.query.search ?? "";
|
|
2896
|
+
const curriculum = req.query.curriculum ?? "";
|
|
2897
|
+
const educationLevel = req.query.educationLevel ?? "";
|
|
2898
|
+
const gradeLevel = req.query.gradeLevel ?? "";
|
|
2899
|
+
try {
|
|
2900
|
+
const curriculumSubjects = await _getAll({
|
|
2901
|
+
school,
|
|
2902
|
+
page,
|
|
2903
|
+
limit,
|
|
2904
|
+
sort: sortObj,
|
|
2905
|
+
status,
|
|
2906
|
+
search,
|
|
2907
|
+
curriculum,
|
|
2908
|
+
educationLevel,
|
|
2909
|
+
gradeLevel
|
|
2910
|
+
});
|
|
2911
|
+
res.json(curriculumSubjects);
|
|
2912
|
+
return;
|
|
2913
|
+
} catch (error2) {
|
|
2914
|
+
next(error2);
|
|
2915
|
+
}
|
|
2916
|
+
}
|
|
2853
2917
|
async function getAsOptions(req, res, next) {
|
|
2854
2918
|
const query = req.query;
|
|
2855
2919
|
const validation = import_joi4.default.object({
|
|
@@ -2957,6 +3021,7 @@ function useSubjectController() {
|
|
|
2957
3021
|
return {
|
|
2958
3022
|
add,
|
|
2959
3023
|
addMany,
|
|
3024
|
+
getBySchool,
|
|
2960
3025
|
getAll,
|
|
2961
3026
|
getById,
|
|
2962
3027
|
getByCurriculum,
|
|
@@ -40747,7 +40812,7 @@ function useSectionRepo() {
|
|
|
40747
40812
|
school = "",
|
|
40748
40813
|
schoolYear = "",
|
|
40749
40814
|
gradeLevel = ""
|
|
40750
|
-
} = {}) {
|
|
40815
|
+
} = {}, session) {
|
|
40751
40816
|
page = page > 0 ? page - 1 : 0;
|
|
40752
40817
|
const query = {
|
|
40753
40818
|
deletedAt: { $in: ["", null] },
|
|
@@ -40794,12 +40859,15 @@ function useSectionRepo() {
|
|
|
40794
40859
|
});
|
|
40795
40860
|
return cached;
|
|
40796
40861
|
}
|
|
40797
|
-
const items = await collection.aggregate(
|
|
40798
|
-
|
|
40799
|
-
|
|
40800
|
-
|
|
40801
|
-
|
|
40802
|
-
|
|
40862
|
+
const items = await collection.aggregate(
|
|
40863
|
+
[
|
|
40864
|
+
{ $match: query },
|
|
40865
|
+
{ $sort: sort },
|
|
40866
|
+
{ $skip: page * limit },
|
|
40867
|
+
{ $limit: limit }
|
|
40868
|
+
],
|
|
40869
|
+
{ session }
|
|
40870
|
+
).toArray();
|
|
40803
40871
|
const length = await collection.countDocuments(query);
|
|
40804
40872
|
const data = (0, import_nodejs_utils59.paginate)(items, page, limit, length);
|
|
40805
40873
|
setCache(cacheKey, data, 600).then(() => {
|
|
@@ -40864,7 +40932,10 @@ function useSectionRepo() {
|
|
|
40864
40932
|
}
|
|
40865
40933
|
async function getSection(options) {
|
|
40866
40934
|
const query = {};
|
|
40867
|
-
const cacheKeyOptions = {
|
|
40935
|
+
const cacheKeyOptions = {
|
|
40936
|
+
tag: "getSection",
|
|
40937
|
+
status: "notDeleted"
|
|
40938
|
+
};
|
|
40868
40939
|
try {
|
|
40869
40940
|
query.school = new import_mongodb34.ObjectId(options.school);
|
|
40870
40941
|
cacheKeyOptions.school = String(options.school);
|
|
@@ -41019,7 +41090,7 @@ function useSectionRepo() {
|
|
|
41019
41090
|
const updateValue = field === "adviser" ? new import_mongodb34.ObjectId(value) : value;
|
|
41020
41091
|
await collection.updateOne(
|
|
41021
41092
|
{ _id, deletedAt: { $in: ["", null] } },
|
|
41022
|
-
{ $set: { [field]: updateValue, updatedAt:
|
|
41093
|
+
{ $set: { [field]: updateValue, updatedAt: /* @__PURE__ */ new Date() } },
|
|
41023
41094
|
{ session }
|
|
41024
41095
|
);
|
|
41025
41096
|
delCachedData();
|
|
@@ -41039,7 +41110,7 @@ function useSectionRepo() {
|
|
|
41039
41110
|
{ _id, deletedAt: { $in: ["", null] } },
|
|
41040
41111
|
{
|
|
41041
41112
|
$addToSet: { students: studentId },
|
|
41042
|
-
$set: { updatedAt:
|
|
41113
|
+
$set: { updatedAt: /* @__PURE__ */ new Date() }
|
|
41043
41114
|
},
|
|
41044
41115
|
{ session }
|
|
41045
41116
|
);
|
|
@@ -41061,7 +41132,7 @@ function useSectionRepo() {
|
|
|
41061
41132
|
{
|
|
41062
41133
|
// @ts-ignore
|
|
41063
41134
|
$pull: { students: studentId },
|
|
41064
|
-
$set: { updatedAt:
|
|
41135
|
+
$set: { updatedAt: /* @__PURE__ */ new Date() }
|
|
41065
41136
|
},
|
|
41066
41137
|
{ session }
|
|
41067
41138
|
);
|
|
@@ -41071,23 +41142,42 @@ function useSectionRepo() {
|
|
|
41071
41142
|
throw new import_nodejs_utils59.InternalServerError("Failed to remove student from section.");
|
|
41072
41143
|
}
|
|
41073
41144
|
}
|
|
41074
|
-
async function deleteById(_id) {
|
|
41145
|
+
async function deleteById(_id, session) {
|
|
41075
41146
|
try {
|
|
41076
41147
|
_id = new import_mongodb34.ObjectId(_id);
|
|
41077
41148
|
} catch (error) {
|
|
41078
41149
|
throw new import_nodejs_utils59.BadRequestError(namespace_collection + " Invalid ID.");
|
|
41079
41150
|
}
|
|
41080
41151
|
try {
|
|
41081
|
-
await collection.
|
|
41082
|
-
{ _id },
|
|
41083
|
-
{ $set: { status: "deleted", deletedAt: (/* @__PURE__ */ new Date()).toISOString() } }
|
|
41084
|
-
);
|
|
41152
|
+
await collection.deleteOne({ _id }, { session });
|
|
41085
41153
|
delCachedData();
|
|
41086
41154
|
return "Successfully deleted section.";
|
|
41087
41155
|
} catch (error) {
|
|
41088
41156
|
throw new import_nodejs_utils59.InternalServerError("Failed to delete section.");
|
|
41089
41157
|
}
|
|
41090
41158
|
}
|
|
41159
|
+
async function deleteByIds(_id, session) {
|
|
41160
|
+
if (_id && Array.isArray(_id)) {
|
|
41161
|
+
_id = _id.map((id) => {
|
|
41162
|
+
try {
|
|
41163
|
+
return new import_mongodb34.ObjectId(id);
|
|
41164
|
+
} catch (error) {
|
|
41165
|
+
throw new import_nodejs_utils59.BadRequestError(namespace_collection + " Invalid ID.");
|
|
41166
|
+
}
|
|
41167
|
+
});
|
|
41168
|
+
}
|
|
41169
|
+
try {
|
|
41170
|
+
await collection.updateOne(
|
|
41171
|
+
{ _id: { $in: _id } },
|
|
41172
|
+
{ $set: { status: "deleted", deletedAt: /* @__PURE__ */ new Date() } },
|
|
41173
|
+
{ session }
|
|
41174
|
+
);
|
|
41175
|
+
delCachedData();
|
|
41176
|
+
return "Successfully deleted sections.";
|
|
41177
|
+
} catch (error) {
|
|
41178
|
+
throw new import_nodejs_utils59.InternalServerError("Failed to delete sections.");
|
|
41179
|
+
}
|
|
41180
|
+
}
|
|
41091
41181
|
async function updateSizeById(_id, size, session) {
|
|
41092
41182
|
try {
|
|
41093
41183
|
_id = new import_mongodb34.ObjectId(_id);
|
|
@@ -41097,7 +41187,7 @@ function useSectionRepo() {
|
|
|
41097
41187
|
try {
|
|
41098
41188
|
await collection.updateOne(
|
|
41099
41189
|
{ _id },
|
|
41100
|
-
{ $set: {
|
|
41190
|
+
{ $set: { students: size, updateAt: /* @__PURE__ */ new Date() } },
|
|
41101
41191
|
{ session }
|
|
41102
41192
|
);
|
|
41103
41193
|
delCachedData();
|
|
@@ -41107,6 +41197,7 @@ function useSectionRepo() {
|
|
|
41107
41197
|
}
|
|
41108
41198
|
}
|
|
41109
41199
|
return {
|
|
41200
|
+
delCachedData,
|
|
41110
41201
|
createIndexes,
|
|
41111
41202
|
add,
|
|
41112
41203
|
getAll,
|
|
@@ -41118,7 +41209,8 @@ function useSectionRepo() {
|
|
|
41118
41209
|
addStudentToSection,
|
|
41119
41210
|
removeStudentFromSection,
|
|
41120
41211
|
deleteById,
|
|
41121
|
-
updateSizeById
|
|
41212
|
+
updateSizeById,
|
|
41213
|
+
deleteByIds
|
|
41122
41214
|
};
|
|
41123
41215
|
}
|
|
41124
41216
|
|
|
@@ -41284,7 +41376,7 @@ function useSectionStudentRepo() {
|
|
|
41284
41376
|
gradeLevel = "",
|
|
41285
41377
|
section = "",
|
|
41286
41378
|
schoolYear = ""
|
|
41287
|
-
} = {}) {
|
|
41379
|
+
} = {}, session) {
|
|
41288
41380
|
const { error } = import_joi37.default.object({
|
|
41289
41381
|
page: import_joi37.default.number().min(1).default(1),
|
|
41290
41382
|
limit: import_joi37.default.number().min(1).max(100).default(10),
|
|
@@ -41346,11 +41438,10 @@ function useSectionStudentRepo() {
|
|
|
41346
41438
|
return cachedData;
|
|
41347
41439
|
}
|
|
41348
41440
|
page = page > 0 ? page - 1 : 0;
|
|
41349
|
-
const items = await collection.aggregate(
|
|
41350
|
-
{ $match: query },
|
|
41351
|
-
{
|
|
41352
|
-
|
|
41353
|
-
]).toArray();
|
|
41441
|
+
const items = await collection.aggregate(
|
|
41442
|
+
[{ $match: query }, { $skip: page * limit }, { $limit: limit }],
|
|
41443
|
+
{ session }
|
|
41444
|
+
).toArray();
|
|
41354
41445
|
const length = await collection.countDocuments(query);
|
|
41355
41446
|
const data = (0, import_nodejs_utils61.paginate)(items, page, limit, length);
|
|
41356
41447
|
setCache(cacheKey, data, 600).then(() => {
|
|
@@ -41425,6 +41516,13 @@ function useSectionStudentRepo() {
|
|
|
41425
41516
|
} catch (error) {
|
|
41426
41517
|
throw new import_nodejs_utils61.BadRequestError("Invalid section student ID.");
|
|
41427
41518
|
}
|
|
41519
|
+
try {
|
|
41520
|
+
if (typeof options.section === "string") {
|
|
41521
|
+
options.section = new import_mongodb36.ObjectId(options.section);
|
|
41522
|
+
}
|
|
41523
|
+
} catch (error) {
|
|
41524
|
+
throw new import_nodejs_utils61.BadRequestError("Invalid section ID.");
|
|
41525
|
+
}
|
|
41428
41526
|
try {
|
|
41429
41527
|
await collection.updateMany({ _id }, { $set: options }, { session });
|
|
41430
41528
|
delCachedData();
|
|
@@ -42419,6 +42517,32 @@ function useTeachingLoadSlotRepo() {
|
|
|
42419
42517
|
}
|
|
42420
42518
|
}
|
|
42421
42519
|
}
|
|
42520
|
+
async function deleteBySection(section, session) {
|
|
42521
|
+
try {
|
|
42522
|
+
section = new import_mongodb40.ObjectId(section);
|
|
42523
|
+
} catch (error) {
|
|
42524
|
+
throw new import_nodejs_utils66.BadRequestError(namespace_collection + " Invalid section ID.");
|
|
42525
|
+
}
|
|
42526
|
+
try {
|
|
42527
|
+
const res = await collection.updateOne(
|
|
42528
|
+
{ section },
|
|
42529
|
+
{ $set: { status: "deleted", deletedAt: /* @__PURE__ */ new Date() } },
|
|
42530
|
+
{ session }
|
|
42531
|
+
);
|
|
42532
|
+
delCachedData();
|
|
42533
|
+
return res;
|
|
42534
|
+
} catch (error) {
|
|
42535
|
+
import_nodejs_utils66.logger.log({
|
|
42536
|
+
level: "error",
|
|
42537
|
+
message: error.message
|
|
42538
|
+
});
|
|
42539
|
+
if (error instanceof import_nodejs_utils66.AppError) {
|
|
42540
|
+
throw error;
|
|
42541
|
+
} else {
|
|
42542
|
+
throw new import_nodejs_utils66.InternalServerError("Failed to delete teaching load slot.");
|
|
42543
|
+
}
|
|
42544
|
+
}
|
|
42545
|
+
}
|
|
42422
42546
|
function delCachedData() {
|
|
42423
42547
|
delNamespace().then(() => {
|
|
42424
42548
|
import_nodejs_utils66.logger.log({
|
|
@@ -42439,7 +42563,8 @@ function useTeachingLoadSlotRepo() {
|
|
|
42439
42563
|
getAll,
|
|
42440
42564
|
getById,
|
|
42441
42565
|
deleteById,
|
|
42442
|
-
delCachedData
|
|
42566
|
+
delCachedData,
|
|
42567
|
+
deleteBySection
|
|
42443
42568
|
};
|
|
42444
42569
|
}
|
|
42445
42570
|
|
|
@@ -42555,6 +42680,43 @@ function useTeachingLoadSlotController() {
|
|
|
42555
42680
|
next(error2);
|
|
42556
42681
|
}
|
|
42557
42682
|
}
|
|
42683
|
+
async function getBySection(req, res, next) {
|
|
42684
|
+
const section = req.params.section ?? "";
|
|
42685
|
+
const validation = import_joi42.default.string().hex().required();
|
|
42686
|
+
const { error: errorTeacher } = validation.validate(section);
|
|
42687
|
+
if (errorTeacher) {
|
|
42688
|
+
next(new import_nodejs_utils68.BadRequestError(errorTeacher.message));
|
|
42689
|
+
import_nodejs_utils68.logger.info(`Controller: ${errorTeacher.message}`);
|
|
42690
|
+
return;
|
|
42691
|
+
}
|
|
42692
|
+
const query = req.query;
|
|
42693
|
+
const schema = import_joi42.default.object({
|
|
42694
|
+
page: import_joi42.default.number().min(1).optional().allow("", null),
|
|
42695
|
+
limit: import_joi42.default.number().min(1).max(100).optional().allow("", null),
|
|
42696
|
+
status: import_joi42.default.string().optional().allow("", null)
|
|
42697
|
+
});
|
|
42698
|
+
const { error } = schema.validate(query);
|
|
42699
|
+
if (error) {
|
|
42700
|
+
next(new import_nodejs_utils68.BadRequestError(error.message));
|
|
42701
|
+
import_nodejs_utils68.logger.info(`Controller: ${error.message}`);
|
|
42702
|
+
return;
|
|
42703
|
+
}
|
|
42704
|
+
const page = Number(req.query.page ?? 1);
|
|
42705
|
+
const limit = Number(req.query.limit ?? 10);
|
|
42706
|
+
const status = req.query.status ?? "active";
|
|
42707
|
+
try {
|
|
42708
|
+
const result = await _getAll({
|
|
42709
|
+
section,
|
|
42710
|
+
page,
|
|
42711
|
+
limit,
|
|
42712
|
+
status
|
|
42713
|
+
});
|
|
42714
|
+
res.json(result);
|
|
42715
|
+
return;
|
|
42716
|
+
} catch (error2) {
|
|
42717
|
+
next(error2);
|
|
42718
|
+
}
|
|
42719
|
+
}
|
|
42558
42720
|
async function getByTeacher(req, res, next) {
|
|
42559
42721
|
const teacher = req.params.teacher ?? "";
|
|
42560
42722
|
const schemaTeacher = import_joi42.default.string().hex().required();
|
|
@@ -42743,7 +42905,8 @@ function useTeachingLoadSlotController() {
|
|
|
42743
42905
|
getById,
|
|
42744
42906
|
deleteById,
|
|
42745
42907
|
getByTeachingLoad,
|
|
42746
|
-
getByTeacher
|
|
42908
|
+
getByTeacher,
|
|
42909
|
+
getBySection
|
|
42747
42910
|
};
|
|
42748
42911
|
}
|
|
42749
42912
|
|
|
@@ -43308,15 +43471,25 @@ function usePersonnelController() {
|
|
|
43308
43471
|
function useSectionService() {
|
|
43309
43472
|
const { getCountByGradeLevel, getByGradeLevel: getLeanerByGradeLevel } = useLearnerRepo();
|
|
43310
43473
|
const { getByGradeLevel } = useGradeLevelRepo();
|
|
43311
|
-
const {
|
|
43474
|
+
const {
|
|
43475
|
+
add: createSection,
|
|
43476
|
+
getSection,
|
|
43477
|
+
updateSizeById,
|
|
43478
|
+
getAll: getAllSection,
|
|
43479
|
+
deleteById: deleteSectionById,
|
|
43480
|
+
delCachedData: delCachedSectionData
|
|
43481
|
+
} = useSectionRepo();
|
|
43312
43482
|
const {
|
|
43313
43483
|
add: assignStudent,
|
|
43314
43484
|
getStudent,
|
|
43315
|
-
updateSectionById
|
|
43485
|
+
updateSectionById,
|
|
43486
|
+
getAll: getAllStudents,
|
|
43487
|
+
delCachedData: delCachedSectionStudentData
|
|
43316
43488
|
} = useSectionStudentRepo();
|
|
43317
43489
|
const { getById: getSchoolById } = useSchoolRepo();
|
|
43318
43490
|
const { getAll: getAllPersonnel } = usePersonnelRepo();
|
|
43319
43491
|
const { add: addTeachingLoad, getByTeacher } = useTeachingLoadRepo();
|
|
43492
|
+
const { deleteBySection: deleteTeachingLoadSlotsBySection } = useTeachingLoadSlotRepo();
|
|
43320
43493
|
function distributeStudents(total, minPer, maxPer) {
|
|
43321
43494
|
if (total <= 0)
|
|
43322
43495
|
return [];
|
|
@@ -43416,6 +43589,8 @@ function useSectionService() {
|
|
|
43416
43589
|
let studentSkipped = 0;
|
|
43417
43590
|
let subjectsAssigned = 0;
|
|
43418
43591
|
let subjectsSkipped = 0;
|
|
43592
|
+
await delCachedSectionData();
|
|
43593
|
+
await delCachedSectionStudentData();
|
|
43419
43594
|
for (let i = 0; i < sectionSizes.length; i++) {
|
|
43420
43595
|
const size = sectionSizes[i];
|
|
43421
43596
|
const sectionName = String(i + 1);
|
|
@@ -43430,11 +43605,7 @@ function useSectionService() {
|
|
|
43430
43605
|
sectionId = existingSection._id?.toString() || "";
|
|
43431
43606
|
sectionsSkipped++;
|
|
43432
43607
|
if (size !== existingSection.students) {
|
|
43433
|
-
await updateSizeById(
|
|
43434
|
-
existingSection._id?.toString() || "",
|
|
43435
|
-
size,
|
|
43436
|
-
session
|
|
43437
|
-
);
|
|
43608
|
+
await updateSizeById(sectionId, size, session);
|
|
43438
43609
|
}
|
|
43439
43610
|
} else {
|
|
43440
43611
|
sectionId = await createSection(
|
|
@@ -43476,14 +43647,13 @@ function useSectionService() {
|
|
|
43476
43647
|
const existingStudent = await getStudent({
|
|
43477
43648
|
student: student._id.toString(),
|
|
43478
43649
|
schoolYear: value.schoolYear,
|
|
43479
|
-
section: sectionId,
|
|
43480
43650
|
gradeLevel: value.gradeLevel
|
|
43481
43651
|
});
|
|
43482
43652
|
if (existingStudent) {
|
|
43483
43653
|
studentSkipped++;
|
|
43484
|
-
if (existingStudent.section !== sectionId) {
|
|
43654
|
+
if (String(existingStudent.section) !== sectionId) {
|
|
43485
43655
|
await updateSectionById(
|
|
43486
|
-
|
|
43656
|
+
existingStudent._id?.toString() ?? "",
|
|
43487
43657
|
{ section: sectionId, sectionName },
|
|
43488
43658
|
session
|
|
43489
43659
|
);
|
|
@@ -43557,6 +43727,36 @@ function useSectionService() {
|
|
|
43557
43727
|
}
|
|
43558
43728
|
}
|
|
43559
43729
|
await session.commitTransaction();
|
|
43730
|
+
await session.startTransaction();
|
|
43731
|
+
await delCachedSectionData();
|
|
43732
|
+
await delCachedSectionStudentData();
|
|
43733
|
+
const sections = await getAllSection(
|
|
43734
|
+
{
|
|
43735
|
+
school: value.school,
|
|
43736
|
+
schoolYear: value.schoolYear,
|
|
43737
|
+
gradeLevel: value.gradeLevel
|
|
43738
|
+
},
|
|
43739
|
+
session
|
|
43740
|
+
);
|
|
43741
|
+
if (sections && sections.items && sections.items.length) {
|
|
43742
|
+
for (const section of sections.items) {
|
|
43743
|
+
const sectionId = section._id?.toString() || "";
|
|
43744
|
+
const students = await getAllStudents(
|
|
43745
|
+
{
|
|
43746
|
+
school: value.school,
|
|
43747
|
+
schoolYear: value.schoolYear,
|
|
43748
|
+
section: sectionId
|
|
43749
|
+
},
|
|
43750
|
+
session
|
|
43751
|
+
);
|
|
43752
|
+
if (students && students.items && students.items.length) {
|
|
43753
|
+
continue;
|
|
43754
|
+
}
|
|
43755
|
+
await deleteSectionById(sectionId, session);
|
|
43756
|
+
await deleteTeachingLoadSlotsBySection(sectionId, session);
|
|
43757
|
+
}
|
|
43758
|
+
}
|
|
43759
|
+
await session.commitTransaction();
|
|
43560
43760
|
return {
|
|
43561
43761
|
message: "Sections generated successfully.",
|
|
43562
43762
|
summary: {
|