U
All checks were successful
Deploy to Production / deploy (push) Successful in 20s

This commit is contained in:
silverpro89
2026-02-27 20:10:15 +07:00
parent 6287a019e3
commit f96833a7e4
10 changed files with 37 additions and 58 deletions

View File

@@ -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,