Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions controllers/getUser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const createError = require("http-errors");
const axios = require("axios");
const User = require("../models/user");
const mongoose = require("mongoose");


exports.getUser = async (req, res, next) => {
try {
const { id } = req.params;
console.log('Received user ID:', id);
const user = await User.findById(id);
if (!user) {
return next(createError(404, "User not found"));
}

res.status(200).json(user);

} catch (err) {
next(err);
}
}
35 changes: 35 additions & 0 deletions controllers/makeProfileController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const createError = require("http-errors");
const axios = require("axios");
const User = require("../models/user");
const mongoose = require("mongoose");

exports.makeProfile = async (req, res, next) => {
try {
console.log("in the makeProfile controller")
const { id } = req.params;
const { name, email, githubLink, telegram, twitter, location, photo } = req.body; // get the new profile data from the request body


const user = await User.findById(id);
if (!user) {
return next(createError(404, 'User not found'));
}


user.name = name;
user.email = email;
user.githubLink = githubLink;
user.telegram = telegram;
user.twitter = twitter;
user.location = location;
user.photo = photo;

const updatedUser = await user.save();

res.status(200).json({ message: 'Profile updated successfully', user: updatedUser });
} catch (error) {
// Handle errors
console.error('Error updating profile:', error);
res.status(500).json({ message: 'Internal server error' });
}
};
1 change: 1 addition & 0 deletions controllers/makeUserController.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ exports.makeUser = async (req, res, next) => {
console.error('Error creating user:', error);
res.status(500).json({ message: 'Internal server error' });
}

}
3 changes: 2 additions & 1 deletion routes/projectRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const { getCurrentUser } = require("../controllers/getCurrentUser");
const { getAllUsers } = require("../controllers/getAllUsers");
const { getUserById } = require("../controllers/getUserById");
const { getProjectByUserId } = require("../controllers/getProjectByUserId");
const { makeProfile } = require("../controllers/makeProfileController");

//IMPORT USER ROUTES
const { makeUser } = require("../controllers/makeUserController");
Expand All @@ -21,7 +22,7 @@ const { makeUser } = require("../controllers/makeUserController");
router.post("/newUser", makeUser);
router.get("/getprofile", authUser, getCurrentUser);
router.get("/getUserById/:id", getUserById);

router.post("/makeProfile/:id", makeProfile)

router.get("/allusers", getAllUsers);

Expand Down