@kipicore/dbcore 1.1.30 → 1.1.33
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/dist/models/psql/SubCategoriesModel.d.ts +1 -0
- package/dist/models/psql/SubCategoriesModel.js +60 -63
- package/dist/models/psql/academicCalendarModel.d.ts +2 -1
- package/dist/models/psql/academicCalendarModel.js +41 -53
- package/dist/models/psql/accountHasReceiptDetailsModel.d.ts +6 -5
- package/dist/models/psql/accountHasReceiptDetailsModel.js +47 -68
- package/dist/models/psql/announcementModel.d.ts +10 -8
- package/dist/models/psql/announcementModel.js +90 -109
- package/dist/models/psql/areaModel.d.ts +5 -1
- package/dist/models/psql/areaModel.js +13 -12
- package/dist/models/psql/bankAccountDetailsModel.d.ts +6 -5
- package/dist/models/psql/bankAccountDetailsModel.js +25 -37
- package/dist/models/psql/bannerModel.d.ts +18 -18
- package/dist/models/psql/bannerModel.js +53 -81
- package/dist/models/psql/batchModel.d.ts +3 -1
- package/dist/models/psql/batchModel.js +77 -135
- package/dist/models/psql/batchSubjectBookAssessmentModel.d.ts +2 -1
- package/dist/models/psql/batchSubjectBookAssessmentModel.js +57 -104
- package/dist/models/psql/batchSubjectProjectAssessmentModel.d.ts +2 -1
- package/dist/models/psql/batchSubjectProjectAssessmentModel.js +59 -92
- package/dist/models/psql/bookAssessmentDateModel.d.ts +2 -1
- package/dist/models/psql/bookAssessmentDateModel.js +26 -46
- package/dist/models/psql/categoriesModel.d.ts +2 -1
- package/dist/models/psql/categoriesModel.js +25 -45
- package/dist/models/psql/cityModel.d.ts +2 -1
- package/dist/models/psql/cityModel.js +21 -33
- package/dist/models/psql/classRoomModel.d.ts +2 -1
- package/dist/models/psql/classRoomModel.js +41 -67
- package/dist/models/psql/cloudStorageModel.d.ts +2 -1
- package/dist/models/psql/cloudStorageModel.js +18 -29
- package/dist/models/psql/coinPurchaseOfferModel.d.ts +5 -4
- package/dist/models/psql/coinPurchaseOfferModel.js +18 -29
- package/dist/models/psql/contactFeedBackModel.d.ts +2 -1
- package/dist/models/psql/contactFeedBackModel.js +49 -62
- package/dist/models/psql/countryModel.d.ts +1 -1
- package/dist/models/psql/countryModel.js +2 -0
- package/dist/models/psql/courseHasVisitorsModel.d.ts +2 -1
- package/dist/models/psql/courseHasVisitorsModel.js +25 -38
- package/dist/models/psql/courseModel.d.ts +2 -1
- package/dist/models/psql/courseModel.js +41 -56
- package/dist/models/psql/driverModel.d.ts +3 -1
- package/dist/models/psql/driverModel.js +61 -65
- package/dist/models/psql/entityGroupModel.d.ts +2 -1
- package/dist/models/psql/entityGroupModel.js +25 -45
- package/dist/models/psql/facilityModel.d.ts +3 -1
- package/dist/models/psql/facilityModel.js +63 -73
- package/dist/models/psql/featureActionModel.d.ts +3 -2
- package/dist/models/psql/featureActionModel.js +21 -36
- package/dist/models/psql/feeHistoryDetailsModel.d.ts +2 -1
- package/dist/models/psql/feeHistoryDetailsModel.js +65 -106
- package/dist/models/psql/feeHistoryModel.d.ts +4 -2
- package/dist/models/psql/feeHistoryModel.js +154 -309
- package/dist/models/psql/feeReminderModel.d.ts +2 -0
- package/dist/models/psql/feeReminderModel.js +147 -179
- package/dist/models/psql/feeReminderSettingModel.d.ts +1 -0
- package/dist/models/psql/feeReminderSettingModel.js +23 -47
- package/dist/models/psql/feeTypeHasTermsModel.d.ts +1 -0
- package/dist/models/psql/feeTypeHasTermsModel.js +48 -51
- package/dist/models/psql/feeTypeModel.d.ts +1 -0
- package/dist/models/psql/feeTypeModel.js +44 -72
- package/dist/models/psql/feesCollectionModel.d.ts +2 -0
- package/dist/models/psql/feesCollectionModel.js +112 -144
- package/dist/models/psql/fileStorageModel.d.ts +1 -0
- package/dist/models/psql/fileStorageModel.js +27 -29
- package/dist/models/psql/floorManagementModel.d.ts +1 -0
- package/dist/models/psql/floorManagementModel.js +23 -42
- package/dist/models/psql/greetingsModel.d.ts +3 -2
- package/dist/models/psql/greetingsModel.js +64 -66
- package/dist/models/psql/homeWorkModel.d.ts +1 -0
- package/dist/models/psql/homeWorkModel.js +40 -70
- package/dist/models/psql/index.js +6 -3
- package/dist/models/psql/instituteEntityModel.d.ts +1 -0
- package/dist/models/psql/instituteEntityModel.js +59 -62
- package/dist/models/psql/instituteEntityTypeModel.d.ts +1 -0
- package/dist/models/psql/instituteEntityTypeModel.js +15 -28
- package/dist/models/psql/instituteModel.d.ts +1 -0
- package/dist/models/psql/instituteModel.js +66 -185
- package/dist/models/psql/instituteSubscriptionPlanModel.d.ts +1 -0
- package/dist/models/psql/instituteSubscriptionPlanModel.js +40 -81
- package/dist/models/psql/inventoryHistoryModel.d.ts +1 -0
- package/dist/models/psql/inventoryHistoryModel.js +39 -79
- package/dist/models/psql/inventoryModel.d.ts +1 -0
- package/dist/models/psql/inventoryModel.js +31 -62
- package/dist/models/psql/lectureHistoryModel.d.ts +1 -0
- package/dist/models/psql/lectureHistoryModel.js +65 -196
- package/dist/models/psql/lectureModel.d.ts +2 -0
- package/dist/models/psql/lectureModel.js +191 -454
- package/dist/models/psql/masterLeaveModel.d.ts +2 -0
- package/dist/models/psql/masterLeaveModel.js +71 -71
- package/dist/models/psql/moduleFeatureModel.d.ts +1 -0
- package/dist/models/psql/moduleFeatureModel.js +41 -44
- package/dist/models/psql/moduleModel.d.ts +1 -0
- package/dist/models/psql/moduleModel.js +48 -52
- package/dist/models/psql/offerModel.d.ts +1 -0
- package/dist/models/psql/offerModel.js +43 -64
- package/dist/models/psql/paymentTermsModel.d.ts +1 -0
- package/dist/models/psql/paymentTermsModel.js +43 -45
- package/dist/models/psql/pdcChequeModel.d.ts +1 -0
- package/dist/models/psql/pdcChequeModel.js +59 -64
- package/dist/models/psql/pdcHistoryModel.d.ts +1 -0
- package/dist/models/psql/pdcHistoryModel.js +55 -73
- package/dist/models/psql/pincodeModel.d.ts +1 -0
- package/dist/models/psql/pincodeModel.js +6 -9
- package/dist/models/psql/productModel.d.ts +1 -0
- package/dist/models/psql/productModel.js +40 -80
- package/dist/models/psql/projectAssessmentOptionModel.d.ts +1 -0
- package/dist/models/psql/projectAssessmentOptionModel.js +23 -45
- package/dist/models/psql/roleModel.d.ts +1 -0
- package/dist/models/psql/roleModel.js +15 -38
- package/dist/models/psql/rulesRegulationModel.d.ts +3 -2
- package/dist/models/psql/rulesRegulationModel.js +20 -33
- package/dist/models/psql/schoolFeeCollectionModel.d.ts +1 -0
- package/dist/models/psql/schoolFeeCollectionModel.js +47 -94
- package/dist/models/psql/schoolOfferModel.d.ts +1 -0
- package/dist/models/psql/schoolOfferModel.js +39 -78
- package/dist/models/psql/sendNotificationModel.d.ts +1 -0
- package/dist/models/psql/sendNotificationModel.js +37 -61
- package/dist/models/psql/slotModel.d.ts +2 -0
- package/dist/models/psql/slotModel.js +46 -58
- package/dist/models/psql/stateModel.d.ts +1 -0
- package/dist/models/psql/stateModel.js +17 -18
- package/dist/models/psql/subjectHasFeeModel.d.ts +1 -0
- package/dist/models/psql/subjectHasFeeModel.js +49 -46
- package/dist/models/psql/subjectHasPayFeeHistoryModel.d.ts +1 -0
- package/dist/models/psql/subjectHasPayFeeHistoryModel.js +74 -69
- package/dist/models/psql/syllabusModel.d.ts +1 -0
- package/dist/models/psql/syllabusModel.js +72 -85
- package/dist/models/psql/testimonialModel.d.ts +2 -0
- package/dist/models/psql/testimonialModel.js +97 -100
- package/dist/models/psql/toDoModel.d.ts +2 -0
- package/dist/models/psql/toDoModel.js +64 -64
- package/dist/models/psql/tripModel.d.ts +1 -0
- package/dist/models/psql/tripModel.js +51 -55
- package/dist/models/psql/typeManagementModel.d.ts +2 -0
- package/dist/models/psql/typeManagementModel.js +69 -69
- package/dist/models/psql/userBookAssessmentModel.d.ts +1 -0
- package/dist/models/psql/userBookAssessmentModel.js +83 -89
- package/dist/models/psql/userFeeTypeByAccountModel.d.ts +1 -0
- package/dist/models/psql/userFeeTypeByAccountModel.js +117 -122
- package/dist/models/psql/userFeeTypeModel.d.ts +1 -0
- package/dist/models/psql/userFeeTypeModel.js +97 -102
- package/dist/models/psql/userHasAnnouncementModel.d.ts +1 -0
- package/dist/models/psql/userHasAnnouncementModel.js +63 -66
- package/dist/models/psql/userHasBatchModel.d.ts +1 -0
- package/dist/models/psql/userHasBatchModel.js +55 -57
- package/dist/models/psql/userHasCourseModel.d.ts +1 -0
- package/dist/models/psql/userHasCourseModel.js +51 -55
- package/dist/models/psql/userHasDeviceModel.d.ts +1 -0
- package/dist/models/psql/userHasDeviceModel.js +35 -38
- package/dist/models/psql/userHasFeeTermsModel.d.ts +1 -0
- package/dist/models/psql/userHasFeeTermsModel.js +51 -117
- package/dist/models/psql/userHasFileModel.d.ts +1 -0
- package/dist/models/psql/userHasFileModel.js +33 -61
- package/dist/models/psql/userHasHomeWorkModel.d.ts +9 -6
- package/dist/models/psql/userHasHomeWorkModel.js +50 -72
- package/dist/models/psql/userHasInventoryHistoryModel.d.ts +5 -4
- package/dist/models/psql/userHasInventoryHistoryModel.js +42 -59
- package/dist/models/psql/userHasInventoryModel.d.ts +5 -4
- package/dist/models/psql/userHasInventoryModel.js +30 -54
- package/dist/models/psql/userHasLeaveHistoryModel.d.ts +5 -4
- package/dist/models/psql/userHasLeaveHistoryModel.js +21 -36
- package/dist/models/psql/userHasLeaveModel.d.ts +6 -5
- package/dist/models/psql/userHasLeaveModel.js +47 -68
- package/dist/models/psql/userHasOfferModel.d.ts +8 -7
- package/dist/models/psql/userHasOfferModel.js +54 -109
- package/dist/models/psql/userHasParentModel.d.ts +7 -5
- package/dist/models/psql/userHasParentModel.js +38 -65
- package/dist/models/psql/userHasRoleModel.d.ts +6 -5
- package/dist/models/psql/userHasRoleModel.js +27 -56
- package/dist/models/psql/userHasRollNumberModel.d.ts +5 -4
- package/dist/models/psql/userHasRollNumberModel.js +39 -54
- package/dist/models/psql/userHasStorageModel.d.ts +5 -4
- package/dist/models/psql/userHasStorageModel.js +31 -35
- package/dist/models/psql/userHasSubjectFeeModel.d.ts +5 -4
- package/dist/models/psql/userHasSubjectFeeModel.js +32 -47
- package/dist/models/psql/userLeaveRequestModel.d.ts +6 -5
- package/dist/models/psql/userLeaveRequestModel.js +24 -40
- package/dist/models/psql/userModel.d.ts +2 -2
- package/dist/models/psql/userModel.js +174 -370
- package/dist/models/psql/userPayoutDetailsModel.d.ts +1 -0
- package/dist/models/psql/userPayoutDetailsModel.js +65 -146
- package/dist/models/psql/userPayoutHistoryModel.d.ts +1 -0
- package/dist/models/psql/userPayoutHistoryModel.js +39 -66
- package/dist/models/psql/userPayoutModel.d.ts +2 -0
- package/dist/models/psql/userPayoutModel.js +205 -240
- package/dist/models/psql/userProjectAssessmentOptionModel.d.ts +1 -0
- package/dist/models/psql/userProjectAssessmentOptionModel.js +39 -74
- package/dist/models/psql/userRequiredStepsModel.d.ts +1 -0
- package/dist/models/psql/userRequiredStepsModel.js +23 -36
- package/dist/models/psql/vehicleModel.d.ts +1 -0
- package/dist/models/psql/vehicleModel.js +27 -53
- package/dist/models/psql/vendorManagementModel.d.ts +6 -5
- package/dist/models/psql/vendorManagementModel.js +48 -97
- package/dist/models/psql/walletHistoryModel.d.ts +2 -1
- package/dist/models/psql/walletHistoryModel.js +31 -33
- package/dist/models/psql/walletModel.d.ts +2 -1
- package/dist/models/psql/walletModel.js +28 -46
- package/dist/models/psql/workingDayModel.d.ts +3 -2
- package/dist/models/psql/workingDayModel.js +18 -31
- package/dist/models/psql/workingShiftModel.d.ts +3 -2
- package/dist/models/psql/workingShiftModel.js +43 -40
- package/dist/types/accountHasReceiptDetailsType.d.ts +1 -1
- package/dist/types/bannerType.d.ts +1 -1
- package/dist/types/batchSubjectBookAssessmentType.d.ts +1 -1
- package/dist/types/batchSubjectProjectAssessmentType.d.ts +1 -1
- package/dist/types/batchType.d.ts +1 -1
- package/dist/types/bookAssessmentDateType.d.ts +1 -1
- package/dist/types/examType.d.ts +1 -1
- package/dist/types/feeHistoryType.d.ts +1 -1
- package/dist/types/greetingsType.d.ts +1 -1
- package/dist/types/holidayType.js +1 -1
- package/dist/types/paymentTermsType.js +1 -1
- package/dist/types/projectAssessmentOptionType.d.ts +1 -1
- package/dist/types/subjectIndexType.d.ts +1 -1
- package/dist/types/syllabusType.d.ts +1 -1
- package/dist/types/testimonialType.d.ts +1 -1
- package/dist/types/userBookAssessmentType.d.ts +1 -1
- package/dist/types/userHasBatchType.d.ts +1 -1
- package/dist/types/userProjectAssessmentOptionType.d.ts +1 -1
- package/package.json +1 -1
|
@@ -1,20 +1,216 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
const sequelize_1 = require("sequelize");
|
|
7
4
|
const index_1 = require("./index");
|
|
8
5
|
const app_1 = require("../../constants/app");
|
|
9
|
-
const userModel_1 = __importDefault(require("./userModel"));
|
|
10
|
-
const instituteModel_1 = __importDefault(require("./instituteModel"));
|
|
11
6
|
const date_fns_1 = require("date-fns");
|
|
12
7
|
const utils_1 = require("../../helpers/utils");
|
|
13
|
-
const subjectHasPayFeeHistoryModel_1 = __importDefault(require("./subjectHasPayFeeHistoryModel"));
|
|
14
|
-
const lectureModel_1 = __importDefault(require("./lectureModel"));
|
|
15
|
-
const attendanceModel_1 = __importDefault(require("../mongodb/attendanceModel"));
|
|
16
|
-
const userPayoutDetailsModel_1 = __importDefault(require("./userPayoutDetailsModel"));
|
|
17
8
|
class UserPayoutModel extends sequelize_1.Model {
|
|
9
|
+
static associate(models) {
|
|
10
|
+
const { UserModel, InstituteModel, UserPayoutDetailsModel } = models;
|
|
11
|
+
UserPayoutModel.belongsTo(UserModel, {
|
|
12
|
+
foreignKey: { name: 'createdBy', allowNull: true, field: 'created_by' },
|
|
13
|
+
as: 'createdByUser',
|
|
14
|
+
});
|
|
15
|
+
UserPayoutModel.belongsTo(UserModel, {
|
|
16
|
+
foreignKey: { name: 'updatedBy', allowNull: true, field: 'updated_by' },
|
|
17
|
+
as: 'updatedByUser',
|
|
18
|
+
});
|
|
19
|
+
UserPayoutModel.belongsTo(UserModel, {
|
|
20
|
+
foreignKey: { name: 'deletedBy', allowNull: true, field: 'deleted_by' },
|
|
21
|
+
as: 'deletedByUser',
|
|
22
|
+
});
|
|
23
|
+
UserPayoutModel.belongsTo(InstituteModel, {
|
|
24
|
+
foreignKey: { name: 'instituteId' },
|
|
25
|
+
as: 'institute',
|
|
26
|
+
});
|
|
27
|
+
InstituteModel.hasMany(UserPayoutModel, {
|
|
28
|
+
foreignKey: { name: 'instituteId' },
|
|
29
|
+
as: 'instituteHasPayoutList',
|
|
30
|
+
});
|
|
31
|
+
UserPayoutModel.belongsTo(UserModel, {
|
|
32
|
+
foreignKey: { name: 'userId' },
|
|
33
|
+
as: 'user',
|
|
34
|
+
});
|
|
35
|
+
UserModel.hasMany(UserPayoutModel, {
|
|
36
|
+
foreignKey: { name: 'userId' },
|
|
37
|
+
as: 'userHasPayoutList',
|
|
38
|
+
});
|
|
39
|
+
UserPayoutModel.hasMany(UserPayoutDetailsModel, {
|
|
40
|
+
foreignKey: { name: 'userPayoutId' },
|
|
41
|
+
as: 'userPayoutDetailsList',
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
static addHooks(models) {
|
|
45
|
+
const { UserPayoutDetailsModel, SubjectHasPayFeeHistory, LectureModel, AttendanceModel } = models;
|
|
46
|
+
const afterCreateOrUpdateHook = async (userPayout, user = null, transaction, filterOptions = {}) => {
|
|
47
|
+
try {
|
|
48
|
+
if (!userPayout.userPayoutDetailsList || !userPayout.userPayoutDetailsList.length)
|
|
49
|
+
return userPayout;
|
|
50
|
+
userPayout.userPayoutDetailsList = (0, utils_1.getUniqueArrayByFields)(userPayout.userPayoutDetailsList, ['subjectId']);
|
|
51
|
+
const options = { transaction };
|
|
52
|
+
if (user)
|
|
53
|
+
options.userId = user.id;
|
|
54
|
+
const now = new Date();
|
|
55
|
+
const previousMonthDate = (0, date_fns_1.subMonths)(now, 1);
|
|
56
|
+
let startOfPreviousMonth = (0, date_fns_1.startOfMonth)(previousMonthDate).toISOString();
|
|
57
|
+
let endOfPreviousMonth = (0, date_fns_1.endOfMonth)(previousMonthDate).toISOString();
|
|
58
|
+
if (filterOptions.include) {
|
|
59
|
+
filterOptions.include = !Array.isArray(filterOptions.include) ? [filterOptions.include] : filterOptions.include;
|
|
60
|
+
const historyListInclude = filterOptions.include.find((include) => include.as === 'userPayoutHistoryList');
|
|
61
|
+
let where = {};
|
|
62
|
+
if (historyListInclude && historyListInclude.where && historyListInclude.where[sequelize_1.Op.and]) {
|
|
63
|
+
where = historyListInclude.where[sequelize_1.Op.and].pop();
|
|
64
|
+
}
|
|
65
|
+
if (where.payout_start_time && where.payout_end_time) {
|
|
66
|
+
startOfPreviousMonth = where.payout_start_time[sequelize_1.Op.gte];
|
|
67
|
+
endOfPreviousMonth = where.payout_end_time[sequelize_1.Op.lte];
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
const attendanceWhereAnd = [{ date: { $gte: startOfPreviousMonth } }, { date: { $lte: endOfPreviousMonth } }];
|
|
71
|
+
const existUserPayout = (await UserPayoutModel.findOne({
|
|
72
|
+
where: { id: userPayout.id },
|
|
73
|
+
include: [{ association: 'userPayoutDetailsList' }],
|
|
74
|
+
transaction,
|
|
75
|
+
}));
|
|
76
|
+
if (!existUserPayout)
|
|
77
|
+
return userPayout;
|
|
78
|
+
if (userPayout.type === app_1.USER_PAYOUT_TYPE.PERCENTAGE) {
|
|
79
|
+
let feeTotalBySubjectList = await SubjectHasPayFeeHistory.findAll({
|
|
80
|
+
where: {
|
|
81
|
+
instituteId: existUserPayout.instituteId,
|
|
82
|
+
subjectId: {
|
|
83
|
+
[sequelize_1.Op.in]: userPayout.userPayoutDetailsList.map(detail => detail.subjectId),
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
attributes: [
|
|
87
|
+
['subject_id', 'subjectId'],
|
|
88
|
+
[sequelize_1.Sequelize.fn('sum', sequelize_1.Sequelize.col('amount')), 'amount'],
|
|
89
|
+
],
|
|
90
|
+
group: ['subject_id', 'created_at'],
|
|
91
|
+
raw: true,
|
|
92
|
+
});
|
|
93
|
+
feeTotalBySubjectList = JSON.parse(JSON.stringify(feeTotalBySubjectList));
|
|
94
|
+
userPayout.userPayoutDetailsList = userPayout.userPayoutDetailsList.map(detail => {
|
|
95
|
+
detail.payableAmount = feeTotalBySubjectList
|
|
96
|
+
.filter((fee) => fee.subjectId === detail.subjectId)
|
|
97
|
+
.reduce((sum, record) => {
|
|
98
|
+
if (detail.percentage) {
|
|
99
|
+
const amount = ((record.amount || 0) * detail.percentage) / 100;
|
|
100
|
+
return sum + parseFloat(amount.toFixed(2));
|
|
101
|
+
}
|
|
102
|
+
return sum;
|
|
103
|
+
}, 0);
|
|
104
|
+
return detail;
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
if (userPayout.type === app_1.USER_PAYOUT_TYPE.HOURLY) {
|
|
108
|
+
let lectureList = (await LectureModel.findAll({
|
|
109
|
+
where: {
|
|
110
|
+
instituteId: existUserPayout.instituteId,
|
|
111
|
+
subject: {
|
|
112
|
+
[sequelize_1.Op.in]: userPayout.userPayoutDetailsList.map(detail => detail.subjectId),
|
|
113
|
+
},
|
|
114
|
+
[sequelize_1.Op.or]: [{ primaryUserId: existUserPayout.userId }, { secondaryUserId: existUserPayout.userId }],
|
|
115
|
+
},
|
|
116
|
+
include: [{ association: 'workingDay' }],
|
|
117
|
+
}));
|
|
118
|
+
lectureList = JSON.parse(JSON.stringify(lectureList));
|
|
119
|
+
const currentMonthAttendanceList = await AttendanceModel.find({
|
|
120
|
+
$and: attendanceWhereAnd,
|
|
121
|
+
userType: userPayout.userType,
|
|
122
|
+
'users.userId': userPayout.userId,
|
|
123
|
+
'users.status': { $ne: app_1.ATTENDANCE_STATUS.ABSENT },
|
|
124
|
+
});
|
|
125
|
+
userPayout.userPayoutDetailsList = userPayout.userPayoutDetailsList.map(detail => {
|
|
126
|
+
let totalMinutes = 0;
|
|
127
|
+
currentMonthAttendanceList.forEach((attendance) => {
|
|
128
|
+
const dayName = (0, date_fns_1.format)(attendance.date, 'EEEE');
|
|
129
|
+
const lecturesByDay = lectureList.filter(lecture => lecture.workingDay.dayName === dayName && lecture.subject === detail.subjectId);
|
|
130
|
+
if (lecturesByDay.length) {
|
|
131
|
+
totalMinutes += lecturesByDay.reduce((sum, record) => sum + record.slotDuration, 0);
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
detail.payableAmount = ((detail.amountPerHour || 0) / app_1.SIXTY) * totalMinutes;
|
|
135
|
+
return detail;
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
const userPayoutDetailsList = [];
|
|
139
|
+
for (let detail of userPayout.userPayoutDetailsList) {
|
|
140
|
+
detail.userPayoutId = existUserPayout.id;
|
|
141
|
+
detail.userId = existUserPayout.userId;
|
|
142
|
+
detail.instituteId = existUserPayout.instituteId;
|
|
143
|
+
detail.type = existUserPayout.type;
|
|
144
|
+
const found = existUserPayout?.userPayoutDetailsList?.find(existing => detail.userPayoutId === existUserPayout.id &&
|
|
145
|
+
detail.instituteId === existing.instituteId &&
|
|
146
|
+
detail.userId === existing.userId &&
|
|
147
|
+
detail.type === existing.type &&
|
|
148
|
+
detail.subjectId === existing.subjectId &&
|
|
149
|
+
detail.batchId === existing.batchId);
|
|
150
|
+
if (found) {
|
|
151
|
+
await UserPayoutDetailsModel.update(detail, { where: { id: found.id }, ...options });
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
detail = (await UserPayoutDetailsModel.create(detail, options));
|
|
155
|
+
}
|
|
156
|
+
userPayoutDetailsList.push(detail);
|
|
157
|
+
}
|
|
158
|
+
if (userPayoutDetailsList.length) {
|
|
159
|
+
await UserPayoutDetailsModel.destroy({
|
|
160
|
+
where: {
|
|
161
|
+
id: { [sequelize_1.Op.notIn]: userPayoutDetailsList.map(detail => detail.id) },
|
|
162
|
+
userPayoutId: existUserPayout.id,
|
|
163
|
+
},
|
|
164
|
+
...options,
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
const totalPayableAmount = userPayoutDetailsList.reduce((sum, record) => sum + (record.payableAmount || 0), 0);
|
|
168
|
+
userPayout.userPayoutDetailsList = userPayoutDetailsList;
|
|
169
|
+
userPayout.totalPayableAmount = totalPayableAmount;
|
|
170
|
+
return userPayout;
|
|
171
|
+
}
|
|
172
|
+
catch (err) {
|
|
173
|
+
throw err;
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
const afterFindHook = async (userPayoutList, options = {}) => {
|
|
177
|
+
const transaction = await index_1.sequelize.transaction();
|
|
178
|
+
try {
|
|
179
|
+
const syncList = JSON.parse(JSON.stringify(userPayoutList));
|
|
180
|
+
if (!syncList.length) {
|
|
181
|
+
await transaction.commit();
|
|
182
|
+
return userPayoutList;
|
|
183
|
+
}
|
|
184
|
+
const updatedData = [];
|
|
185
|
+
for (let syncUserPayout of syncList) {
|
|
186
|
+
syncUserPayout = await afterCreateOrUpdateHook(syncUserPayout, undefined, transaction, options);
|
|
187
|
+
updatedData.push(syncUserPayout);
|
|
188
|
+
}
|
|
189
|
+
userPayoutList = userPayoutList.map(payout => {
|
|
190
|
+
const found = updatedData.find(one => one.id === payout.id);
|
|
191
|
+
if (found) {
|
|
192
|
+
payout.totalPayableAmount = found.totalPayableAmount;
|
|
193
|
+
payout.userPayoutDetailsList = found.userPayoutDetailsList;
|
|
194
|
+
}
|
|
195
|
+
return payout;
|
|
196
|
+
});
|
|
197
|
+
await transaction.commit();
|
|
198
|
+
return userPayoutList;
|
|
199
|
+
}
|
|
200
|
+
catch (err) {
|
|
201
|
+
await transaction.rollback();
|
|
202
|
+
return userPayoutList;
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
UserPayoutModel.addHook('afterFind', async (result, options) => {
|
|
206
|
+
if (options.syncUserPayoutLastCalculatedAt && Array.isArray(result)) {
|
|
207
|
+
result = (await afterFindHook(result, options));
|
|
208
|
+
}
|
|
209
|
+
else if (options.syncUserPayoutLastCalculatedAt && result) {
|
|
210
|
+
result = (await afterFindHook([result], options)).pop();
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
}
|
|
18
214
|
}
|
|
19
215
|
UserPayoutModel.init({
|
|
20
216
|
id: {
|
|
@@ -67,235 +263,4 @@ UserPayoutModel.init({
|
|
|
67
263
|
timestamps: true,
|
|
68
264
|
sequelize: index_1.sequelize,
|
|
69
265
|
});
|
|
70
|
-
UserPayoutModel.belongsTo(userModel_1.default, {
|
|
71
|
-
foreignKey: {
|
|
72
|
-
name: 'createdBy',
|
|
73
|
-
allowNull: true,
|
|
74
|
-
field: 'created_by',
|
|
75
|
-
},
|
|
76
|
-
as: 'createdByUser',
|
|
77
|
-
});
|
|
78
|
-
UserPayoutModel.belongsTo(userModel_1.default, {
|
|
79
|
-
foreignKey: {
|
|
80
|
-
name: 'updatedBy',
|
|
81
|
-
allowNull: true,
|
|
82
|
-
field: 'updated_by',
|
|
83
|
-
},
|
|
84
|
-
as: 'updatedByUser',
|
|
85
|
-
});
|
|
86
|
-
UserPayoutModel.belongsTo(userModel_1.default, {
|
|
87
|
-
foreignKey: {
|
|
88
|
-
name: 'deletedBy',
|
|
89
|
-
allowNull: true,
|
|
90
|
-
field: 'deleted_by',
|
|
91
|
-
},
|
|
92
|
-
as: 'deletedByUser',
|
|
93
|
-
});
|
|
94
|
-
UserPayoutModel.belongsTo(instituteModel_1.default, {
|
|
95
|
-
foreignKey: {
|
|
96
|
-
name: 'instituteId',
|
|
97
|
-
},
|
|
98
|
-
as: 'institute',
|
|
99
|
-
});
|
|
100
|
-
instituteModel_1.default.hasMany(UserPayoutModel, {
|
|
101
|
-
foreignKey: {
|
|
102
|
-
name: 'instituteId',
|
|
103
|
-
},
|
|
104
|
-
as: 'instituteHasPayoutList',
|
|
105
|
-
});
|
|
106
|
-
UserPayoutModel.belongsTo(userModel_1.default, {
|
|
107
|
-
foreignKey: {
|
|
108
|
-
name: 'userId',
|
|
109
|
-
},
|
|
110
|
-
as: 'user',
|
|
111
|
-
});
|
|
112
|
-
userModel_1.default.hasMany(UserPayoutModel, {
|
|
113
|
-
foreignKey: {
|
|
114
|
-
name: 'userId',
|
|
115
|
-
},
|
|
116
|
-
as: 'userHasPayoutList',
|
|
117
|
-
});
|
|
118
|
-
const afterCreateOrUpdateHook = async (userPayout, user = null, transaction, filterOptions = {}) => {
|
|
119
|
-
try {
|
|
120
|
-
if (!userPayout.userPayoutDetailsList || !userPayout.userPayoutDetailsList.length)
|
|
121
|
-
return userPayout;
|
|
122
|
-
userPayout.userPayoutDetailsList = (0, utils_1.getUniqueArrayByFields)(userPayout.userPayoutDetailsList, ['subjectId']);
|
|
123
|
-
const options = {
|
|
124
|
-
transaction,
|
|
125
|
-
};
|
|
126
|
-
if (user)
|
|
127
|
-
options.userId = user.id;
|
|
128
|
-
const now = new Date();
|
|
129
|
-
const previousMonthDate = (0, date_fns_1.subMonths)(now, 1);
|
|
130
|
-
let startOfPreviousMonth = (0, date_fns_1.startOfMonth)(previousMonthDate).toISOString();
|
|
131
|
-
let endOfPreviousMonth = (0, date_fns_1.endOfMonth)(previousMonthDate).toISOString();
|
|
132
|
-
if (filterOptions.include) {
|
|
133
|
-
filterOptions.include = !Array.isArray(filterOptions.include) ? [filterOptions.include] : filterOptions.include;
|
|
134
|
-
const historyListInclude = filterOptions.include.find((include) => include.as === 'userPayoutHistoryList');
|
|
135
|
-
let where = {};
|
|
136
|
-
if (historyListInclude && historyListInclude.where && historyListInclude.where[sequelize_1.Op.and]) {
|
|
137
|
-
where = historyListInclude.where[sequelize_1.Op.and].pop();
|
|
138
|
-
}
|
|
139
|
-
if (where.payout_start_time && where.payout_end_time) {
|
|
140
|
-
startOfPreviousMonth = where.payout_start_time[sequelize_1.Op.gte];
|
|
141
|
-
endOfPreviousMonth = where.payout_end_time[sequelize_1.Op.lte];
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
const attendanceWhereAnd = [{ date: { $gte: startOfPreviousMonth } }, { date: { $lte: endOfPreviousMonth } }];
|
|
145
|
-
const exsitUserPayout = (await UserPayoutModel.findOne({
|
|
146
|
-
where: { id: userPayout.id },
|
|
147
|
-
include: [{ association: 'userPayoutDetailsList' }],
|
|
148
|
-
transaction,
|
|
149
|
-
}));
|
|
150
|
-
if (!exsitUserPayout)
|
|
151
|
-
return userPayout;
|
|
152
|
-
if (userPayout.type === app_1.USER_PAYOUT_TYPE.PERCENTAGE) {
|
|
153
|
-
let feeTotalBySubjectList = await subjectHasPayFeeHistoryModel_1.default.findAll({
|
|
154
|
-
where: {
|
|
155
|
-
instituteId: exsitUserPayout.instituteId,
|
|
156
|
-
subjectId: {
|
|
157
|
-
[sequelize_1.Op.in]: userPayout.userPayoutDetailsList.map(userPayoutDetails => userPayoutDetails.subjectId),
|
|
158
|
-
},
|
|
159
|
-
},
|
|
160
|
-
attributes: [
|
|
161
|
-
['subject_id', 'subjectId'],
|
|
162
|
-
[sequelize_1.Sequelize.fn('sum', sequelize_1.Sequelize.col('amount')), 'amount'],
|
|
163
|
-
],
|
|
164
|
-
group: ['subject_id', 'created_at'],
|
|
165
|
-
raw: true,
|
|
166
|
-
});
|
|
167
|
-
feeTotalBySubjectList = JSON.parse(JSON.stringify(feeTotalBySubjectList));
|
|
168
|
-
userPayout.userPayoutDetailsList = userPayout.userPayoutDetailsList.map(oneUserPayoutDetails => {
|
|
169
|
-
oneUserPayoutDetails.payableAmount = feeTotalBySubjectList
|
|
170
|
-
.filter(feeTotalBySubject => feeTotalBySubject.subjectId === oneUserPayoutDetails.subjectId)
|
|
171
|
-
.reduce((sum, record) => {
|
|
172
|
-
if (oneUserPayoutDetails.percentage) {
|
|
173
|
-
const amount = ((record.amount || 0) * oneUserPayoutDetails.percentage) / 100;
|
|
174
|
-
return sum + parseFloat(amount.toFixed(2)); // Add fixed precision and convert back to number
|
|
175
|
-
}
|
|
176
|
-
return sum;
|
|
177
|
-
}, 0);
|
|
178
|
-
return oneUserPayoutDetails;
|
|
179
|
-
});
|
|
180
|
-
}
|
|
181
|
-
if (userPayout.type === app_1.USER_PAYOUT_TYPE.HOURLY) {
|
|
182
|
-
let lectureList = (await lectureModel_1.default.findAll({
|
|
183
|
-
where: {
|
|
184
|
-
instituteId: exsitUserPayout.instituteId,
|
|
185
|
-
subject: {
|
|
186
|
-
[sequelize_1.Op.in]: userPayout.userPayoutDetailsList.map(userPayoutDetails => userPayoutDetails.subjectId),
|
|
187
|
-
},
|
|
188
|
-
[sequelize_1.Op.or]: [{ primaryUserId: exsitUserPayout.userId }, { secondaryUserId: exsitUserPayout.userId }],
|
|
189
|
-
},
|
|
190
|
-
include: [{ association: 'workingDay' }],
|
|
191
|
-
}));
|
|
192
|
-
lectureList = JSON.parse(JSON.stringify(lectureList));
|
|
193
|
-
const currentMonthAttendenceList = await attendanceModel_1.default.find({
|
|
194
|
-
$and: attendanceWhereAnd,
|
|
195
|
-
userType: userPayout.userType,
|
|
196
|
-
'users.userId': userPayout.userId,
|
|
197
|
-
'users.status': { $ne: app_1.ATTENDANCE_STATUS.ABSENT },
|
|
198
|
-
});
|
|
199
|
-
userPayout.userPayoutDetailsList = userPayout.userPayoutDetailsList.map(oneUserPayoutDetails => {
|
|
200
|
-
let totalMinutes = 0;
|
|
201
|
-
currentMonthAttendenceList.forEach(attendance => {
|
|
202
|
-
const dayName = (0, date_fns_1.format)(attendance.date, 'EEEE');
|
|
203
|
-
const attendanceDayLectureBySubjectList = lectureList.filter(lecture => {
|
|
204
|
-
return lecture.workingDay.dayName === dayName && lecture.subject === oneUserPayoutDetails.subjectId;
|
|
205
|
-
});
|
|
206
|
-
if (attendanceDayLectureBySubjectList.length) {
|
|
207
|
-
totalMinutes += attendanceDayLectureBySubjectList.reduce((sum, record) => {
|
|
208
|
-
return sum + record.slotDuration;
|
|
209
|
-
}, 0);
|
|
210
|
-
}
|
|
211
|
-
});
|
|
212
|
-
oneUserPayoutDetails.payableAmount = ((oneUserPayoutDetails.amountPerHour || 0) / app_1.SIXTY) * totalMinutes;
|
|
213
|
-
return oneUserPayoutDetails;
|
|
214
|
-
});
|
|
215
|
-
}
|
|
216
|
-
const userPayoutDetailsList = [];
|
|
217
|
-
for (let userPayoutDetails of userPayout.userPayoutDetailsList) {
|
|
218
|
-
userPayoutDetails.userPayoutId = exsitUserPayout.id;
|
|
219
|
-
userPayoutDetails.userId = exsitUserPayout.userId;
|
|
220
|
-
userPayoutDetails.instituteId = exsitUserPayout.instituteId;
|
|
221
|
-
userPayoutDetails.type = exsitUserPayout.type;
|
|
222
|
-
const found = exsitUserPayout?.userPayoutDetailsList?.find(exsitUserPayoutDetails => userPayoutDetails.userPayoutId === exsitUserPayout.id &&
|
|
223
|
-
userPayoutDetails.instituteId === exsitUserPayoutDetails.instituteId &&
|
|
224
|
-
userPayoutDetails.userId === exsitUserPayoutDetails.userId &&
|
|
225
|
-
userPayoutDetails.type === exsitUserPayoutDetails.type &&
|
|
226
|
-
userPayoutDetails.subjectId === exsitUserPayoutDetails.subjectId &&
|
|
227
|
-
userPayoutDetails.batchId === exsitUserPayoutDetails.batchId);
|
|
228
|
-
if (found) {
|
|
229
|
-
await userPayoutDetailsModel_1.default.update(userPayoutDetails, {
|
|
230
|
-
where: { id: found.id },
|
|
231
|
-
...options,
|
|
232
|
-
});
|
|
233
|
-
}
|
|
234
|
-
else {
|
|
235
|
-
userPayoutDetails = (await userPayoutDetailsModel_1.default.create(userPayoutDetails, options));
|
|
236
|
-
}
|
|
237
|
-
userPayoutDetailsList.push(userPayoutDetails);
|
|
238
|
-
}
|
|
239
|
-
if (userPayoutDetailsList.length) {
|
|
240
|
-
await userPayoutDetailsModel_1.default.destroy({
|
|
241
|
-
where: {
|
|
242
|
-
id: {
|
|
243
|
-
[sequelize_1.Op.notIn]: userPayoutDetailsList.map(userPayoutDetails => userPayoutDetails.id),
|
|
244
|
-
},
|
|
245
|
-
userPayoutId: exsitUserPayout.id,
|
|
246
|
-
},
|
|
247
|
-
...options,
|
|
248
|
-
});
|
|
249
|
-
}
|
|
250
|
-
const totalPayableAmount = userPayoutDetailsList.reduce((sum, record) => {
|
|
251
|
-
return sum + record.payableAmount || 0;
|
|
252
|
-
}, 0);
|
|
253
|
-
//this is updatating payble amount so comment it .
|
|
254
|
-
// await this.update({ id: exsitUserPayout.id }, { totalPayableAmount, lastCalculatedAt: startOfToday() }, options);
|
|
255
|
-
userPayout.userPayoutDetailsList = userPayoutDetailsList;
|
|
256
|
-
userPayout.totalPayableAmount = totalPayableAmount;
|
|
257
|
-
return userPayout;
|
|
258
|
-
}
|
|
259
|
-
catch (err) {
|
|
260
|
-
throw err;
|
|
261
|
-
}
|
|
262
|
-
};
|
|
263
|
-
const afterFindHook = async (userPayoutList, options = {}) => {
|
|
264
|
-
const afterFindHookTransaction = await index_1.sequelize.transaction();
|
|
265
|
-
try {
|
|
266
|
-
const syncUserPayoutList = JSON.parse(JSON.stringify(userPayoutList));
|
|
267
|
-
if (!syncUserPayoutList.length) {
|
|
268
|
-
await afterFindHookTransaction.commit();
|
|
269
|
-
return userPayoutList;
|
|
270
|
-
}
|
|
271
|
-
const updatedData = [];
|
|
272
|
-
for (let syncUserPayout of syncUserPayoutList) {
|
|
273
|
-
syncUserPayout = await afterCreateOrUpdateHook(JSON.parse(JSON.stringify(syncUserPayout)), undefined, afterFindHookTransaction, options);
|
|
274
|
-
updatedData.push(syncUserPayout);
|
|
275
|
-
}
|
|
276
|
-
userPayoutList = userPayoutList.map((userPayout) => {
|
|
277
|
-
const found = updatedData.find(one => one.id === userPayout.id);
|
|
278
|
-
if (found) {
|
|
279
|
-
userPayout.totalPayableAmount = found.totalPayableAmount;
|
|
280
|
-
userPayout.userPayoutDetailsList = found.userPayoutDetailsList;
|
|
281
|
-
}
|
|
282
|
-
return userPayout;
|
|
283
|
-
});
|
|
284
|
-
await afterFindHookTransaction.commit();
|
|
285
|
-
return userPayoutList;
|
|
286
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
287
|
-
}
|
|
288
|
-
catch (err) {
|
|
289
|
-
await afterFindHookTransaction.rollback();
|
|
290
|
-
return userPayoutList;
|
|
291
|
-
}
|
|
292
|
-
};
|
|
293
|
-
UserPayoutModel.addHook('afterFind', async (result, options) => {
|
|
294
|
-
if (options.syncUserPayoutLastCalculatedAt && Array.isArray(result)) {
|
|
295
|
-
result = (await afterFindHook(result, options));
|
|
296
|
-
}
|
|
297
|
-
else if (options.syncUserPayoutLastCalculatedAt && result) {
|
|
298
|
-
result = (await afterFindHook([result], options)).pop();
|
|
299
|
-
}
|
|
300
|
-
});
|
|
301
266
|
exports.default = UserPayoutModel;
|
|
@@ -15,5 +15,6 @@ declare class UserProjectAssessmentOptionModel extends Model<IUserProjectAssessm
|
|
|
15
15
|
readonly createdAt: Date;
|
|
16
16
|
readonly deletedAt: string;
|
|
17
17
|
readonly updatedAt: Date;
|
|
18
|
+
static associate(models: any): void;
|
|
18
19
|
}
|
|
19
20
|
export default UserProjectAssessmentOptionModel;
|
|
@@ -1,15 +1,48 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
const sequelize_1 = require("sequelize");
|
|
7
4
|
const index_1 = require("./index");
|
|
8
|
-
const userModel_1 = __importDefault(require("./userModel"));
|
|
9
5
|
const app_1 = require("../../constants/app");
|
|
10
|
-
const batchSubjectProjectAssessmentModel_1 = __importDefault(require("./batchSubjectProjectAssessmentModel"));
|
|
11
|
-
const projectAssessmentOptionModel_1 = __importDefault(require("./projectAssessmentOptionModel"));
|
|
12
6
|
class UserProjectAssessmentOptionModel extends sequelize_1.Model {
|
|
7
|
+
static associate(models) {
|
|
8
|
+
const { BatchSubjectProjectAssessmentModel, ProjectAssessmentOptionModel, UserModel } = models;
|
|
9
|
+
UserProjectAssessmentOptionModel.belongsTo(BatchSubjectProjectAssessmentModel, {
|
|
10
|
+
foreignKey: { name: 'assessmentProjectId', field: 'assessment_project_id' },
|
|
11
|
+
as: 'assessmentProject',
|
|
12
|
+
});
|
|
13
|
+
BatchSubjectProjectAssessmentModel.hasMany(UserProjectAssessmentOptionModel, {
|
|
14
|
+
foreignKey: { name: 'assessmentProjectId', field: 'assessment_project_id' },
|
|
15
|
+
as: 'assessmentProjectUserList',
|
|
16
|
+
});
|
|
17
|
+
UserProjectAssessmentOptionModel.belongsTo(ProjectAssessmentOptionModel, {
|
|
18
|
+
foreignKey: { name: 'projectOptionId', field: 'project_option_id' },
|
|
19
|
+
as: 'assessmentProjectOption',
|
|
20
|
+
});
|
|
21
|
+
ProjectAssessmentOptionModel.hasMany(UserProjectAssessmentOptionModel, {
|
|
22
|
+
foreignKey: { name: 'projectOptionId', field: 'project_option_id' },
|
|
23
|
+
as: 'assessmentProjectOptionUserList',
|
|
24
|
+
});
|
|
25
|
+
UserProjectAssessmentOptionModel.belongsTo(UserModel, {
|
|
26
|
+
foreignKey: { name: 'userId', field: 'user_id' },
|
|
27
|
+
as: 'user',
|
|
28
|
+
});
|
|
29
|
+
UserModel.hasMany(UserProjectAssessmentOptionModel, {
|
|
30
|
+
foreignKey: { name: 'userId', field: 'user_id' },
|
|
31
|
+
as: 'userProjectAssessmentOptionList',
|
|
32
|
+
});
|
|
33
|
+
UserProjectAssessmentOptionModel.belongsTo(UserModel, {
|
|
34
|
+
foreignKey: { name: 'createdBy', allowNull: true, field: 'created_by' },
|
|
35
|
+
as: 'createdByUser',
|
|
36
|
+
});
|
|
37
|
+
UserProjectAssessmentOptionModel.belongsTo(UserModel, {
|
|
38
|
+
foreignKey: { name: 'updatedBy', allowNull: true, field: 'updated_by' },
|
|
39
|
+
as: 'updatedByUser',
|
|
40
|
+
});
|
|
41
|
+
UserProjectAssessmentOptionModel.belongsTo(UserModel, {
|
|
42
|
+
foreignKey: { name: 'deletedBy', allowNull: true, field: 'deleted_by' },
|
|
43
|
+
as: 'deletedByUser',
|
|
44
|
+
});
|
|
45
|
+
}
|
|
13
46
|
}
|
|
14
47
|
UserProjectAssessmentOptionModel.init({
|
|
15
48
|
id: {
|
|
@@ -51,76 +84,8 @@ UserProjectAssessmentOptionModel.init({
|
|
|
51
84
|
name: 'user_project_assessments_unique_key',
|
|
52
85
|
unique: true,
|
|
53
86
|
fields: ['user_id', 'assessment_project_id'],
|
|
54
|
-
// eslint-disable-next-line camelcase
|
|
55
87
|
where: { deleted_at: null },
|
|
56
88
|
},
|
|
57
89
|
],
|
|
58
90
|
});
|
|
59
|
-
// Associations
|
|
60
|
-
UserProjectAssessmentOptionModel.belongsTo(batchSubjectProjectAssessmentModel_1.default, {
|
|
61
|
-
foreignKey: {
|
|
62
|
-
name: 'assessmentProjectId',
|
|
63
|
-
field: 'assessment_project_id',
|
|
64
|
-
},
|
|
65
|
-
as: 'assessmentProject',
|
|
66
|
-
});
|
|
67
|
-
batchSubjectProjectAssessmentModel_1.default.hasMany(UserProjectAssessmentOptionModel, {
|
|
68
|
-
foreignKey: {
|
|
69
|
-
name: 'assessmentProjectId',
|
|
70
|
-
field: 'assessment_project_id',
|
|
71
|
-
},
|
|
72
|
-
as: 'assessmentProjectUserList',
|
|
73
|
-
});
|
|
74
|
-
UserProjectAssessmentOptionModel.belongsTo(projectAssessmentOptionModel_1.default, {
|
|
75
|
-
foreignKey: {
|
|
76
|
-
name: 'projectOptionId',
|
|
77
|
-
field: 'project_option_id',
|
|
78
|
-
},
|
|
79
|
-
as: 'assessmentProjectOption',
|
|
80
|
-
});
|
|
81
|
-
projectAssessmentOptionModel_1.default.hasMany(UserProjectAssessmentOptionModel, {
|
|
82
|
-
foreignKey: {
|
|
83
|
-
name: 'projectOptionId',
|
|
84
|
-
field: 'project_option_id',
|
|
85
|
-
},
|
|
86
|
-
as: 'assessmentProjectOptionUserList',
|
|
87
|
-
});
|
|
88
|
-
UserProjectAssessmentOptionModel.belongsTo(userModel_1.default, {
|
|
89
|
-
foreignKey: {
|
|
90
|
-
name: 'userId',
|
|
91
|
-
field: 'user_id',
|
|
92
|
-
},
|
|
93
|
-
as: 'user',
|
|
94
|
-
});
|
|
95
|
-
userModel_1.default.hasMany(UserProjectAssessmentOptionModel, {
|
|
96
|
-
foreignKey: {
|
|
97
|
-
name: 'userId',
|
|
98
|
-
field: 'user_id',
|
|
99
|
-
},
|
|
100
|
-
as: 'userProjectAssessmentOptionList',
|
|
101
|
-
});
|
|
102
|
-
UserProjectAssessmentOptionModel.belongsTo(userModel_1.default, {
|
|
103
|
-
foreignKey: {
|
|
104
|
-
name: 'createdBy',
|
|
105
|
-
allowNull: true,
|
|
106
|
-
field: 'created_by',
|
|
107
|
-
},
|
|
108
|
-
as: 'createdByUser',
|
|
109
|
-
});
|
|
110
|
-
UserProjectAssessmentOptionModel.belongsTo(userModel_1.default, {
|
|
111
|
-
foreignKey: {
|
|
112
|
-
name: 'updatedBy',
|
|
113
|
-
allowNull: true,
|
|
114
|
-
field: 'updated_by',
|
|
115
|
-
},
|
|
116
|
-
as: 'updatedByUser',
|
|
117
|
-
});
|
|
118
|
-
UserProjectAssessmentOptionModel.belongsTo(userModel_1.default, {
|
|
119
|
-
foreignKey: {
|
|
120
|
-
name: 'deletedBy',
|
|
121
|
-
allowNull: true,
|
|
122
|
-
field: 'deleted_by',
|
|
123
|
-
},
|
|
124
|
-
as: 'deletedByUser',
|
|
125
|
-
});
|
|
126
91
|
exports.default = UserProjectAssessmentOptionModel;
|
|
@@ -1,12 +1,31 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
const sequelize_1 = require("sequelize");
|
|
7
4
|
const index_1 = require("./index");
|
|
8
|
-
const userModel_1 = __importDefault(require("./userModel"));
|
|
9
5
|
class UserRequiredSteps extends sequelize_1.Model {
|
|
6
|
+
static associate(models) {
|
|
7
|
+
const { UserModel } = models;
|
|
8
|
+
UserRequiredSteps.belongsTo(UserModel, {
|
|
9
|
+
foreignKey: { name: 'createdBy', allowNull: true, field: 'created_by' },
|
|
10
|
+
as: 'createdByUser',
|
|
11
|
+
});
|
|
12
|
+
UserRequiredSteps.belongsTo(UserModel, {
|
|
13
|
+
foreignKey: { name: 'updatedBy', allowNull: true, field: 'updated_by' },
|
|
14
|
+
as: 'updatedByUser',
|
|
15
|
+
});
|
|
16
|
+
UserRequiredSteps.belongsTo(UserModel, {
|
|
17
|
+
foreignKey: { name: 'deletedBy', allowNull: true, field: 'deleted_by' },
|
|
18
|
+
as: 'deletedByUser',
|
|
19
|
+
});
|
|
20
|
+
UserModel.hasMany(UserRequiredSteps, {
|
|
21
|
+
foreignKey: 'userId',
|
|
22
|
+
as: 'userHasRequiredSteps',
|
|
23
|
+
});
|
|
24
|
+
UserRequiredSteps.belongsTo(UserModel, {
|
|
25
|
+
foreignKey: 'userId',
|
|
26
|
+
as: 'requiredStepsUser',
|
|
27
|
+
});
|
|
28
|
+
}
|
|
10
29
|
}
|
|
11
30
|
UserRequiredSteps.init({
|
|
12
31
|
id: {
|
|
@@ -43,36 +62,4 @@ UserRequiredSteps.init({
|
|
|
43
62
|
timestamps: true,
|
|
44
63
|
underscored: true,
|
|
45
64
|
});
|
|
46
|
-
UserRequiredSteps.belongsTo(userModel_1.default, {
|
|
47
|
-
foreignKey: {
|
|
48
|
-
name: 'createdBy',
|
|
49
|
-
allowNull: true,
|
|
50
|
-
field: 'created_by',
|
|
51
|
-
},
|
|
52
|
-
as: 'createdByUser',
|
|
53
|
-
});
|
|
54
|
-
UserRequiredSteps.belongsTo(userModel_1.default, {
|
|
55
|
-
foreignKey: {
|
|
56
|
-
name: 'updatedBy',
|
|
57
|
-
allowNull: true,
|
|
58
|
-
field: 'updated_by',
|
|
59
|
-
},
|
|
60
|
-
as: 'updatedByUser',
|
|
61
|
-
});
|
|
62
|
-
UserRequiredSteps.belongsTo(userModel_1.default, {
|
|
63
|
-
foreignKey: {
|
|
64
|
-
name: 'deletedBy',
|
|
65
|
-
allowNull: true,
|
|
66
|
-
field: 'deleted_by',
|
|
67
|
-
},
|
|
68
|
-
as: 'deletedByUser',
|
|
69
|
-
});
|
|
70
|
-
userModel_1.default.hasMany(UserRequiredSteps, {
|
|
71
|
-
foreignKey: 'userId',
|
|
72
|
-
as: 'userHasRequiredSteps',
|
|
73
|
-
});
|
|
74
|
-
UserRequiredSteps.belongsTo(userModel_1.default, {
|
|
75
|
-
foreignKey: 'userId',
|
|
76
|
-
as: 'requiredStepsUser',
|
|
77
|
-
});
|
|
78
65
|
exports.default = UserRequiredSteps;
|