Skip to content

Commit 51ebe3e

Browse files
committed
delete confessions allowed for admins, feed gender prioritization
1 parent 0aa6424 commit 51ebe3e

File tree

2 files changed

+39
-12
lines changed

2 files changed

+39
-12
lines changed

controllers/confession.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const Confessions = require("../models/confession.js");
2-
const { CONFESSIONS_TYPE_ENUM , CONFESSIONS_REPORTS_ENUM } = require("../shared/constants.js");
2+
const { CONFESSIONS_TYPE_ENUM , CONFESSIONS_REPORTS_ENUM, AdminList } = require("../shared/constants.js");
33
const {DetectToxicity , RemoveBadWords} = require("../utils/profanityCheck.js");
44
const UserProfile = require('../models/UserProfile.js');
55
const { GenerateHash } = require('../utils/hashing.js');
@@ -372,6 +372,19 @@ exports.deleteConfession = async(req, res) => {
372372
*/
373373

374374
const { id } = req.params;
375+
376+
if(AdminList.includes(req.email)) {
377+
await Promise.all([
378+
Confessions.findByIdAndDelete(id) ,
379+
Reply.deleteMany({confessionId : id})
380+
]);
381+
382+
return res.json({
383+
success : true ,
384+
message : "Confession deleted"
385+
});
386+
}
387+
375388
const { encryptedEmail } = req.body;
376389

377390
if (!id || typeof encryptedEmail !== "string" || encryptedEmail.trim().length === 0) {

controllers/feedController.js

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ exports.getFeed = async(req, res) => {
5656
});
5757

5858
if (!currUser
59-
// || !currUser.personalityType
6059
) {
6160
return res
6261
.json({
@@ -65,8 +64,6 @@ exports.getFeed = async(req, res) => {
6564
});
6665
}
6766

68-
// const currUserScoreFactors = cumulateMatchingFactors(currUser);
69-
7067
let userProfiles = await UserProfile.find({
7168
...newFilters ,
7269
email : {
@@ -83,12 +80,6 @@ exports.getFeed = async(req, res) => {
8380
const lessPreferredGenderUser = [];
8481

8582
userProfiles.forEach(otherUser => {
86-
// const otherUserScoreFactors = cumulateMatchingFactors(otherUser);
87-
// const scoredProfile = {
88-
// score : calculateMatchingScore(currUserScoreFactors , otherUserScoreFactors) ,
89-
// ...(otherUser.toObject())
90-
// };
91-
9283
if(
9384
(
9485
currUser.gender !== otherUser.gender
@@ -100,11 +91,34 @@ exports.getFeed = async(req, res) => {
10091
) {
10192
morePreferredGenderUser.push(otherUser);
10293
} else {
103-
morePreferredGenderUser.push(otherUser);
94+
lessPreferredGenderUser.push(otherUser);
10495
}
10596
});
97+
98+
shuffleProfiles(morePreferredGenderUser);
99+
shuffleProfiles(lessPreferredGenderUser);
106100

107-
let paginatedUsers = pickUsers(morePreferredGenderUser, lessPreferredGenderUser);
101+
const pageNumber = (parseInt(req.params.pageNumber, 10) || 0) % (morePreferredGenderUser.length + lessPreferredGenderUser.length);
102+
const pageSize = 10;
103+
const startIndex = pageNumber * pageSize;
104+
const endIndex = startIndex + pageSize;
105+
106+
let paginatedUsers = [];
107+
108+
const moreLength = morePreferredGenderUser.length;
109+
110+
if (startIndex < moreLength && endIndex <= moreLength) {
111+
paginatedUsers = morePreferredGenderUser.slice(startIndex, endIndex);
112+
} else if (startIndex < moreLength && endIndex > moreLength) {
113+
const fromMore = morePreferredGenderUser.slice(startIndex, moreLength);
114+
const remaining = endIndex - moreLength;
115+
const fromLess = lessPreferredGenderUser.slice(0, remaining);
116+
paginatedUsers = [...fromMore, ...fromLess];
117+
} else {
118+
const newStart = startIndex - moreLength;
119+
const newEnd = endIndex - moreLength;
120+
paginatedUsers = lessPreferredGenderUser.slice(newStart, newEnd);
121+
}
108122

109123
shuffleProfiles(paginatedUsers);
110124

0 commit comments

Comments
 (0)