MCPcopy Create free account
hub / github.com/RealDevSquad/website-backend / updateUser

Function updateUser

controllers/users.js:767–809  ·  view source on GitHub ↗
(req, res)

Source from the content-addressed store, hash-verified

765 * Updates the user data
766 *
767 * @param req {Object} - Express request object
768 * @param res {Object} - Express response object
769 */
770const updateUser = async (req, res) => {
771 try {
772 const { id: profileDiffId, message } = req.body;
773 const devFeatureFlag = req.query.dev === "true";
774 let profileDiffData;
775
776 const userDoc = await usersCollection.doc(req.params.userId).get();
777 if (!userDoc.exists) {
778 return res.boom.notFound("The User doesn't exist.");
779 }
780
781 if (devFeatureFlag) {
782 profileDiffData = await profileDiffsQuery.fetchProfileDiffUnobfuscated(profileDiffId);
783 } else {
784 profileDiffData = await profileDiffsQuery.fetchProfileDiff(profileDiffId);
785 }
786 Object.freeze(profileDiffData);
787 if (!profileDiffData) return res.boom.notFound("Profile Diff doesn't exist");
788
789 const { approval, timestamp, userId, ...profileDiff } = profileDiffData;
790
791 const user = await dataAccess.retrieveUsers({ id: userId });
792 if (!user.userExists) return res.boom.notFound("User doesn't exist");
793
794 await profileDiffsQuery.updateProfileDiff({ approval: profileDiffStatus.APPROVED }, profileDiffId);
795
796 await userQuery.addOrUpdate(profileDiff, userId, devFeatureFlag);
797
798 const meta = {
799 approvedBy: req.userData.id,
800 userId: userId,
801 };
802
803 await logsQuery.addLog(logType.PROFILE_DIFF_APPROVED, meta, { profileDiffId, message });
804
805 return res.json({
806 message: "Updated user's data successfully!",
807 });
808 } catch (error) {
809 logger.error(`Error while updating user data: ${error}`);
810 return res.boom.badImplementation(INTERNAL_SERVER_ERROR);
811 }
812};

Callers 2

updateProfileFunction · 0.70

Calls 1

getMethod · 0.80

Tested by

no test coverage detected