import settingsService from '../services/settingsService.js'; export const filterSettings = async (req, res) => { const { userid, type } = req.body; try { const responseFields = await settingsService.filterSettings(userid, type); res.status(200).json(responseFields); } catch (error) { console.error('Error filtering settings:', error); res.status(500).json({ error: 'An error occurred while filtering the settings' }); } }; export const updateSetting = async (req, res) => { const { userid, settingId, value } = req.body; try { await settingsService.updateSetting(userid, settingId, value); res.status(200).json({ message: 'Setting updated successfully' }); } catch (error) { console.error('Error updating user setting:', error); res.status(500).json({ error: 'Internal server error' }); } }; export const getTypeParamValueId = async (req, res) => { const { paramValue } = req.body; try { const paramValueId = await settingsService.getTypeParamValueId(paramValue); res.status(200).json({ paramValueId }); } catch (error) { console.error('Error retrieving parameter value ID:', error); res.status(404).json({ error: "notfound" }); } }; export const getTypeParamValues = async (req, res) => { const { type } = req.body; try { const paramValues = await settingsService.getTypeParamValues(type); res.status(200).json(paramValues); } catch (error) { console.error('Error retrieving parameter values:', error); res.status(500).json({ error: 'An error occurred while retrieving the parameter values' }); } } export const getTypeParamValue = async (req, res) => { const { id } = req.params; try { const paramValue = await settingsService.getTypeParamValue(id); res.status(200).json({ paramValue }); } catch (error) { console.error('Error retrieving parameter value:', error); res.status(404).json({ error: "notfound" }); } }; export const getAccountSettings = async (req, res) => { try { const { userId } = req.body; const accountSettings = await settingsService.getAccountSettings(userId); res.status(200).json(accountSettings); } catch (error) { console.error('Error retrieving account settings:', error); res.status(500).json({ error: 'Internal server error' }); } }; export const setAccountSettings = async (req, res) => { try { await settingsService.setAccountSettings(req.body); res.status(200).json({ message: 'Account settings updated successfully' }); } catch (error) { console.error('Error updating account settings:', error); res.status(500).json({ error: 'Internal server error' }); } }; export const getPossibleInterests = async (req, res) => { try { const { userid: userId } = req.headers; const interests = await settingsService.getPossibleInterests(userId); res.status(200).json(interests); } catch (error) { console.error('Error retrieving possible interests:', error); res.status(500).json({ error: 'An error occurred while retrieving the possible interests' }); } } export const getInterests = async (req, res) => { try { const { userid: userId } = req.headers; const interests = await settingsService.getInterests(userId); res.status(200).json(interests); } catch (error) { console.error('Error retrieving interests:', error); res.status(500).json({ error: 'Internal server error' }); } } export const addInterest = async (req, res) => { try { const { userid: userId } = req.headers; const { name } = req.body; const interest = await settingsService.addInterest(userId, name); res.status(200).json({ interest }); } catch (error) { console.error('Error adding interest:', error); res.status(500).json({ error: 'Internal server error' }); } } export const addUserInterest = async (req, res) => { try { const { userid: userId } = req.headers; const { interestid: interestId } = req.body; await settingsService.addUserInterest(userId, interestId); res.status(200).json({ message: 'User interest added successfully' }); } catch (error) { console.error('Error adding user interest:', error); res.status(500).json({ error: 'Internal server error' }); } } export const removeInterest = async (req, res) => { try { const { userid: userId } = req.headers; const { id: interestId } = req.params; await settingsService.removeInterest(userId, interestId); res.status(200).json({ message: 'Interest removed successfully' }); } catch (error) { console.error('Error removing interest:', error); res.status(500).json({ error: 'Internal server error' }); } }