@duvdu-v1/duvdu 1.1.335 → 1.1.337
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.
|
@@ -28,4 +28,5 @@ export type UserDocument = Document & Iuser;
|
|
|
28
28
|
export declare const updateRankForUser: (userId: string) => Promise<(Document<unknown, {}, Iuser> & Iuser & {
|
|
29
29
|
_id: import("mongoose").Types.ObjectId;
|
|
30
30
|
}) | undefined>;
|
|
31
|
+
export declare const updateUsersAfterRankDeletion: (deletedRankTitle: string) => Promise<void>;
|
|
31
32
|
export declare const recalculateAllUsersRanks: () => Promise<void>;
|
|
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.recalculateAllUsersRanks = exports.updateRankForUser = void 0;
|
|
12
|
+
exports.recalculateAllUsersRanks = exports.updateUsersAfterRankDeletion = exports.updateRankForUser = void 0;
|
|
13
13
|
const ranks_model_1 = require("../models/ranks.model");
|
|
14
14
|
const User_model_1 = require("../models/User.model");
|
|
15
15
|
const updateRankForUser = (userId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -81,6 +81,46 @@ const updateRankForUser = (userId) => __awaiter(void 0, void 0, void 0, function
|
|
|
81
81
|
return user;
|
|
82
82
|
});
|
|
83
83
|
exports.updateRankForUser = updateRankForUser;
|
|
84
|
+
const updateUsersAfterRankDeletion = (deletedRankTitle) => __awaiter(void 0, void 0, void 0, function* () {
|
|
85
|
+
const BATCH_SIZE = 100;
|
|
86
|
+
let processedCount = 0;
|
|
87
|
+
try {
|
|
88
|
+
// Find all users who have the deleted rank
|
|
89
|
+
const totalUsersWithRank = yield User_model_1.Users.countDocuments({
|
|
90
|
+
'rank.title': deletedRankTitle,
|
|
91
|
+
});
|
|
92
|
+
if (totalUsersWithRank === 0) {
|
|
93
|
+
console.log('No users found with the deleted rank:', deletedRankTitle);
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
console.log(`Found ${totalUsersWithRank} users with rank "${deletedRankTitle}" that need to be updated`);
|
|
97
|
+
// Process users in batches
|
|
98
|
+
while (true) {
|
|
99
|
+
const users = yield User_model_1.Users.find({ 'rank.title': deletedRankTitle })
|
|
100
|
+
.skip(processedCount)
|
|
101
|
+
.limit(BATCH_SIZE);
|
|
102
|
+
if (users.length === 0)
|
|
103
|
+
break;
|
|
104
|
+
// Update rank for each user in the batch using the same logic as updateRankForUser
|
|
105
|
+
yield Promise.all(users.map((user) => __awaiter(void 0, void 0, void 0, function* () {
|
|
106
|
+
try {
|
|
107
|
+
yield (0, exports.updateRankForUser)(user._id.toString());
|
|
108
|
+
}
|
|
109
|
+
catch (error) {
|
|
110
|
+
console.error(`Failed to update rank for user ${user._id}:`, error);
|
|
111
|
+
}
|
|
112
|
+
})));
|
|
113
|
+
processedCount += users.length;
|
|
114
|
+
console.log(`Updated ${processedCount}/${totalUsersWithRank} users`);
|
|
115
|
+
}
|
|
116
|
+
console.log(`Successfully updated all ${processedCount} users after rank deletion`);
|
|
117
|
+
}
|
|
118
|
+
catch (error) {
|
|
119
|
+
console.error('Failed to update users after rank deletion:', error);
|
|
120
|
+
throw error;
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
exports.updateUsersAfterRankDeletion = updateUsersAfterRankDeletion;
|
|
84
124
|
const recalculateAllUsersRanks = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
85
125
|
const BATCH_SIZE = 100;
|
|
86
126
|
let processedCount = 0;
|