Skip to content

Commit 4e5f5da

Browse files
authored
Merge pull request #2253 from RahulGoyal-tech/iss2223
Added function for unobfuscated profileDiffs, filtered id while updating profileDiffs
2 parents 10bc222 + 6dbda50 commit 4e5f5da

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed

controllers/users.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -678,8 +678,14 @@ const getUserImageForVerification = async (req, res) => {
678678
const updateUser = async (req, res) => {
679679
try {
680680
const { id: profileDiffId, message } = req.body;
681-
682-
const profileDiffData = await profileDiffsQuery.fetchProfileDiff(profileDiffId);
681+
const devFeatureFlag = req.query.dev;
682+
let profileDiffData;
683+
if (devFeatureFlag === "true") {
684+
profileDiffData = await profileDiffsQuery.fetchProfileDiffUnobfuscated(profileDiffId);
685+
} else {
686+
profileDiffData = await profileDiffsQuery.fetchProfileDiff(profileDiffId);
687+
}
688+
Object.freeze(profileDiffData);
683689
if (!profileDiffData) return res.boom.notFound("Profile Diff doesn't exist");
684690

685691
const { approval, timestamp, userId, ...profileDiff } = profileDiffData;

models/profileDiffs.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,30 @@ const fetchProfileDiff = async (profileDiffId) => {
133133
}
134134
};
135135

136+
/**
137+
* Fetches the unobfuscated profileDiff data of the provided profileDiff Id
138+
* @param profileDiffId profileDiffId of the diffs need to be fetched
139+
* @returns unobfuscated profileDiff Data
140+
*/
141+
const fetchProfileDiffUnobfuscated = async (profileDiffId) => {
142+
try {
143+
const profileDiff = await profileDiffsModel.doc(profileDiffId).get();
144+
145+
if (!profileDiff.exists) {
146+
return { profileDiffExists: false };
147+
}
148+
const profileDiffData = profileDiff.data();
149+
return {
150+
id: profileDiff.id,
151+
profileDiffExists: true,
152+
...profileDiffData,
153+
};
154+
} catch (err) {
155+
logger.error("Error retrieving Unobfuscated profile Diff", err);
156+
throw err;
157+
}
158+
};
159+
136160
/** Add profileDiff
137161
*
138162
* @param profileDiffData { Object }: Data to be added
@@ -181,4 +205,5 @@ module.exports = {
181205
add,
182206
updateProfileDiff,
183207
fetchProfileDiffsWithPagination,
208+
fetchProfileDiffUnobfuscated,
184209
};

models/users.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ const addOrUpdate = async (userData, userId = null) => {
9292
const isNewUser = !user.data();
9393
// user exists update user
9494
if (user.data()) {
95+
// remove id field if exist in fetched data or profileDiff
96+
if ("id" in userData) {
97+
delete userData.id;
98+
}
9599
await userModel.doc(userId).set(
96100
{
97101
...user.data(),

0 commit comments

Comments
 (0)