This commit is contained in:
payacom
2026-08-31 20:45:41 +03:30
parent fa9f23c61d
commit 3f416a7a60
367 changed files with 621895 additions and 6443 deletions

View File

@@ -337,6 +337,38 @@ const getAdvertisingCategoryById = async (req, res, next) => {
}
};
/**
* PATCH /advertising/advertising-categories/:id
*/
const updateAdvertisingCategory = async (req, res, next) => {
try {
const { id } = req.params;
if (!id || !id.match(/^[0-9a-fA-F]{24}$/)) {
return res.status(400).json({ success: false, message: 'شناسه معتبر نیست' });
}
const { title, status, relatedExpertise } = req.body;
const update = {};
if (typeof title !== 'undefined') update.title = title.trim();
if (typeof status !== 'undefined') update.status = status;
if (typeof relatedExpertise !== 'undefined') {
if (!Array.isArray(relatedExpertise)) {
return res.status(422).json({ success: false, message: 'اطلاعات ارسالی اشتباه است' });
}
update.relatedExpertise = relatedExpertise;
}
const category = await AdvertisingCategoryModel.findByIdAndUpdate(id, update, { new: true });
if (!category) {
return res.status(404).json({ success: false, message: 'دسته‌بندی یافت نشد' });
}
return res.status(200).json({ success: true, message: 'دسته‌بندی با موفقیت ویرایش شد', data: category });
} catch (error) {
next(error);
}
};
module.exports = {
getSingleAdvertising,
@@ -345,6 +377,7 @@ module.exports = {
createAdvertisingCategory,
getAdvertisingCategories,
getAdvertisingCategoryById,
updateAdvertisingCategory,
acceptAdvertising,
rejectAdvertising
}