61 lines
1.4 KiB
JavaScript
61 lines
1.4 KiB
JavaScript
const { getUserById } = require('../models/user');
|
|
const logger = require('../utils/logger');
|
|
|
|
/**
|
|
* Get current user profile
|
|
* @param {Object} req - Express request object
|
|
* @param {Object} res - Express response object
|
|
* @param {Function} next - Express next middleware function
|
|
*/
|
|
const getProfile = async (req, res, next) => {
|
|
try {
|
|
// User is already attached to req by auth middleware
|
|
const userId = req.user.id;
|
|
|
|
// Get full user details from database
|
|
const user = await getUserById(userId);
|
|
|
|
if (!user) {
|
|
return res.status(404).json({
|
|
error: 'Not Found',
|
|
message: 'User not found'
|
|
});
|
|
}
|
|
|
|
// Return user data (excluding password)
|
|
res.status(200).json({
|
|
user: {
|
|
id: user.id,
|
|
email: user.email,
|
|
createdAt: user.created_at
|
|
}
|
|
});
|
|
} catch (error) {
|
|
next(error);
|
|
}
|
|
};
|
|
|
|
/**
|
|
* Update user profile
|
|
* @param {Object} req - Express request object
|
|
* @param {Object} res - Express response object
|
|
* @param {Function} next - Express next middleware function
|
|
*/
|
|
const updateProfile = async (req, res, next) => {
|
|
try {
|
|
// TODO: Implement user profile update functionality
|
|
// This would include updating user details in the database
|
|
|
|
res.status(501).json({
|
|
message: 'Profile update functionality not yet implemented'
|
|
});
|
|
} catch (error) {
|
|
next(error);
|
|
}
|
|
};
|
|
|
|
module.exports = {
|
|
getProfile,
|
|
updateProfile
|
|
};
|