@duvdu-v1/duvdu 1.1.224 → 1.1.226

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.
@@ -53,10 +53,7 @@ const userSchema = new mongoose_1.Schema({
53
53
  value: { type: Boolean, default: false },
54
54
  reason: { type: String, default: null },
55
55
  },
56
- notificationToken: {
57
- type: String,
58
- default: null,
59
- },
56
+ fcmTokens: [{ fcmToken: String, deviceId: String }],
60
57
  followCount: {
61
58
  followers: { type: Number, default: 0 },
62
59
  following: { type: Number, default: 0 },
@@ -90,8 +87,10 @@ const userSchema = new mongoose_1.Schema({
90
87
  .index({ location: '2dsphere' });
91
88
  userSchema.pre('save', function (next) {
92
89
  return __awaiter(this, void 0, void 0, function* () {
93
- if (this.isModified('acceptedProjectsCounter'))
90
+ if (this.isModified('acceptedProjectsCounter') ||
91
+ this.isModified('likes')) {
94
92
  yield (0, rank_service_1.updateRankForUser)(this);
93
+ }
95
94
  next();
96
95
  });
97
96
  });
@@ -26,6 +26,9 @@
26
26
  export interface Irank {
27
27
  actionCount: number;
28
28
  rank: string;
29
+ favoriteCount: number;
30
+ projectsLiked: number;
31
+ projectsCount: number;
29
32
  color: string;
30
33
  }
31
34
  export declare const Rank: import("mongoose").Model<Irank, {}, {}, {}, import("mongoose").Document<unknown, {}, Irank> & Irank & {
@@ -7,4 +7,7 @@ exports.Rank = (0, mongoose_1.model)(model_names_1.MODELS.rank, new mongoose_1.S
7
7
  actionCount: { type: Number, unique: true, default: 0 },
8
8
  rank: { type: String, unique: true, default: null },
9
9
  color: { type: String, default: null },
10
+ favoriteCount: { type: Number, default: 0 },
11
+ projectsLiked: { type: Number, default: 0 },
12
+ projectsCount: { type: Number, default: 0 },
10
13
  }, { timestamps: true, collection: model_names_1.MODELS.rank }));
@@ -10,21 +10,73 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.updateRankForUser = void 0;
13
+ const allProjects_model_1 = require("../models/allProjects.model");
14
+ const favourites_model_1 = require("../models/favourites.model");
13
15
  const ranks_model_1 = require("../models/ranks.model");
14
16
  const updateRankForUser = (user) => __awaiter(void 0, void 0, void 0, function* () {
15
- const currentRank = yield ranks_model_1.Rank.findOne({ actionCount: { $lte: user.acceptedProjectsCounter } })
16
- .sort({ actionCount: -1 })
17
+ // get all user stats
18
+ const projectsCount = yield allProjects_model_1.Project.countDocuments({ user: user._id });
19
+ const favoriteCount = yield favourites_model_1.Favourites.countDocuments({ user: user._id });
20
+ const projectsLiked = user.likes;
21
+ const acceptedProjectsCounter = user.acceptedProjectsCounter;
22
+ // Find current rank that matches ALL criteria
23
+ const currentRank = yield ranks_model_1.Rank.findOne({
24
+ actionCount: { $lte: acceptedProjectsCounter },
25
+ favoriteCount: { $lte: favoriteCount },
26
+ projectsLiked: { $lte: projectsLiked },
27
+ projectsCount: { $lte: projectsCount }
28
+ })
29
+ .sort({
30
+ actionCount: -1,
31
+ favoriteCount: -1,
32
+ projectsLiked: -1,
33
+ projectsCount: -1
34
+ })
17
35
  .exec();
18
- const nextRank = yield ranks_model_1.Rank.findOne({ actionCount: { $gt: user.acceptedProjectsCounter } })
19
- .sort({ actionCount: 1 })
36
+ // Find next possible rank
37
+ const nextRank = yield ranks_model_1.Rank.findOne({
38
+ $or: [
39
+ { actionCount: { $gt: acceptedProjectsCounter } },
40
+ { favoriteCount: { $gt: favoriteCount } },
41
+ { projectsLiked: { $gt: projectsLiked } },
42
+ { projectsCount: { $gt: projectsCount } }
43
+ ]
44
+ })
45
+ .sort({
46
+ actionCount: 1,
47
+ favoriteCount: 1,
48
+ projectsLiked: 1,
49
+ projectsCount: 1
50
+ })
20
51
  .exec();
21
52
  if (currentRank) {
22
53
  user.rank.title = currentRank.rank;
23
54
  user.rank.color = currentRank.color;
24
55
  if (nextRank) {
25
- const actionsNeeded = nextRank.actionCount - currentRank.actionCount;
26
- const actionsCompleted = user.acceptedProjectsCounter - currentRank.actionCount;
27
- user.rank.nextRangPercentage = (actionsCompleted / actionsNeeded) * 100;
56
+ // Calculate progress based on the most relevant criterion
57
+ const criteriaProgress = [
58
+ {
59
+ completed: acceptedProjectsCounter - currentRank.actionCount,
60
+ needed: nextRank.actionCount - currentRank.actionCount
61
+ },
62
+ {
63
+ completed: favoriteCount - currentRank.favoriteCount,
64
+ needed: nextRank.favoriteCount - currentRank.favoriteCount
65
+ },
66
+ {
67
+ completed: projectsLiked - currentRank.projectsLiked,
68
+ needed: nextRank.projectsLiked - currentRank.projectsLiked
69
+ },
70
+ {
71
+ completed: projectsCount - currentRank.projectsCount,
72
+ needed: nextRank.projectsCount - currentRank.projectsCount
73
+ }
74
+ ];
75
+ // Find the criterion with the highest progress percentage
76
+ const progress = criteriaProgress
77
+ .filter(c => c.needed > 0)
78
+ .map(c => (c.completed / c.needed) * 100);
79
+ user.rank.nextRangPercentage = progress.length ? Math.max(...progress) : 0;
28
80
  user.rank.nextRankTitle = nextRank.rank;
29
81
  }
30
82
  else {
@@ -87,7 +87,10 @@ export interface Iuser {
87
87
  following: number;
88
88
  followers: number;
89
89
  };
90
- notificationToken: string | null;
90
+ fcmTokens: {
91
+ fcmToken: string;
92
+ deviceId: string;
93
+ }[];
91
94
  isFollow?: boolean;
92
95
  favourites: {
93
96
  project: Types.ObjectId;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@duvdu-v1/duvdu",
3
- "version": "1.1.224",
3
+ "version": "1.1.226",
4
4
  "main": "./build/index.js",
5
5
  "types": "./build/index.d.ts",
6
6
  "files": [