AdminLTE3
This commit is contained in:
@@ -216,6 +216,114 @@ router.post('/services', requireAuth, async (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
router.put('/services/:id', requireAuth, async (req, res) => {
|
||||
try {
|
||||
const service = await Service.findByPk(req.params.id);
|
||||
if (!service) {
|
||||
return res.status(404).json({ success: false, message: 'Service not found' });
|
||||
}
|
||||
|
||||
const {
|
||||
name,
|
||||
description,
|
||||
shortDescription,
|
||||
icon,
|
||||
category,
|
||||
features,
|
||||
pricing,
|
||||
estimatedTime,
|
||||
isActive,
|
||||
featured,
|
||||
tags,
|
||||
order,
|
||||
seo
|
||||
} = req.body;
|
||||
|
||||
// Parse arrays and objects
|
||||
let featuresArray = [];
|
||||
let tagsArray = [];
|
||||
let pricingObj = {};
|
||||
let seoObj = {};
|
||||
|
||||
if (features) {
|
||||
if (Array.isArray(features)) {
|
||||
featuresArray = features;
|
||||
} else {
|
||||
try {
|
||||
featuresArray = JSON.parse(features);
|
||||
} catch (e) {
|
||||
featuresArray = features.split(',').map(f => f.trim());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (tags) {
|
||||
if (Array.isArray(tags)) {
|
||||
tagsArray = tags;
|
||||
} else {
|
||||
try {
|
||||
tagsArray = JSON.parse(tags);
|
||||
} catch (e) {
|
||||
tagsArray = tags.split(',').map(t => t.trim());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (pricing) {
|
||||
if (typeof pricing === 'object') {
|
||||
pricingObj = pricing;
|
||||
} else {
|
||||
try {
|
||||
pricingObj = JSON.parse(pricing);
|
||||
} catch (e) {
|
||||
pricingObj = { basePrice: pricing };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (seo) {
|
||||
if (typeof seo === 'object') {
|
||||
seoObj = seo;
|
||||
} else {
|
||||
try {
|
||||
seoObj = JSON.parse(seo);
|
||||
} catch (e) {
|
||||
seoObj = {};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const updateData = {
|
||||
name,
|
||||
description,
|
||||
shortDescription,
|
||||
icon,
|
||||
category,
|
||||
features: featuresArray,
|
||||
pricing: pricingObj,
|
||||
estimatedTime,
|
||||
isActive: Boolean(isActive),
|
||||
featured: Boolean(featured),
|
||||
tags: tagsArray,
|
||||
order: order ? parseInt(order) : 0,
|
||||
seo: seoObj
|
||||
};
|
||||
|
||||
// Remove undefined values
|
||||
Object.keys(updateData).forEach(key => {
|
||||
if (updateData[key] === undefined) {
|
||||
delete updateData[key];
|
||||
}
|
||||
});
|
||||
|
||||
await service.update(updateData);
|
||||
res.json({ success: true, service });
|
||||
} catch (error) {
|
||||
console.error('Service update error:', error);
|
||||
res.status(500).json({ success: false, message: error.message });
|
||||
}
|
||||
});
|
||||
|
||||
router.delete('/services/:id', requireAuth, async (req, res) => {
|
||||
try {
|
||||
const service = await Service.findByPk(req.params.id);
|
||||
|
||||
Reference in New Issue
Block a user