Integrate Web Pricing Editor and update configurations
This commit is contained in:
@ -28,7 +28,7 @@ app.use(session({
|
||||
},
|
||||
}));
|
||||
|
||||
const pricingData = JSON.parse(
|
||||
let pricingData = JSON.parse(
|
||||
fs.readFileSync(path.join(__dirname, 'data', 'pricing.json'), 'utf-8')
|
||||
);
|
||||
|
||||
@ -71,6 +71,38 @@ app.get('/api/pricing', requireAuth, (req, res) => {
|
||||
res.json(pricingData);
|
||||
});
|
||||
|
||||
app.post('/api/pricing', requireAuth, (req, res) => {
|
||||
try {
|
||||
const newPricing = req.body;
|
||||
if (!newPricing || typeof newPricing !== 'object') {
|
||||
return res.status(400).json({ error: 'Invalid pricing data format' });
|
||||
}
|
||||
// Basic validation
|
||||
const requiredSections = ['operators', 'groundLoopStyles', 'loopDetectors', 'groundLoopSizes', 'groundLoopTypes', 'remoteButtonOptions', 'accessControl'];
|
||||
for (const section of requiredSections) {
|
||||
if (!Array.isArray(newPricing[section])) {
|
||||
return res.status(400).json({ error: `Missing or invalid section: ${section}` });
|
||||
}
|
||||
}
|
||||
|
||||
const pricingPath = path.join(__dirname, 'data', 'pricing.json');
|
||||
const backupPath = path.join(__dirname, 'data', 'pricing.backup.json');
|
||||
|
||||
// Create a backup of the current pricing.json
|
||||
fs.copyFileSync(pricingPath, backupPath);
|
||||
|
||||
// Save the new pricing data
|
||||
fs.writeFileSync(pricingPath, JSON.stringify(newPricing, null, 2), 'utf-8');
|
||||
|
||||
// Update the in-memory data
|
||||
pricingData = newPricing;
|
||||
|
||||
res.json({ success: true, message: 'Pricing updated successfully', backupCreated: true });
|
||||
} catch (err) {
|
||||
res.status(500).json({ error: 'Failed to save pricing data: ' + err.message });
|
||||
}
|
||||
});
|
||||
|
||||
app.get('/api/pricing/:category', requireAuth, (req, res) => {
|
||||
const { category } = req.params;
|
||||
const validCategories = ['operators', 'groundLoopStyles', 'groundLoopSizes', 'loopDetectors', 'groundLoopTypes', 'accessControl', 'remoteButtonOptions'];
|
||||
|
||||
Reference in New Issue
Block a user