Files
rentall-app/backend/routes/users.js
jackiettran c09384e3ea Initial commit - Rentall App
- Full-stack rental marketplace application
- React frontend with TypeScript
- Node.js/Express backend with JWT authentication
- Features: item listings, rental requests, calendar availability, user profiles
2025-07-15 21:21:09 -04:00

38 lines
990 B
JavaScript

const express = require('express');
const { User } = require('../models'); // Import from models/index.js to get models with associations
const { authenticateToken } = require('../middleware/auth');
const router = express.Router();
router.get('/profile', authenticateToken, async (req, res) => {
try {
const user = await User.findByPk(req.user.id, {
attributes: { exclude: ['password'] }
});
res.json(user);
} catch (error) {
res.status(500).json({ error: error.message });
}
});
router.put('/profile', authenticateToken, async (req, res) => {
try {
const { firstName, lastName, phone, address } = req.body;
await req.user.update({
firstName,
lastName,
phone,
address
});
const updatedUser = await User.findByPk(req.user.id, {
attributes: { exclude: ['password'] }
});
res.json(updatedUser);
} catch (error) {
res.status(500).json({ error: error.message });
}
});
module.exports = router;