Files
MyPOS/server/controller/settingsController.js
2025-11-13 19:09:00 +08:00

63 lines
1.6 KiB
JavaScript

import supabase from "../config/supabaseClient.js";
export const getSettings = async (req, res) => {
try {
const { data: settings, error } = await supabase
.from('settings')
.select('*')
.order('setting_id', { ascending: true })
.limit(1);
if (error) throw error;
res.json(settings);
} catch (error) {
console.error('Error fetching settings:', error);
res.status(500).json({ error: 'Failed to fetch settings' });
}
};
export const updateSettings = async (req, res) => {
const {
store_name,
address,
contact,
tax_rate,
pwd_discount_rate,
senior_discount_rate,
dark_mode,
fullscreen_mode,
store_logo_url,
business_hours,
receipt_footer
} = req.body;
try {
const { data: settings, error } = await supabase
.from('settings')
.update({
store_name,
address,
contact,
tax_rate,
pwd_discount_rate,
senior_discount_rate,
dark_mode,
fullscreen_mode,
store_logo_url,
business_hours,
receipt_footer
// Remove updated_at since the column doesn't exist
})
.eq('setting_id', 1)
.select()
.single();
if (error) throw error;
res.json(settings);
} catch (error) {
console.error('Error updating settings:', error);
res.status(500).json({ error: 'Failed to update settings' });
}
};