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