full
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user