@kipicore/dbcore 1.1.5 → 1.1.6
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/README.md +1 -1
- package/dist/constants/app.js +0 -1
- package/dist/db/mongodb.js +4 -4
- package/dist/db/postgres.d.ts +1 -1
- package/dist/db/postgres.js +5 -5
- package/dist/index.d.ts +417 -415
- package/dist/index.js +742 -428
- package/dist/models/mongodb/attendanceModel.d.ts +2 -2
- package/dist/models/mongodb/attendanceModel.js +7 -8
- package/dist/models/mongodb/eventModel.d.ts +2 -2
- package/dist/models/mongodb/eventModel.js +3 -3
- package/dist/models/mongodb/examGroupModel.d.ts +2 -2
- package/dist/models/mongodb/examGroupModel.js +22 -28
- package/dist/models/mongodb/examHasAnswerSheetModel.d.ts +2 -2
- package/dist/models/mongodb/examHasAnswerSheetModel.js +5 -6
- package/dist/models/mongodb/examModel.d.ts +2 -2
- package/dist/models/mongodb/examModel.js +7 -10
- package/dist/models/mongodb/holidayModel.d.ts +2 -2
- package/dist/models/mongodb/holidayModel.js +4 -6
- package/dist/models/mongodb/inquiryModel.d.ts +2 -2
- package/dist/models/mongodb/inquiryModel.js +3 -4
- package/dist/models/mongodb/plugin/transformIdInResponsePlugin.d.ts +1 -1
- package/dist/models/mongodb/plugin/transformIdInResponsePlugin.js +4 -6
- package/dist/models/mongodb/schoolFeeModel.d.ts +2 -2
- package/dist/models/mongodb/schoolFeeModel.js +3 -3
- package/dist/models/mongodb/subjectIndexModel.d.ts +2 -2
- package/dist/models/mongodb/subjectIndexModel.js +66 -108
- package/dist/models/mongodb/subscriptionPlanModel.d.ts +2 -2
- package/dist/models/mongodb/subscriptionPlanModel.js +1 -1
- package/dist/models/mongodb/taskManagementModel.d.ts +2 -2
- package/dist/models/mongodb/taskManagementModel.js +3 -3
- package/dist/models/mongodb/userDoc.d.ts +1 -1
- package/dist/models/mongodb/userDoc.js +1 -1
- package/dist/models/mongodb/userSchoolMetaModel.d.ts +1 -1
- package/dist/models/mongodb/userSchoolMetaModel.js +8 -8
- package/dist/models/psql/announcementModel.d.ts +4 -4
- package/dist/models/psql/announcementModel.js +25 -25
- package/dist/models/psql/batchModel.d.ts +4 -4
- package/dist/models/psql/batchModel.js +51 -51
- package/dist/models/psql/driverModel.d.ts +4 -4
- package/dist/models/psql/driverModel.js +28 -28
- package/dist/models/psql/facilityModel.d.ts +4 -4
- package/dist/models/psql/facilityModel.js +23 -23
- package/dist/models/psql/feeHistoryModel.d.ts +4 -4
- package/dist/models/psql/feeHistoryModel.js +64 -65
- package/dist/models/psql/feeReminderModel.d.ts +3 -3
- package/dist/models/psql/feeReminderModel.js +32 -32
- package/dist/models/psql/feesCollectionModel.d.ts +4 -4
- package/dist/models/psql/feesCollectionModel.js +36 -37
- package/dist/models/psql/index.d.ts +1 -1
- package/dist/models/psql/index.js +12 -12
- package/dist/models/psql/lectureModel.d.ts +4 -4
- package/dist/models/psql/lectureModel.js +75 -84
- package/dist/models/psql/masterLeaveModel.d.ts +4 -4
- package/dist/models/psql/masterLeaveModel.js +22 -23
- package/dist/models/psql/testimonialModel.d.ts +4 -4
- package/dist/models/psql/testimonialModel.js +25 -27
- package/dist/models/psql/toDoModel.d.ts +4 -4
- package/dist/models/psql/toDoModel.js +23 -23
- package/dist/models/psql/typeManagementModel.d.ts +4 -4
- package/dist/models/psql/typeManagementModel.js +19 -19
- package/dist/models/psql/userModel.d.ts +4 -4
- package/dist/models/psql/userModel.js +47 -48
- package/dist/models/psql/userPayoutModel.d.ts +4 -4
- package/dist/models/psql/userPayoutModel.js +55 -70
- package/dist/services/Concrete/mongooseCommonService.d.ts +4 -4
- package/dist/services/Concrete/mongooseCommonService.js +2 -4
- package/dist/services/Contracts/IMongooseCommonService.d.ts +2 -2
- package/dist/services/Contracts/ISequelizeCommonService.d.ts +12 -12
- package/dist/types/generateIdCardType.d.ts +2 -2
- package/package.json +49 -47
|
@@ -89,8 +89,7 @@ const ChapterFileSchema = new mongoose_1.Schema({
|
|
|
89
89
|
type: Boolean,
|
|
90
90
|
default: false,
|
|
91
91
|
},
|
|
92
|
-
}, { _id: false }
|
|
93
|
-
);
|
|
92
|
+
}, { _id: false });
|
|
94
93
|
const assignedUsersSchema = new mongoose_1.Schema({
|
|
95
94
|
userId: {
|
|
96
95
|
type: String,
|
|
@@ -124,8 +123,7 @@ const assignedUsersSchema = new mongoose_1.Schema({
|
|
|
124
123
|
type: String,
|
|
125
124
|
require: false,
|
|
126
125
|
},
|
|
127
|
-
}, { _id: false }
|
|
128
|
-
);
|
|
126
|
+
}, { _id: false });
|
|
129
127
|
// Define the schema for IChapterIndexAttributes
|
|
130
128
|
const ChapterIndexSchema = new mongoose_1.Schema({
|
|
131
129
|
id: {
|
|
@@ -165,8 +163,7 @@ const ChapterIndexSchema = new mongoose_1.Schema({
|
|
|
165
163
|
type: Boolean,
|
|
166
164
|
default: false,
|
|
167
165
|
},
|
|
168
|
-
}, { _id: false }
|
|
169
|
-
);
|
|
166
|
+
}, { _id: false });
|
|
170
167
|
// Define the schema for ISubjectIndexModelAttributes
|
|
171
168
|
const SubjectIndexSchema = new mongoose_1.Schema({
|
|
172
169
|
title: {
|
|
@@ -236,9 +233,7 @@ const creatOrUpdateHook = async (subjectIndex) => {
|
|
|
236
233
|
throw new Error(errorMessages_js_1.INSTITUTE_ERROR_MESSAGES.NOT_FOUND);
|
|
237
234
|
}
|
|
238
235
|
if (subjectIndex.sharedInstituteId?.length) {
|
|
239
|
-
subjectIndex.sharedInstituteId = [
|
|
240
|
-
...new Set(subjectIndex.sharedInstituteId),
|
|
241
|
-
];
|
|
236
|
+
subjectIndex.sharedInstituteId = [...new Set(subjectIndex.sharedInstituteId)];
|
|
242
237
|
const count = await instituteModel_js_1.default.count({
|
|
243
238
|
where: {
|
|
244
239
|
id: { [sequelize_1.Op.in]: subjectIndex.sharedInstituteId },
|
|
@@ -248,9 +243,7 @@ const creatOrUpdateHook = async (subjectIndex) => {
|
|
|
248
243
|
throw new Error(errorMessages_js_1.INSTITUTE_ERROR_MESSAGES.NOT_FOUND);
|
|
249
244
|
}
|
|
250
245
|
if (subjectIndex.sharedUnverifiedInstituteId?.length) {
|
|
251
|
-
subjectIndex.sharedUnverifiedInstituteId = [
|
|
252
|
-
...new Set(subjectIndex.sharedUnverifiedInstituteId),
|
|
253
|
-
].filter((instituteId) => !subjectIndex?.sharedInstituteId?.includes(instituteId));
|
|
246
|
+
subjectIndex.sharedUnverifiedInstituteId = [...new Set(subjectIndex.sharedUnverifiedInstituteId)].filter(instituteId => !subjectIndex?.sharedInstituteId?.includes(instituteId));
|
|
254
247
|
const count = await instituteModel_js_1.default.count({
|
|
255
248
|
where: {
|
|
256
249
|
id: { [sequelize_1.Op.in]: subjectIndex.sharedUnverifiedInstituteId },
|
|
@@ -264,7 +257,7 @@ const creatOrUpdateHook = async (subjectIndex) => {
|
|
|
264
257
|
where: { id: subjectIndex.subject },
|
|
265
258
|
include: [
|
|
266
259
|
{
|
|
267
|
-
association:
|
|
260
|
+
association: 'entityType',
|
|
268
261
|
where: { sequence: app_js_1.INSTITUTE_ENTITY_TYPE_SEQUENCE.LAST },
|
|
269
262
|
},
|
|
270
263
|
],
|
|
@@ -297,13 +290,12 @@ const creatOrUpdateHook = async (subjectIndex) => {
|
|
|
297
290
|
if (!list.length)
|
|
298
291
|
return true;
|
|
299
292
|
//make unique index aray
|
|
300
|
-
const indexList = list.map(
|
|
293
|
+
const indexList = list.map(one => one.index);
|
|
301
294
|
const tmpArr = [...new Set(indexList)];
|
|
302
295
|
if (tmpArr.length !== indexList.length)
|
|
303
296
|
return false;
|
|
304
297
|
//check index start from 1 and last should be nth;
|
|
305
|
-
if (indexList[0] !== 1 ||
|
|
306
|
-
indexList[indexList.length - 1] !== indexList.length)
|
|
298
|
+
if (indexList[0] !== 1 || indexList[indexList.length - 1] !== indexList.length)
|
|
307
299
|
return false;
|
|
308
300
|
// Sort the array
|
|
309
301
|
indexList.sort((a, b) => a - b);
|
|
@@ -316,52 +308,44 @@ const creatOrUpdateHook = async (subjectIndex) => {
|
|
|
316
308
|
}
|
|
317
309
|
return true;
|
|
318
310
|
};
|
|
319
|
-
const chapterList = subjectIndex.chapterIndex.filter(
|
|
311
|
+
const chapterList = subjectIndex.chapterIndex.filter(chapter => chapter.type === app_js_1.CHAPTER_INDEX_TYPE.CHAPTER);
|
|
320
312
|
if (!isValidIndex(chapterList))
|
|
321
313
|
throw new Error(errorMessages_js_1.SUBJECT_INDEX_ERROR_MESSAGES.INVALID_CHAPTER_INDEX);
|
|
322
314
|
for (const chapter of chapterList) {
|
|
323
|
-
const topicList = subjectIndex.chapterIndex.filter(
|
|
324
|
-
topic.parentId === chapter.id);
|
|
315
|
+
const topicList = subjectIndex.chapterIndex.filter(topic => topic.type === app_js_1.CHAPTER_INDEX_TYPE.TOPIC && topic.parentId === chapter.id);
|
|
325
316
|
if (!isValidIndex(topicList))
|
|
326
317
|
throw new Error(errorMessages_js_1.SUBJECT_INDEX_ERROR_MESSAGES.INVALID_CHAPTER_TOPIC_INDEX);
|
|
327
318
|
for (const topic of topicList) {
|
|
328
|
-
const subTopicList = subjectIndex.chapterIndex.filter(
|
|
329
|
-
subTopic.parentId === topic.id);
|
|
319
|
+
const subTopicList = subjectIndex.chapterIndex.filter(subTopic => subTopic.type === app_js_1.CHAPTER_INDEX_TYPE.SUB_TOPIC && subTopic.parentId === topic.id);
|
|
330
320
|
if (!isValidIndex(subTopicList))
|
|
331
321
|
throw new Error(errorMessages_js_1.SUBJECT_INDEX_ERROR_MESSAGES.INVALID_CHAPTER_SUB_TOPIC_INDEX);
|
|
332
|
-
const topicIndex = subjectIndex.chapterIndex.findIndex(
|
|
322
|
+
const topicIndex = subjectIndex.chapterIndex.findIndex(c => c.id === topic.id);
|
|
333
323
|
if (!subTopicList.length && topic.teachingTime) {
|
|
334
|
-
subjectIndex.chapterIndex[topicIndex].teachingTime =
|
|
335
|
-
topic.teachingTime;
|
|
324
|
+
subjectIndex.chapterIndex[topicIndex].teachingTime = topic.teachingTime;
|
|
336
325
|
}
|
|
337
326
|
else {
|
|
338
|
-
subjectIndex.chapterIndex[topicIndex].teachingTime =
|
|
339
|
-
subTopicList.reduce((sum, subTopic) => sum + (subTopic.teachingTime || 0), 0);
|
|
327
|
+
subjectIndex.chapterIndex[topicIndex].teachingTime = subTopicList.reduce((sum, subTopic) => sum + (subTopic.teachingTime || 0), 0);
|
|
340
328
|
}
|
|
341
329
|
}
|
|
342
|
-
const chapterIndex = subjectIndex.chapterIndex.findIndex(
|
|
330
|
+
const chapterIndex = subjectIndex.chapterIndex.findIndex(c => c.id === chapter.id);
|
|
343
331
|
if (!topicList.length && chapter.teachingTime) {
|
|
344
|
-
subjectIndex.chapterIndex[chapterIndex].teachingTime =
|
|
345
|
-
chapter.teachingTime;
|
|
332
|
+
subjectIndex.chapterIndex[chapterIndex].teachingTime = chapter.teachingTime;
|
|
346
333
|
}
|
|
347
334
|
else {
|
|
348
|
-
subjectIndex.chapterIndex[chapterIndex].teachingTime =
|
|
349
|
-
topicList.reduce((sum, topic) => sum + (topic.teachingTime || 0), 0);
|
|
335
|
+
subjectIndex.chapterIndex[chapterIndex].teachingTime = topicList.reduce((sum, topic) => sum + (topic.teachingTime || 0), 0);
|
|
350
336
|
}
|
|
351
337
|
}
|
|
352
338
|
for (const chapterIndex of subjectIndex.chapterIndex) {
|
|
353
339
|
if (!chapterIndex.id)
|
|
354
340
|
chapterIndex.id = uuid_1.default.v4();
|
|
355
341
|
if (chapterIndex.type !== app_js_1.CHAPTER_INDEX_TYPE.CHAPTER) {
|
|
356
|
-
const parentChapterIndex = subjectIndex.chapterIndex.find(
|
|
342
|
+
const parentChapterIndex = subjectIndex.chapterIndex.find(index => index.id === chapterIndex.parentId);
|
|
357
343
|
if (!parentChapterIndex)
|
|
358
344
|
throw new Error(errorMessages_js_1.SUBJECT_INDEX_ERROR_MESSAGES.INVALID_CHAPTER_TOPIC_INDEX);
|
|
359
|
-
if (chapterIndex.type === app_js_1.CHAPTER_INDEX_TYPE.SUB_TOPIC &&
|
|
360
|
-
parentChapterIndex.type !== app_js_1.CHAPTER_INDEX_TYPE.TOPIC) {
|
|
345
|
+
if (chapterIndex.type === app_js_1.CHAPTER_INDEX_TYPE.SUB_TOPIC && parentChapterIndex.type !== app_js_1.CHAPTER_INDEX_TYPE.TOPIC) {
|
|
361
346
|
throw new Error(errorMessages_js_1.SUBJECT_INDEX_ERROR_MESSAGES.INVALID_CHAPTER_TOPIC_INDEX);
|
|
362
347
|
}
|
|
363
|
-
if (chapterIndex.type === app_js_1.CHAPTER_INDEX_TYPE.TOPIC &&
|
|
364
|
-
parentChapterIndex.type !== app_js_1.CHAPTER_INDEX_TYPE.CHAPTER) {
|
|
348
|
+
if (chapterIndex.type === app_js_1.CHAPTER_INDEX_TYPE.TOPIC && parentChapterIndex.type !== app_js_1.CHAPTER_INDEX_TYPE.CHAPTER) {
|
|
365
349
|
throw new Error(errorMessages_js_1.SUBJECT_INDEX_ERROR_MESSAGES.INVALID_CHAPTER_SUB_TOPIC_INDEX);
|
|
366
350
|
}
|
|
367
351
|
}
|
|
@@ -371,7 +355,7 @@ const creatOrUpdateHook = async (subjectIndex) => {
|
|
|
371
355
|
// subjectIndex.selectedCategoryIds?.includes(file.categoryId as string),
|
|
372
356
|
// );
|
|
373
357
|
// }
|
|
374
|
-
chapterIndex.files = chapterIndex.files.map(
|
|
358
|
+
chapterIndex.files = chapterIndex.files.map(file => {
|
|
375
359
|
if (!file.id)
|
|
376
360
|
file.id = uuid_1.default.v4();
|
|
377
361
|
return file;
|
|
@@ -380,38 +364,34 @@ const creatOrUpdateHook = async (subjectIndex) => {
|
|
|
380
364
|
}
|
|
381
365
|
}
|
|
382
366
|
if (subjectIndex.assignedUsers && subjectIndex.assignedUsers.length) {
|
|
383
|
-
subjectIndex.assignedUsers = (0, utils_js_1.getUniqueArrayByFields)(subjectIndex.assignedUsers, [
|
|
367
|
+
subjectIndex.assignedUsers = (0, utils_js_1.getUniqueArrayByFields)(subjectIndex.assignedUsers, ['userId', 'chapterIndexId']);
|
|
384
368
|
const chapterIndex = [...(subjectIndex.chapterIndex || [])];
|
|
385
369
|
const chapterIndexIdList = chapterIndex
|
|
386
370
|
// .filter(chapter => chapter.type === CHAPTER_INDEX_TYPE.CHAPTER)
|
|
387
|
-
.map(
|
|
371
|
+
.map(chapter => chapter.id);
|
|
388
372
|
// const isValidIndex = subjectIndex.assignedUsers.every(assignedUser => chapterIndexIdList.includes(assignedUser.chapterIndexId));
|
|
389
373
|
// if (!isValidIndex) throw new Error(SUBJECT_INDEX_ERROR_MESSAGES.CAN_NOT_ASSIGN_TO_USER);
|
|
390
|
-
subjectIndex.assignedUsers = subjectIndex.assignedUsers.filter(
|
|
374
|
+
subjectIndex.assignedUsers = subjectIndex.assignedUsers.filter(assignedUser => chapterIndexIdList.includes(assignedUser.chapterIndexId));
|
|
391
375
|
const chapterIndexList = chapterIndex
|
|
392
|
-
.filter(
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
.map((chapter) => {
|
|
396
|
-
const found = subjectIndex?.assignedUsers?.find((assignedUser) => chapter.id === assignedUser.chapterIndexId);
|
|
376
|
+
.filter(chapter => subjectIndex.assignedUsers?.map(assigned => assigned.chapterIndexId).includes(chapter.id))
|
|
377
|
+
.map(chapter => {
|
|
378
|
+
const found = subjectIndex?.assignedUsers?.find(assignedUser => chapter.id === assignedUser.chapterIndexId);
|
|
397
379
|
if (found && found.teachingTime)
|
|
398
380
|
chapter.teachingTime = found.teachingTime;
|
|
399
381
|
return chapter;
|
|
400
382
|
});
|
|
401
|
-
const chapterList = chapterIndexList.filter(
|
|
383
|
+
const chapterList = chapterIndexList.filter(chapter => chapter.type === app_js_1.CHAPTER_INDEX_TYPE.CHAPTER);
|
|
402
384
|
if (!chapterList.length)
|
|
403
385
|
throw new Error(errorMessages_js_1.SUBJECT_INDEX_ERROR_MESSAGES.INVALID_CHAPTER_INDEX);
|
|
404
386
|
for (const chapter of chapterList) {
|
|
405
|
-
const topicList = chapterIndexList.filter(
|
|
406
|
-
topic.parentId === chapter.id);
|
|
387
|
+
const topicList = chapterIndexList.filter(topic => topic.type === app_js_1.CHAPTER_INDEX_TYPE.TOPIC && topic.parentId === chapter.id);
|
|
407
388
|
if (!topicList)
|
|
408
389
|
throw new Error(errorMessages_js_1.SUBJECT_INDEX_ERROR_MESSAGES.INVALID_CHAPTER_TOPIC_INDEX);
|
|
409
390
|
for (const topic of topicList) {
|
|
410
|
-
const subTopicList = chapterIndexList.filter(
|
|
411
|
-
subTopic.parentId === topic.id);
|
|
391
|
+
const subTopicList = chapterIndexList.filter(subTopic => subTopic.type === app_js_1.CHAPTER_INDEX_TYPE.SUB_TOPIC && subTopic.parentId === topic.id);
|
|
412
392
|
if (!subTopicList)
|
|
413
393
|
throw new Error(errorMessages_js_1.SUBJECT_INDEX_ERROR_MESSAGES.INVALID_CHAPTER_SUB_TOPIC_INDEX);
|
|
414
|
-
const topicIndex = chapterIndexList.findIndex(
|
|
394
|
+
const topicIndex = chapterIndexList.findIndex(c => c.id === topic.id);
|
|
415
395
|
if (!subTopicList.length && topic.teachingTime) {
|
|
416
396
|
chapterIndexList[topicIndex].teachingTime = topic.teachingTime;
|
|
417
397
|
}
|
|
@@ -419,7 +399,7 @@ const creatOrUpdateHook = async (subjectIndex) => {
|
|
|
419
399
|
chapterIndexList[topicIndex].teachingTime = subTopicList.reduce((sum, subTopic) => sum + (subTopic.teachingTime || 0), 0);
|
|
420
400
|
}
|
|
421
401
|
}
|
|
422
|
-
const chapterIndex = chapterIndexList.findIndex(
|
|
402
|
+
const chapterIndex = chapterIndexList.findIndex(c => c.id === chapter.id);
|
|
423
403
|
if (!topicList.length && chapter.teachingTime) {
|
|
424
404
|
chapterIndexList[chapterIndex].teachingTime = chapter.teachingTime;
|
|
425
405
|
}
|
|
@@ -428,14 +408,14 @@ const creatOrUpdateHook = async (subjectIndex) => {
|
|
|
428
408
|
}
|
|
429
409
|
}
|
|
430
410
|
subjectIndex.assignedUsers = [
|
|
431
|
-
...subjectIndex.assignedUsers.map(
|
|
432
|
-
const found = chapterIndexList.find(
|
|
411
|
+
...subjectIndex.assignedUsers.map(assignedUser => {
|
|
412
|
+
const found = chapterIndexList.find(chapter => chapter.id === assignedUser.chapterIndexId);
|
|
433
413
|
if (found && found.teachingTime)
|
|
434
414
|
assignedUser.teachingTime = found.teachingTime;
|
|
435
415
|
return assignedUser;
|
|
436
416
|
}),
|
|
437
417
|
];
|
|
438
|
-
let userIdList = subjectIndex.assignedUsers.map(
|
|
418
|
+
let userIdList = subjectIndex.assignedUsers.map(assignedUser => assignedUser.userId);
|
|
439
419
|
userIdList = [...new Set(userIdList)];
|
|
440
420
|
const assignedUsersIdCount = await userModel_js_1.default.count({
|
|
441
421
|
where: {
|
|
@@ -455,22 +435,19 @@ const creatOrUpdateHook = async (subjectIndex) => {
|
|
|
455
435
|
};
|
|
456
436
|
if (subjectIndex.type === app_js_1.SUBJECT_INDEX_TYPE.PRIVATE) {
|
|
457
437
|
where.instituteId = {
|
|
458
|
-
$in: [
|
|
459
|
-
...subjectIndex.sharedInstituteId,
|
|
460
|
-
subjectIndex.instituteId || "",
|
|
461
|
-
],
|
|
438
|
+
$in: [...subjectIndex.sharedInstituteId, subjectIndex.instituteId || ''],
|
|
462
439
|
};
|
|
463
440
|
}
|
|
464
441
|
else {
|
|
465
442
|
where.instituteId = subjectIndex.instituteId;
|
|
466
443
|
}
|
|
467
444
|
const userIntituteMetaList = await userInstituteMetaModel_js_1.default.find({ ...where }, { userId: 1 });
|
|
468
|
-
let allowUserIds = userIntituteMetaList.map(
|
|
445
|
+
let allowUserIds = userIntituteMetaList.map(userIntituteMeta => userIntituteMeta.userId);
|
|
469
446
|
if (subjectIndex.type === app_js_1.SUBJECT_INDEX_TYPE.PRIVATE) {
|
|
470
447
|
allowUserIds.push(subjectIndex.userId);
|
|
471
448
|
}
|
|
472
449
|
allowUserIds = [...new Set(allowUserIds)];
|
|
473
|
-
const notAllowUserIds = subjectIndex.assignedUsers?.filter(
|
|
450
|
+
const notAllowUserIds = subjectIndex.assignedUsers?.filter(assignedUsers => !allowUserIds.includes(assignedUsers.userId));
|
|
474
451
|
if (notAllowUserIds?.length)
|
|
475
452
|
throw new Error(errorMessages_js_1.SUBJECT_INDEX_ERROR_MESSAGES.CAN_NOT_ASSIGN_TO_USER);
|
|
476
453
|
}
|
|
@@ -483,53 +460,47 @@ const addDocsDetailsHook = async (subjectIndexList, where = {}, options = {}) =>
|
|
|
483
460
|
const batchList = await batchModel_js_1.default.findAll({
|
|
484
461
|
where: {
|
|
485
462
|
id: {
|
|
486
|
-
[sequelize_1.Op.in]: subjectIndexList.map(
|
|
463
|
+
[sequelize_1.Op.in]: subjectIndexList.map(subject => subject.batch),
|
|
487
464
|
},
|
|
488
465
|
},
|
|
489
466
|
});
|
|
490
|
-
const batchListById = (0, utils_js_1.keyByFieldOrFields)(batchList,
|
|
467
|
+
const batchListById = (0, utils_js_1.keyByFieldOrFields)(batchList, 'id');
|
|
491
468
|
const subjectList = await instituteEntityModel_js_1.default.findAll({
|
|
492
469
|
where: {
|
|
493
470
|
id: {
|
|
494
|
-
[sequelize_1.Op.in]: subjectIndexList.map(
|
|
471
|
+
[sequelize_1.Op.in]: subjectIndexList.map(subject => subject.subject),
|
|
495
472
|
},
|
|
496
473
|
},
|
|
497
474
|
});
|
|
498
|
-
const subjectListById = (0, utils_js_1.keyByFieldOrFields)(subjectList,
|
|
499
|
-
const userIdSet = new Set(subjectIndexList.flatMap(
|
|
500
|
-
|
|
501
|
-
subject.createdBy,
|
|
502
|
-
]));
|
|
503
|
-
subjectIndexList.forEach((subject) => subject.assignedUsers?.forEach((assign) => userIdSet.add(assign.userId)));
|
|
475
|
+
const subjectListById = (0, utils_js_1.keyByFieldOrFields)(subjectList, 'id');
|
|
476
|
+
const userIdSet = new Set(subjectIndexList.flatMap(subject => [subject.userId, subject.createdBy]));
|
|
477
|
+
subjectIndexList.forEach(subject => subject.assignedUsers?.forEach(assign => userIdSet.add(assign.userId)));
|
|
504
478
|
const userList = await userModel_js_1.default.findAll({
|
|
505
479
|
where: { id: { [sequelize_1.Op.in]: [...userIdSet] } },
|
|
506
480
|
attributes: defaultModelAttributes_js_1.USER_BASIC_DETAIL,
|
|
507
481
|
});
|
|
508
|
-
const userListById = (0, utils_js_1.keyByFieldOrFields)(userList,
|
|
509
|
-
const instituteIdSet = new Set(subjectIndexList.flatMap(
|
|
510
|
-
subject.instituteId,
|
|
511
|
-
...(subject.sharedInstituteId || []),
|
|
512
|
-
]));
|
|
482
|
+
const userListById = (0, utils_js_1.keyByFieldOrFields)(userList, 'id');
|
|
483
|
+
const instituteIdSet = new Set(subjectIndexList.flatMap(subject => [subject.instituteId, ...(subject.sharedInstituteId || [])]));
|
|
513
484
|
const instituteList = await instituteModel_js_1.default.findAll({
|
|
514
485
|
where: { id: { [sequelize_1.Op.in]: [...instituteIdSet] } },
|
|
515
486
|
attributes: defaultModelAttributes_js_1.INSTITUTE_BASIC_DETAIL,
|
|
516
487
|
});
|
|
517
|
-
const instituteListById = (0, utils_js_1.keyByFieldOrFields)(instituteList,
|
|
518
|
-
const fileStorageIdList = subjectIndexList.flatMap(
|
|
488
|
+
const instituteListById = (0, utils_js_1.keyByFieldOrFields)(instituteList, 'id');
|
|
489
|
+
const fileStorageIdList = subjectIndexList.flatMap(subject => subject.chapterIndex?.flatMap(chapter => chapter.files?.map(file => file.fileStorageId) || []) || []);
|
|
519
490
|
const fileStorageList = await fileStorageModel_js_1.default.findAll({
|
|
520
491
|
where: { id: { [sequelize_1.Op.in]: fileStorageIdList } },
|
|
521
492
|
attributes: { exclude: defaultModelAttributes_js_1.DEFAULT_EXCLUDES_ATTRIBUTES },
|
|
522
493
|
raw: true,
|
|
523
494
|
});
|
|
524
|
-
const fileStorageListById = (0, utils_js_1.keyByFieldOrFields)(fileStorageList,
|
|
495
|
+
const fileStorageListById = (0, utils_js_1.keyByFieldOrFields)(fileStorageList, 'id');
|
|
525
496
|
const fileCategoryIdList = subjectIndexList
|
|
526
|
-
.flatMap(
|
|
527
|
-
.filter(
|
|
497
|
+
.flatMap(subject => subject.chapterIndex?.flatMap(chapter => chapter.files?.map(file => file.categoryId) || []) || [])
|
|
498
|
+
.filter(id => (0, utils_js_1.isValidUUID)(id));
|
|
528
499
|
const fileCategoryList = await typeManagementModel_js_1.default.findAll({
|
|
529
500
|
where: { id: { [sequelize_1.Op.in]: fileCategoryIdList } },
|
|
530
501
|
attributes: { exclude: defaultModelAttributes_js_1.DEFAULT_EXCLUDES_ATTRIBUTES },
|
|
531
502
|
});
|
|
532
|
-
const fileCategoryListById = (0, utils_js_1.keyByFieldOrFields)(fileCategoryList,
|
|
503
|
+
const fileCategoryListById = (0, utils_js_1.keyByFieldOrFields)(fileCategoryList, 'id');
|
|
533
504
|
return await Promise.all(
|
|
534
505
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
535
506
|
subjectIndexList.map(async (subject) => {
|
|
@@ -539,17 +510,12 @@ const addDocsDetailsHook = async (subjectIndexList, where = {}, options = {}) =>
|
|
|
539
510
|
subject.subjectDetails = subjectListById[subject.subject] || {};
|
|
540
511
|
subject.instituteDetails = instituteListById[subject.instituteId] || {};
|
|
541
512
|
if (subject.sharedInstituteId?.length) {
|
|
542
|
-
subject.sharedInstituteDetails = subject.sharedInstituteId
|
|
543
|
-
.map((id) => instituteListById[id])
|
|
544
|
-
.filter(Boolean);
|
|
513
|
+
subject.sharedInstituteDetails = subject.sharedInstituteId.map((id) => instituteListById[id]).filter(Boolean);
|
|
545
514
|
}
|
|
546
515
|
if (where.assignedUsers) {
|
|
547
516
|
subject.assignedUsers =
|
|
548
517
|
subject.assignedUsers?.filter((assignedUser) => where.assignedUsers.$elemMatch.userId.$in.includes(assignedUser.userId)) || [];
|
|
549
|
-
const assignedUsersMap = new Map(subject.assignedUsers?.map((assign) => [
|
|
550
|
-
assign.chapterIndexId,
|
|
551
|
-
assign,
|
|
552
|
-
]) || []);
|
|
518
|
+
const assignedUsersMap = new Map(subject.assignedUsers?.map((assign) => [assign.chapterIndexId, assign]) || []);
|
|
553
519
|
subject.chapterIndex = subject.chapterIndex
|
|
554
520
|
?.filter((chapter) => assignedUsersMap.has(chapter.id))
|
|
555
521
|
.map((chapter) => {
|
|
@@ -558,12 +524,10 @@ const addDocsDetailsHook = async (subjectIndexList, where = {}, options = {}) =>
|
|
|
558
524
|
});
|
|
559
525
|
}
|
|
560
526
|
let completedChapterLastLecture = [];
|
|
561
|
-
if (subject.assignedUsers &&
|
|
562
|
-
subject.assignedUsers.length &&
|
|
563
|
-
options?.reqUser?.type === app_js_1.USER_TYPES.STUDENT) {
|
|
527
|
+
if (subject.assignedUsers && subject.assignedUsers.length && options?.reqUser?.type === app_js_1.USER_TYPES.STUDENT) {
|
|
564
528
|
const lectureList = await lectureModel_js_1.default.findAll({
|
|
565
529
|
where: { subject: { [sequelize_1.Op.in]: [subject.subject] } },
|
|
566
|
-
order: [[
|
|
530
|
+
order: [['checkedInAt', 'DESC']],
|
|
567
531
|
limit: 1,
|
|
568
532
|
});
|
|
569
533
|
const lastLecture = lectureList.pop();
|
|
@@ -586,20 +550,14 @@ const addDocsDetailsHook = async (subjectIndexList, where = {}, options = {}) =>
|
|
|
586
550
|
if (chapter.files?.length) {
|
|
587
551
|
if (subject.type === app_js_1.SUBJECT_INDEX_TYPE.BATCH &&
|
|
588
552
|
options.reqUser &&
|
|
589
|
-
[
|
|
590
|
-
|
|
591
|
-
app_js_1.USER_TYPES.PARENTS,
|
|
592
|
-
app_js_1.USER_TYPES.TEACHER,
|
|
593
|
-
].includes(options.reqUser.type)) {
|
|
594
|
-
chapter.files = chapter.files.filter((file) => subject.selectedCategoryIds.includes(file.categoryId));
|
|
553
|
+
[app_js_1.USER_TYPES.STUDENT, app_js_1.USER_TYPES.PARENTS, app_js_1.USER_TYPES.TEACHER].includes(options.reqUser.type)) {
|
|
554
|
+
chapter.files = chapter.files.filter(file => subject.selectedCategoryIds.includes(file.categoryId));
|
|
595
555
|
if (!completedChapterLastLecture.includes(chapter.id))
|
|
596
556
|
chapter.files = [];
|
|
597
557
|
}
|
|
598
558
|
chapter.files = await Promise.all(chapter.files.map(async (file) => {
|
|
599
|
-
file.fileStorageDetails =
|
|
600
|
-
|
|
601
|
-
file.fileCategoryDetails =
|
|
602
|
-
fileCategoryListById[file.categoryId] || {};
|
|
559
|
+
file.fileStorageDetails = fileStorageListById[file.fileStorageId] || {};
|
|
560
|
+
file.fileCategoryDetails = fileCategoryListById[file.categoryId] || {};
|
|
603
561
|
if (file.fileStorageDetails.storageFileName) {
|
|
604
562
|
file.fileStorageDetails.filePath = await (0, s3Uploader_js_1.getPresignedUrl)(env_js_1.ENV_VARIABLE.AWS_BUCKET_NAME, file.fileStorageDetails);
|
|
605
563
|
}
|
|
@@ -608,7 +566,7 @@ const addDocsDetailsHook = async (subjectIndexList, where = {}, options = {}) =>
|
|
|
608
566
|
}
|
|
609
567
|
return chapter;
|
|
610
568
|
}));
|
|
611
|
-
subject.nestChapterIndex = (0, utils_js_1.buildNestedStructure)(subject.chapterIndex,
|
|
569
|
+
subject.nestChapterIndex = (0, utils_js_1.buildNestedStructure)(subject.chapterIndex, 'parentId', 'list');
|
|
612
570
|
}
|
|
613
571
|
if (subject.assignedUsers?.length) {
|
|
614
572
|
subject.assignedUsers = subject.assignedUsers.map((assign) => {
|
|
@@ -619,8 +577,8 @@ const addDocsDetailsHook = async (subjectIndexList, where = {}, options = {}) =>
|
|
|
619
577
|
return subject;
|
|
620
578
|
}));
|
|
621
579
|
};
|
|
622
|
-
const queryHooks = [
|
|
623
|
-
queryHooks.forEach(
|
|
580
|
+
const queryHooks = ['find', 'findOne', 'findById'];
|
|
581
|
+
queryHooks.forEach(hook => {
|
|
624
582
|
SubjectIndexSchema.post(hook, async function (docs) {
|
|
625
583
|
const queryFilter = this.getFilter(); // Get the query filter
|
|
626
584
|
const queryOptions = this.getOptions(); // Get the query filter
|
|
@@ -635,7 +593,7 @@ queryHooks.forEach((hook) => {
|
|
|
635
593
|
}
|
|
636
594
|
});
|
|
637
595
|
});
|
|
638
|
-
SubjectIndexSchema.pre(
|
|
596
|
+
SubjectIndexSchema.pre('save', async function (next) {
|
|
639
597
|
const subjectIndex = this;
|
|
640
598
|
try {
|
|
641
599
|
await creatOrUpdateHook(subjectIndex);
|
|
@@ -645,7 +603,7 @@ SubjectIndexSchema.pre("save", async function (next) {
|
|
|
645
603
|
throw error;
|
|
646
604
|
}
|
|
647
605
|
});
|
|
648
|
-
SubjectIndexSchema.pre(
|
|
606
|
+
SubjectIndexSchema.pre('updateMany', async function (next) {
|
|
649
607
|
const subjectIndex = this.getUpdate();
|
|
650
608
|
try {
|
|
651
609
|
await creatOrUpdateHook(subjectIndex);
|
|
@@ -660,7 +618,7 @@ SubjectIndexSchema.index({
|
|
|
660
618
|
type: 1,
|
|
661
619
|
subject: 1,
|
|
662
620
|
});
|
|
663
|
-
const SubjectIndexModel = mongoose_1.default.model(
|
|
621
|
+
const SubjectIndexModel = mongoose_1.default.model('subject_indexes', SubjectIndexSchema);
|
|
664
622
|
// (async () => {
|
|
665
623
|
// await SubjectIndexModel.syncIndexes();
|
|
666
624
|
// })(); // Rebuilds indexes in DB based on schema
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Model } from
|
|
2
|
-
import { ISubscriptionPlanModelAttributes } from
|
|
1
|
+
import { Model } from 'mongoose';
|
|
2
|
+
import { ISubscriptionPlanModelAttributes } from '../../interfaces/subscriptionPlanInterface.js';
|
|
3
3
|
declare const SubscriptionPlanModel: Model<ISubscriptionPlanModelAttributes>;
|
|
4
4
|
export default SubscriptionPlanModel;
|
|
@@ -132,5 +132,5 @@ const subscriptionPlanModelSchema = new mongoose_1.Schema({
|
|
|
132
132
|
timestamps: true,
|
|
133
133
|
versionKey: false,
|
|
134
134
|
});
|
|
135
|
-
const SubscriptionPlanModel = mongoose_1.default.model(
|
|
135
|
+
const SubscriptionPlanModel = mongoose_1.default.model('subscription_plans', subscriptionPlanModelSchema);
|
|
136
136
|
exports.default = SubscriptionPlanModel;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Model } from
|
|
2
|
-
import { ITaskManagementModelAttributes } from
|
|
1
|
+
import { Model } from 'mongoose';
|
|
2
|
+
import { ITaskManagementModelAttributes } from '../../interfaces/taskManagementInterface.js';
|
|
3
3
|
declare const TaskManagementModel: Model<ITaskManagementModelAttributes>;
|
|
4
4
|
export default TaskManagementModel;
|
|
@@ -143,7 +143,7 @@ const creatOrUpdateHook = async (task) => {
|
|
|
143
143
|
throw error;
|
|
144
144
|
}
|
|
145
145
|
};
|
|
146
|
-
TaskManagementModelSchema.pre(
|
|
146
|
+
TaskManagementModelSchema.pre('save', async function (next) {
|
|
147
147
|
const task = this;
|
|
148
148
|
try {
|
|
149
149
|
await creatOrUpdateHook(task);
|
|
@@ -153,7 +153,7 @@ TaskManagementModelSchema.pre("save", async function (next) {
|
|
|
153
153
|
throw error;
|
|
154
154
|
}
|
|
155
155
|
});
|
|
156
|
-
TaskManagementModelSchema.pre(
|
|
156
|
+
TaskManagementModelSchema.pre('updateMany', async function (next) {
|
|
157
157
|
const task = this.getUpdate();
|
|
158
158
|
try {
|
|
159
159
|
await creatOrUpdateHook(task);
|
|
@@ -163,5 +163,5 @@ TaskManagementModelSchema.pre("updateMany", async function (next) {
|
|
|
163
163
|
throw error;
|
|
164
164
|
}
|
|
165
165
|
});
|
|
166
|
-
const TaskManagementModel = mongoose_1.default.model(
|
|
166
|
+
const TaskManagementModel = mongoose_1.default.model('task_managements', TaskManagementModelSchema);
|
|
167
167
|
exports.default = TaskManagementModel;
|
|
@@ -6,4 +6,4 @@ const UserSchema = new mongoose_1.Schema({
|
|
|
6
6
|
name: { type: String, required: true },
|
|
7
7
|
email: { type: String, required: true, unique: true },
|
|
8
8
|
}, { timestamps: true });
|
|
9
|
-
exports.UserDoc = (0, mongoose_1.model)(
|
|
9
|
+
exports.UserDoc = (0, mongoose_1.model)('User', UserSchema);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IUserSchoolMetaModelAttributes } from
|
|
1
|
+
import { IUserSchoolMetaModelAttributes } from '../../interfaces/userSchoolMetaInterface.js';
|
|
2
2
|
declare const UserSchoolMetaModel: import("mongoose").Model<IUserSchoolMetaModelAttributes, {}, {}, {}, import("mongoose").Document<unknown, {}, IUserSchoolMetaModelAttributes, {}, {}> & IUserSchoolMetaModelAttributes & Required<{
|
|
3
3
|
_id: unknown;
|
|
4
4
|
}> & {
|
|
@@ -456,7 +456,7 @@ const userSchoolMetaModelSchema = new mongoose_1.Schema({
|
|
|
456
456
|
timestamps: true,
|
|
457
457
|
versionKey: false,
|
|
458
458
|
});
|
|
459
|
-
userSchoolMetaModelSchema.pre(
|
|
459
|
+
userSchoolMetaModelSchema.pre('save', async function (next) {
|
|
460
460
|
const userSchoolMeta = this;
|
|
461
461
|
try {
|
|
462
462
|
await Promise.all([
|
|
@@ -484,17 +484,17 @@ userSchoolMetaModelSchema.pre("save", async function (next) {
|
|
|
484
484
|
if (correspondent.city) {
|
|
485
485
|
const cityExists = await cityModel_js_1.default.findByPk(correspondent.city);
|
|
486
486
|
if (!cityExists)
|
|
487
|
-
throw new Error(
|
|
487
|
+
throw new Error('City not found');
|
|
488
488
|
}
|
|
489
489
|
if (correspondent.state) {
|
|
490
490
|
const stateExists = await stateModel_js_1.default.findByPk(correspondent.state);
|
|
491
491
|
if (!stateExists)
|
|
492
|
-
throw new Error(
|
|
492
|
+
throw new Error('State not found');
|
|
493
493
|
}
|
|
494
494
|
if (correspondent.country) {
|
|
495
495
|
const countryExists = await countryModel_js_1.default.findByPk(correspondent.country);
|
|
496
496
|
if (!countryExists)
|
|
497
|
-
throw new Error(
|
|
497
|
+
throw new Error('Country not found');
|
|
498
498
|
}
|
|
499
499
|
}));
|
|
500
500
|
}
|
|
@@ -505,17 +505,17 @@ userSchoolMetaModelSchema.pre("save", async function (next) {
|
|
|
505
505
|
if (trust.city) {
|
|
506
506
|
const cityExists = await cityModel_js_1.default.findByPk(trust.city);
|
|
507
507
|
if (!cityExists)
|
|
508
|
-
throw new Error(
|
|
508
|
+
throw new Error('City not found');
|
|
509
509
|
}
|
|
510
510
|
if (trust.state) {
|
|
511
511
|
const stateExists = await stateModel_js_1.default.findByPk(trust.state);
|
|
512
512
|
if (!stateExists)
|
|
513
|
-
throw new Error(
|
|
513
|
+
throw new Error('State not found');
|
|
514
514
|
}
|
|
515
515
|
if (trust.country) {
|
|
516
516
|
const countryExists = await countryModel_js_1.default.findByPk(trust.country);
|
|
517
517
|
if (!countryExists)
|
|
518
|
-
throw new Error(
|
|
518
|
+
throw new Error('Country not found');
|
|
519
519
|
}
|
|
520
520
|
}));
|
|
521
521
|
}
|
|
@@ -548,5 +548,5 @@ userSchoolMetaModelSchema.pre("save", async function (next) {
|
|
|
548
548
|
// );
|
|
549
549
|
// }
|
|
550
550
|
// }
|
|
551
|
-
const UserSchoolMetaModel = (0, mongoose_1.model)(
|
|
551
|
+
const UserSchoolMetaModel = (0, mongoose_1.model)('UserSchoolMeta', userSchoolMetaModelSchema);
|
|
552
552
|
exports.default = UserSchoolMetaModel;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Model } from
|
|
2
|
-
import { IAnnouncementModelAttributes } from
|
|
3
|
-
import { TAnnouncementModelCreationAttributes } from
|
|
4
|
-
import { ANNOUCEMENT_SCHEDULE_TYPE, ANNOUCEMENT_STATUS, USER_TYPES } from
|
|
1
|
+
import { Model } from 'sequelize';
|
|
2
|
+
import { IAnnouncementModelAttributes } from '../../interfaces/announcementInterface.js';
|
|
3
|
+
import { TAnnouncementModelCreationAttributes } from '../../types/announcementType.js';
|
|
4
|
+
import { ANNOUCEMENT_SCHEDULE_TYPE, ANNOUCEMENT_STATUS, USER_TYPES } from '../../constants/app.js';
|
|
5
5
|
declare class AnnouncementModel extends Model<IAnnouncementModelAttributes, TAnnouncementModelCreationAttributes> {
|
|
6
6
|
id: string;
|
|
7
7
|
title: string;
|