@duvdu-v1/duvdu 1.1.227 → 1.1.229

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.
@@ -69,6 +69,7 @@ const userSchema = new mongoose_1.Schema({
69
69
  projectsView: { type: Number, default: 0 },
70
70
  haveInvitation: { type: Boolean, default: false },
71
71
  faceRecognition: { type: String, default: null },
72
+ projectsCount: { type: Number, default: 0 },
72
73
  }, {
73
74
  timestamps: true,
74
75
  collection: model_names_1.MODELS.user,
@@ -88,7 +89,8 @@ const userSchema = new mongoose_1.Schema({
88
89
  userSchema.pre('save', function (next) {
89
90
  return __awaiter(this, void 0, void 0, function* () {
90
91
  if (this.isModified('acceptedProjectsCounter') ||
91
- this.isModified('likes')) {
92
+ this.isModified('likes') ||
93
+ this.isModified('projectsCount')) {
92
94
  yield (0, rank_service_1.updateRankForUser)(this);
93
95
  }
94
96
  next();
@@ -7,7 +7,6 @@ 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
10
  projectsLiked: { type: Number, default: 0 },
12
11
  projectsCount: { type: Number, default: 0 },
13
12
  }, { timestamps: true, collection: model_names_1.MODELS.rank }));
@@ -10,20 +10,16 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.recalculateAllUsersRanks = exports.updateRankForUser = void 0;
13
- const allProjects_model_1 = require("../models/allProjects.model");
14
- const favourites_model_1 = require("../models/favourites.model");
15
13
  const ranks_model_1 = require("../models/ranks.model");
16
14
  const User_model_1 = require("../models/User.model");
17
15
  const updateRankForUser = (user) => __awaiter(void 0, void 0, void 0, function* () {
18
16
  // get all user stats
19
- const projectsCount = yield allProjects_model_1.Project.countDocuments({ user: user._id });
20
- const favoriteCount = yield favourites_model_1.Favourites.countDocuments({ user: user._id });
17
+ const projectsCount = user.projectsCount;
21
18
  const projectsLiked = user.likes;
22
19
  const acceptedProjectsCounter = user.acceptedProjectsCounter;
23
20
  // Find current rank that matches ALL criteria
24
21
  const currentRank = yield ranks_model_1.Rank.findOne({
25
22
  actionCount: { $lte: acceptedProjectsCounter },
26
- favoriteCount: { $lte: favoriteCount },
27
23
  projectsLiked: { $lte: projectsLiked },
28
24
  projectsCount: { $lte: projectsCount }
29
25
  })
@@ -38,7 +34,6 @@ const updateRankForUser = (user) => __awaiter(void 0, void 0, void 0, function*
38
34
  const nextRank = yield ranks_model_1.Rank.findOne({
39
35
  $or: [
40
36
  { actionCount: { $gt: acceptedProjectsCounter } },
41
- { favoriteCount: { $gt: favoriteCount } },
42
37
  { projectsLiked: { $gt: projectsLiked } },
43
38
  { projectsCount: { $gt: projectsCount } }
44
39
  ]
@@ -60,10 +55,6 @@ const updateRankForUser = (user) => __awaiter(void 0, void 0, void 0, function*
60
55
  completed: acceptedProjectsCounter - currentRank.actionCount,
61
56
  needed: nextRank.actionCount - currentRank.actionCount
62
57
  },
63
- {
64
- completed: favoriteCount - currentRank.favoriteCount,
65
- needed: nextRank.favoriteCount - currentRank.favoriteCount
66
- },
67
58
  {
68
59
  completed: projectsLiked - currentRank.projectsLiked,
69
60
  needed: nextRank.projectsLiked - currentRank.projectsLiked
@@ -107,4 +107,5 @@ export interface Iuser {
107
107
  projectsView: number;
108
108
  haveInvitation: boolean;
109
109
  faceRecognition: string | null;
110
+ projectsCount: number;
110
111
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@duvdu-v1/duvdu",
3
- "version": "1.1.227",
3
+ "version": "1.1.229",
4
4
  "main": "./build/index.js",
5
5
  "types": "./build/index.d.ts",
6
6
  "files": [