This commit is contained in:
@@ -291,7 +291,7 @@ class CategoryController {
|
||||
// Generate cache key
|
||||
const cacheKey = `category:${id}:subjects:${page}:${limit}:${is_active || 'all'}`;
|
||||
|
||||
// Try cache first
|
||||
/* Try cache first
|
||||
const cached = await cacheUtils.get(cacheKey);
|
||||
if (cached) {
|
||||
return res.json({
|
||||
@@ -300,7 +300,7 @@ class CategoryController {
|
||||
cached: true,
|
||||
});
|
||||
}
|
||||
|
||||
*/
|
||||
// Check if category exists
|
||||
const category = await Categories.findByPk(id);
|
||||
if (!category) {
|
||||
@@ -356,7 +356,14 @@ class CategoryController {
|
||||
async addSubjectToCategory(req, res, next) {
|
||||
try {
|
||||
const { categoryId } = req.params;
|
||||
const subjectData = req.body;
|
||||
const { id } = req.body;
|
||||
|
||||
if (!id) {
|
||||
return res.status(400).json({
|
||||
success: false,
|
||||
message: 'Subject id is required',
|
||||
});
|
||||
}
|
||||
|
||||
// Check if category exists
|
||||
const category = await Categories.findByPk(categoryId);
|
||||
@@ -367,17 +374,23 @@ class CategoryController {
|
||||
});
|
||||
}
|
||||
|
||||
// Create subject with category_id
|
||||
const subject = await Subject.create({
|
||||
...subjectData,
|
||||
category_id: categoryId,
|
||||
});
|
||||
// Find existing subject
|
||||
const subject = await Subject.findByPk(id);
|
||||
if (!subject) {
|
||||
return res.status(404).json({
|
||||
success: false,
|
||||
message: 'Subject not found',
|
||||
});
|
||||
}
|
||||
|
||||
// Assign category
|
||||
await subject.update({ category_id: categoryId });
|
||||
|
||||
// Clear cache
|
||||
await cacheUtils.deletePattern('subjects:list:*');
|
||||
await cacheUtils.deletePattern(`category:${categoryId}:subjects:*`);
|
||||
|
||||
res.status(201).json({
|
||||
res.json({
|
||||
success: true,
|
||||
message: 'Subject added to category successfully',
|
||||
data: subject,
|
||||
|
||||
Reference in New Issue
Block a user