diff --git a/controllers/users.js b/controllers/users.js index c6cb0375e..79e554223 100644 --- a/controllers/users.js +++ b/controllers/users.js @@ -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; diff --git a/models/profileDiffs.js b/models/profileDiffs.js index 494e192c9..34b64e340 100644 --- a/models/profileDiffs.js +++ b/models/profileDiffs.js @@ -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 @@ -181,4 +205,5 @@ module.exports = { add, updateProfileDiff, fetchProfileDiffsWithPagination, + fetchProfileDiffUnobfuscated, }; diff --git a/models/users.js b/models/users.js index a47575bed..ce840a354 100644 --- a/models/users.js +++ b/models/users.js @@ -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(),