feat: add updatedAt field to user profile endpoints

- Add updated_at to SELECT query in getProfile
- Add updatedAt to response in getProfile
- Auto-update updated_at timestamp in updateProfile
- Add updated_at to RETURNING clause in updateProfile
- Include isVerified, createdAt, updatedAt in updateProfile response

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
soufiane 2025-11-22 17:53:31 +01:00
parent a76cf4e887
commit 3e08a647a5

View File

@ -13,7 +13,7 @@ export const getProfile = asyncHandler(async (req, res) => {
const userId = req.user.id;
const result = await pool.query(
`SELECT id, email, first_name, last_name, phone, address, city, postal_code, role, is_verified, created_at
`SELECT id, email, first_name, last_name, phone, address, city, postal_code, role, is_verified, created_at, updated_at
FROM users WHERE id = $1`,
[userId]
);
@ -34,6 +34,7 @@ export const getProfile = asyncHandler(async (req, res) => {
role: user.role,
isVerified: user.is_verified,
createdAt: user.created_at,
updatedAt: user.updated_at,
},
});
});
@ -83,13 +84,15 @@ export const updateProfile = asyncHandler(async (req, res) => {
});
}
// Ajouter updated_at à la mise à jour
updates.push(`updated_at = NOW()`);
values.push(userId);
const query = `
UPDATE users
SET ${updates.join(', ')}
WHERE id = $${paramCount}
RETURNING id, email, first_name, last_name, phone, address, city, postal_code, role
RETURNING id, email, first_name, last_name, phone, address, city, postal_code, role, is_verified, created_at, updated_at
`;
const result = await pool.query(query, values);
@ -108,6 +111,9 @@ export const updateProfile = asyncHandler(async (req, res) => {
city: user.city,
postalCode: user.postal_code,
role: user.role,
isVerified: user.is_verified,
createdAt: user.created_at,
updatedAt: user.updated_at,
},
});
});