Skip to content

Commit

Permalink
Merge pull request #2253 from RahulGoyal-tech/iss2223
Browse files Browse the repository at this point in the history
Added function for unobfuscated profileDiffs, filtered id while updating profileDiffs
  • Loading branch information
lakshayman authored Dec 1, 2024
2 parents 10bc222 + 6dbda50 commit 4e5f5da
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
10 changes: 8 additions & 2 deletions controllers/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -678,8 +678,14 @@ const getUserImageForVerification = async (req, res) => {
const updateUser = async (req, res) => {
try {
const { id: profileDiffId, message } = req.body;

const profileDiffData = await profileDiffsQuery.fetchProfileDiff(profileDiffId);
const devFeatureFlag = req.query.dev;
let profileDiffData;
if (devFeatureFlag === "true") {
profileDiffData = await profileDiffsQuery.fetchProfileDiffUnobfuscated(profileDiffId);
} else {
profileDiffData = await profileDiffsQuery.fetchProfileDiff(profileDiffId);
}
Object.freeze(profileDiffData);
if (!profileDiffData) return res.boom.notFound("Profile Diff doesn't exist");

const { approval, timestamp, userId, ...profileDiff } = profileDiffData;
Expand Down
25 changes: 25 additions & 0 deletions models/profileDiffs.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,30 @@ const fetchProfileDiff = async (profileDiffId) => {
}
};

/**
* Fetches the unobfuscated profileDiff data of the provided profileDiff Id
* @param profileDiffId profileDiffId of the diffs need to be fetched
* @returns unobfuscated profileDiff Data
*/
const fetchProfileDiffUnobfuscated = async (profileDiffId) => {
try {
const profileDiff = await profileDiffsModel.doc(profileDiffId).get();

if (!profileDiff.exists) {
return { profileDiffExists: false };
}
const profileDiffData = profileDiff.data();
return {
id: profileDiff.id,
profileDiffExists: true,
...profileDiffData,
};
} catch (err) {
logger.error("Error retrieving Unobfuscated profile Diff", err);
throw err;
}
};

/** Add profileDiff
*
* @param profileDiffData { Object }: Data to be added
Expand Down Expand Up @@ -181,4 +205,5 @@ module.exports = {
add,
updateProfileDiff,
fetchProfileDiffsWithPagination,
fetchProfileDiffUnobfuscated,
};
4 changes: 4 additions & 0 deletions models/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ const addOrUpdate = async (userData, userId = null) => {
const isNewUser = !user.data();
// user exists update user
if (user.data()) {
// remove id field if exist in fetched data or profileDiff
if ("id" in userData) {
delete userData.id;
}
await userModel.doc(userId).set(
{
...user.data(),
Expand Down

0 comments on commit 4e5f5da

Please sign in to comment.