@duvdu-v1/duvdu 1.1.245 → 1.1.247
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/build/services/rank.service.js +11 -35
- package/package.json +1 -1
|
@@ -36,28 +36,16 @@ const updateRankForUser = (userId) => __awaiter(void 0, void 0, void 0, function
|
|
|
36
36
|
projectsCount: -1
|
|
37
37
|
})
|
|
38
38
|
.exec();
|
|
39
|
-
console.log('currentRank', currentRank);
|
|
40
39
|
// Find next possible rank
|
|
41
40
|
const nextRank = yield ranks_model_1.Rank.findOne({
|
|
42
|
-
$
|
|
43
|
-
{ actionCount: { $gt: acceptedProjectsCounter } },
|
|
44
|
-
{ projectsLiked: { $gt: projectsLiked } },
|
|
45
|
-
{ projectsCount: { $gt: projectsCount } }
|
|
46
|
-
]
|
|
47
|
-
})
|
|
48
|
-
.sort({
|
|
49
|
-
actionCount: 1,
|
|
50
|
-
favoriteCount: 1,
|
|
51
|
-
projectsLiked: 1,
|
|
52
|
-
projectsCount: 1
|
|
41
|
+
actionCount: { $gt: acceptedProjectsCounter || 0 }
|
|
53
42
|
})
|
|
43
|
+
.sort({ actionCount: 1 })
|
|
54
44
|
.exec();
|
|
55
|
-
console.log('nextRank', nextRank);
|
|
56
45
|
if (currentRank) {
|
|
57
46
|
user.rank.title = currentRank.rank;
|
|
58
47
|
user.rank.color = currentRank.color;
|
|
59
48
|
if (nextRank) {
|
|
60
|
-
// Calculate progress based on the most relevant criterion
|
|
61
49
|
const criteriaProgress = [
|
|
62
50
|
{
|
|
63
51
|
completed: acceptedProjectsCounter - currentRank.actionCount,
|
|
@@ -72,10 +60,10 @@ const updateRankForUser = (userId) => __awaiter(void 0, void 0, void 0, function
|
|
|
72
60
|
needed: nextRank.projectsCount - currentRank.projectsCount
|
|
73
61
|
}
|
|
74
62
|
];
|
|
75
|
-
//
|
|
63
|
+
// Improved progress calculation
|
|
76
64
|
const progress = criteriaProgress
|
|
77
65
|
.filter(c => c.needed > 0)
|
|
78
|
-
.map(c => (c.completed / c.needed) * 100);
|
|
66
|
+
.map(c => Math.min(Math.max((c.completed / c.needed) * 100, 0), 100)); // Ensure between 0-100
|
|
79
67
|
user.rank.nextRangPercentage = progress.length ? Math.max(...progress) : 0;
|
|
80
68
|
user.rank.nextRankTitle = nextRank.rank;
|
|
81
69
|
}
|
|
@@ -110,9 +98,6 @@ const recalculateAllUsersRanks = () => __awaiter(void 0, void 0, void 0, functio
|
|
|
110
98
|
const projectsCount = user.projectsCount;
|
|
111
99
|
const projectsLiked = user.likes;
|
|
112
100
|
const acceptedProjectsCounter = user.acceptedProjectsCounter;
|
|
113
|
-
console.log('acceptedProjectsCounter', acceptedProjectsCounter);
|
|
114
|
-
console.log('projectsLiked', projectsLiked);
|
|
115
|
-
console.log('projectsCount', projectsCount);
|
|
116
101
|
// Find current rank that matches ALL criteria
|
|
117
102
|
const currentRank = yield ranks_model_1.Rank.findOne({
|
|
118
103
|
actionCount: { $lte: acceptedProjectsCounter },
|
|
@@ -126,28 +111,16 @@ const recalculateAllUsersRanks = () => __awaiter(void 0, void 0, void 0, functio
|
|
|
126
111
|
projectsCount: -1
|
|
127
112
|
})
|
|
128
113
|
.exec();
|
|
129
|
-
console.log('currentRank', currentRank);
|
|
130
114
|
// Find next possible rank
|
|
131
115
|
const nextRank = yield ranks_model_1.Rank.findOne({
|
|
132
|
-
$
|
|
133
|
-
{ actionCount: { $gt: acceptedProjectsCounter } },
|
|
134
|
-
{ projectsLiked: { $gt: projectsLiked } },
|
|
135
|
-
{ projectsCount: { $gt: projectsCount } }
|
|
136
|
-
]
|
|
137
|
-
})
|
|
138
|
-
.sort({
|
|
139
|
-
actionCount: 1,
|
|
140
|
-
favoriteCount: 1,
|
|
141
|
-
projectsLiked: 1,
|
|
142
|
-
projectsCount: 1
|
|
116
|
+
actionCount: { $gt: acceptedProjectsCounter || 0 }
|
|
143
117
|
})
|
|
118
|
+
.sort({ actionCount: 1 })
|
|
144
119
|
.exec();
|
|
145
|
-
console.log('nextRank', nextRank);
|
|
146
120
|
if (currentRank) {
|
|
147
121
|
user.rank.title = currentRank.rank;
|
|
148
122
|
user.rank.color = currentRank.color;
|
|
149
123
|
if (nextRank) {
|
|
150
|
-
// Calculate progress based on the most relevant criterion
|
|
151
124
|
const criteriaProgress = [
|
|
152
125
|
{
|
|
153
126
|
completed: acceptedProjectsCounter - currentRank.actionCount,
|
|
@@ -162,10 +135,13 @@ const recalculateAllUsersRanks = () => __awaiter(void 0, void 0, void 0, functio
|
|
|
162
135
|
needed: nextRank.projectsCount - currentRank.projectsCount
|
|
163
136
|
}
|
|
164
137
|
];
|
|
165
|
-
|
|
138
|
+
console.log('criteriaProgress', criteriaProgress);
|
|
139
|
+
// Improved progress calculation
|
|
166
140
|
const progress = criteriaProgress
|
|
167
141
|
.filter(c => c.needed > 0)
|
|
168
|
-
.map(c => (c.completed / c.needed) * 100);
|
|
142
|
+
.map(c => Math.min(Math.max((c.completed / c.needed) * 100, 0), 100)); // Ensure between 0-100
|
|
143
|
+
console.log('progress', progress);
|
|
144
|
+
console.log('progress.length', progress.length ? Math.max(...progress) : 0);
|
|
169
145
|
user.rank.nextRangPercentage = progress.length ? Math.max(...progress) : 0;
|
|
170
146
|
user.rank.nextRankTitle = nextRank.rank;
|
|
171
147
|
}
|