Skip to content

Commit a18b1bf

Browse files
RahulGoyal-techbyt3quester
authored andcommitted
Added seperate function for unobfuscated contact details and filtered id in update data step.
1 parent f497bdd commit a18b1bf

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

controllers/users.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,7 @@ const updateUser = async (req, res) => {
654654
try {
655655
const { id: profileDiffId, message } = req.body;
656656

657-
const profileDiffData = await profileDiffsQuery.fetchProfileDiff(profileDiffId);
657+
const profileDiffData = await profileDiffsQuery.fetchProfileDiffUnobfuscated(profileDiffId);
658658
if (!profileDiffData) return res.boom.notFound("Profile Diff doesn't exist");
659659

660660
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 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: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,17 @@ const addOrUpdate = async (userData, userId = null) => {
4444
const isNewUser = !user.data();
4545
// user exists update user
4646
if (user.data()) {
47+
// remove id field if exist in fetched data or profileDiff
48+
const currentData = user.data();
49+
if ("id" in currentData) {
50+
delete currentData.id;
51+
}
52+
if ("id" in userData) {
53+
delete userData.id;
54+
}
4755
await userModel.doc(userId).set(
4856
{
49-
...user.data(),
57+
...currentData,
5058
...userData,
5159
updated_at: Date.now(),
5260
},

0 commit comments

Comments
 (0)