Workout Management tests done
This commit is contained in:
Binary file not shown.
@@ -139,30 +139,28 @@ router.patch('/profile', validate(updateProfileSchema), async (req, res) => {
|
||||
const token = req.headers.authorization?.split(' ')[1];
|
||||
if (!token) return res.status(401).json({ error: 'Unauthorized' });
|
||||
|
||||
const { userId, profile } = req.body;
|
||||
// const { userId, profile } = req.body;
|
||||
|
||||
|
||||
// Convert birthDate from timestamp to Date object if needed
|
||||
if (profile.birthDate) {
|
||||
if (req.body.birthDate) {
|
||||
// Handle both number (timestamp) and string (ISO)
|
||||
profile.birthDate = new Date(profile.birthDate);
|
||||
req.body.birthDate = new Date(req.body.birthDate);
|
||||
}
|
||||
|
||||
// Verify token
|
||||
const decoded = jwt.verify(token, JWT_SECRET) as any;
|
||||
if (decoded.userId !== userId) {
|
||||
return res.status(403).json({ error: 'Forbidden' });
|
||||
}
|
||||
const userId = decoded.userId;
|
||||
|
||||
// Update or create profile
|
||||
await prisma.userProfile.upsert({
|
||||
where: { userId: userId },
|
||||
update: {
|
||||
...profile
|
||||
...req.body
|
||||
},
|
||||
create: {
|
||||
userId: userId,
|
||||
...profile
|
||||
...req.body
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user