feat: Enhance favorites management with validation, update data structure, and improve UI interactions

This commit is contained in:
Marco Beretta 2025-11-24 21:18:16 +01:00
parent bfeae91a96
commit 960e2ee527
No known key found for this signature in database
GPG key ID: D918033D8E74CC11
10 changed files with 117 additions and 31 deletions

View file

@ -9,6 +9,28 @@ const updateFavoritesController = async (req, res) => {
return res.status(400).json({ message: 'Favorites data is required' });
}
// Validate favorites structure
if (!Array.isArray(favorites)) {
return res.status(400).json({ message: 'Favorites must be an array' });
}
for (const fav of favorites) {
const hasAgent = !!fav.agentId;
const hasModel = !!(fav.model && fav.endpoint);
if (!hasAgent && !hasModel) {
return res.status(400).json({
message: 'Each favorite must have either agentId or model+endpoint',
});
}
if (hasAgent && hasModel) {
return res.status(400).json({
message: 'Favorite cannot have both agentId and model/endpoint',
});
}
}
const user = await User.findByIdAndUpdate(
userId,
{ $set: { favorites } },