diff --git a/controllers/categoryController.js b/controllers/categoryController.js index ae651ea..2e61607 100644 --- a/controllers/categoryController.js +++ b/controllers/categoryController.js @@ -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, diff --git a/data/familynfriend/g1/F11.json b/data/familynfriend/g1/F11.json index d56ed06..746976b 100644 --- a/data/familynfriend/g1/F11.json +++ b/data/familynfriend/g1/F11.json @@ -66,9 +66,6 @@ { "grade": "010106", "vocab": [ - "Rosy", - "Tim", - "Billy", "Mom", "clean", "tidy", diff --git a/data/familynfriend/g1/F12.json b/data/familynfriend/g1/F12.json index 34f43e7..cf478aa 100644 --- a/data/familynfriend/g1/F12.json +++ b/data/familynfriend/g1/F12.json @@ -75,10 +75,7 @@ "ao dai" ], "phonics": null, - "grammar": [ - "They are dancers from Viet Nam.", - "They have fans." - ] + "grammar": null }, { "grade": "010208", diff --git a/data/familynfriend/g1/F14.json b/data/familynfriend/g1/F14.json index 9ced5b7..f487e60 100644 --- a/data/familynfriend/g1/F14.json +++ b/data/familynfriend/g1/F14.json @@ -91,9 +91,7 @@ "phonics": null, "grammar": [ "A flower!", - "A frog!", - "It's a bird.", - "score a goal" + "A frog!" ] }, { diff --git a/data/familynfriend/g1/F15.json b/data/familynfriend/g1/F15.json index c063e8d..169076a 100644 --- a/data/familynfriend/g1/F15.json +++ b/data/familynfriend/g1/F15.json @@ -79,8 +79,7 @@ "phonics": null, "grammar": [ "This is...", - "These are...", - "Let's take care in the sun." + "These are..." ] }, { diff --git a/data/familynfriend/g1/F16.json b/data/familynfriend/g1/F16.json index 0ba1acd..ae32023 100644 --- a/data/familynfriend/g1/F16.json +++ b/data/familynfriend/g1/F16.json @@ -69,8 +69,7 @@ "vocab": [], "phonics": null, "grammar": [ - "I have ...", - "Share with others." + "I have ..." ] }, { diff --git a/data/familynfriend/g1/F1S.json b/data/familynfriend/g1/F1S.json index 0c5a7dd..078d2c1 100644 --- a/data/familynfriend/g1/F1S.json +++ b/data/familynfriend/g1/F1S.json @@ -3,10 +3,7 @@ "grade": "010001", "vocab": [ "hello", - "goodbye", - "Rosy", - "Tim", - "Billy" + "goodbye" ], "phonics": null, "grammar": [ @@ -18,17 +15,9 @@ }, { "grade": "010002", - "vocab": [ - "hello", - "goodbye", - "Rosy", - "Tim", - "Billy" - ], + "vocab": null, "phonics": null, "grammar": [ - "What's your name?", - "I'm ...", "Stand up", "Sit down", "Line up", @@ -78,16 +67,10 @@ "vocab": [ "hello", "goodbye", - "Rosy", - "Tim", - "Billy", - "Mom", - "Miss Bell" + "Mom" ], "phonics": null, - "grammar": [ - "It is good to say Hello and Goodbye." - ] + "grammar": null }, { "grade": "010007", @@ -101,8 +84,7 @@ ], "phonics": null, "grammar": [ - "I'm from ...", - "It's red and white." + "I'm from ..." ] }, { diff --git a/data/moveup/g1/M11.json b/data/moveup/g1/M11.json index dd7a5b1..88ff55f 100644 --- a/data/moveup/g1/M11.json +++ b/data/moveup/g1/M11.json @@ -4,14 +4,10 @@ "vocab": [ "pink", "brown", - "white", - "Hello", - "Nice to meet you" + "white" ], "phonics": null, "grammar": [ - "Hello.", - "Nice to meet you.", "This is...", "What color is it?", "It's..." diff --git a/data/moveup/g1/M14.json b/data/moveup/g1/M14.json index 6d41609..d78c4da 100644 --- a/data/moveup/g1/M14.json +++ b/data/moveup/g1/M14.json @@ -8,8 +8,7 @@ ], "phonics": null, "grammar": [ - "What's this?", - "Point and say." + "What's this?" ] }, { @@ -159,8 +158,7 @@ ], "phonics": null, "grammar": [ - "Hello, I'm... the lion.", - "Nice to meet you." + "Hello, I'm... the lion." ] } ] \ No newline at end of file diff --git a/routes/categoryRoutes.js b/routes/categoryRoutes.js index 60df480..ad6ebe1 100644 --- a/routes/categoryRoutes.js +++ b/routes/categoryRoutes.js @@ -21,9 +21,6 @@ router.get('/code/:code', categoryController.getCategoryByCode); // GET /api/categories/:id - Get category by ID router.get('/:id', categoryController.getCategoryById); -// GET /api/categories/:id/subjects - Get subjects by category -router.get('/:id/subjects', categoryController.getSubjectsByCategory); - // POST /api/categories - Create new category router.post('/', categoryController.createCategory); @@ -34,6 +31,9 @@ router.put('/:id', categoryController.updateCategory); router.delete('/:id', categoryController.deleteCategory); // ============ Nested Subject Routes ============ +// GET /api/categories/:id/subjects - Get subjects by category +router.get('/:id/subjects', categoryController.getSubjectsByCategory); + // POST /api/categories/:categoryId/subjects - Add subject to category router.post('/:categoryId/subjects', categoryController.addSubjectToCategory);