From 9af45a7875deefd120f1171d0dc1ded03cefdf05 Mon Sep 17 00:00:00 2001 From: silverpro89 Date: Thu, 26 Feb 2026 15:00:58 +0700 Subject: [PATCH] update backend --- controllers/categoryController.js | 2 +- controllers/vocabController.js | 36 +++++++++++++++++++++++++++++++ data/familynfriend/g1/F11.json | 16 ++------------ data/familynfriend/g1/F15.json | 4 +--- data/familynfriend/g1/F1S.json | 9 +------- data/familynfriend/g5/F510.json | 2 +- models/Categories.js | 2 +- models/Vocab.js | 6 ++++++ 8 files changed, 49 insertions(+), 28 deletions(-) diff --git a/controllers/categoryController.js b/controllers/categoryController.js index 3e90e42..408ae68 100644 --- a/controllers/categoryController.js +++ b/controllers/categoryController.js @@ -311,7 +311,7 @@ class CategoryController { } // Build query conditions - const where = { category_id: id }; + const where = { id: id }; if (is_active !== undefined) where.is_active = is_active === 'true'; // Query subjects diff --git a/controllers/vocabController.js b/controllers/vocabController.js index d6dd944..8feddc3 100644 --- a/controllers/vocabController.js +++ b/controllers/vocabController.js @@ -67,6 +67,7 @@ exports.createVocab = async (req, res) => { vi, category, topic, + grade_number = 0, image_small, image_square, image_normal, @@ -103,6 +104,7 @@ exports.createVocab = async (req, res) => { syntax: syntax || null, semantics: semantics || null, constraints: constraints || null, + grade_number: grade_number || 0, is_active: true }); @@ -166,6 +168,8 @@ exports.getAllVocabs = async (req, res) => { base_word, text, search, + grade_start, + grade_end, is_active = true } = req.query; @@ -202,6 +206,21 @@ exports.getAllVocabs = async (req, res) => { ]; } + // Grade number range filter + if (grade_start !== undefined && grade_end !== undefined) { + const s = parseInt(grade_start); + const e = parseInt(grade_end); + if (s === e) { + where.grade_number = s; + } else if (s < e) { + where.grade_number = { [Op.between]: [s, e] }; + } + } else if (grade_start !== undefined) { + where.grade_number = { [Op.gte]: parseInt(grade_start) }; + } else if (grade_end !== undefined) { + where.grade_number = { [Op.lte]: parseInt(grade_end) }; + } + const { count, rows } = await Vocab.findAndCountAll({ where, limit: parseInt(limit), @@ -786,6 +805,8 @@ exports.searchVocabs = async (req, res) => { form_key, text, vi, + grade_start, + grade_end, v_type, shuffle_pos, page = 1, @@ -825,6 +846,21 @@ exports.searchVocabs = async (req, res) => { where.vi = { [Op.like]: `%${vi}%` }; } + // Grade number range filter + if (grade_start !== undefined && grade_end !== undefined) { + const s = parseInt(grade_start); + const e = parseInt(grade_end); + if (s === e) { + where.grade_number = s; + } else if (s < e) { + where.grade_number = { [Op.between]: [s, e] }; + } + } else if (grade_start !== undefined) { + where.grade_number = { [Op.gte]: parseInt(grade_start) }; + } else if (grade_end !== undefined) { + where.grade_number = { [Op.lte]: parseInt(grade_end) }; + } + // Handle v_type: find variants of same base_word if (v_type === true) { // Nếu có v_type, cần tìm tất cả các từ có cùng base_word diff --git a/data/familynfriend/g1/F11.json b/data/familynfriend/g1/F11.json index 72ddc1f..d56ed06 100644 --- a/data/familynfriend/g1/F11.json +++ b/data/familynfriend/g1/F11.json @@ -14,11 +14,6 @@ { "grade": "010102", "vocab": [ - "red", - "green", - "blue", - "black", - "yellow", "leaf", "apple", "sky", @@ -37,9 +32,7 @@ "car" ], "phonics": [ - "C", - "c", - "/k/" + "c", "/k/" ], "grammar": [] }, @@ -65,7 +58,6 @@ "duck" ], "phonics": [ - "D", "d", "/d/" ], @@ -119,13 +111,9 @@ ], "phonics": [ "A", - "a", "B", - "b", "C", - "c", - "D", - "d" + "D" ], "grammar": [ "What color is it?", diff --git a/data/familynfriend/g1/F15.json b/data/familynfriend/g1/F15.json index cb46a89..c063e8d 100644 --- a/data/familynfriend/g1/F15.json +++ b/data/familynfriend/g1/F15.json @@ -97,9 +97,7 @@ { "grade": "010508", "vocab": null, - "phonics": [ - "letters and sounds from unit" - ], + "phonics": null, "grammar": [ "This is...", "These are...", diff --git a/data/familynfriend/g1/F1S.json b/data/familynfriend/g1/F1S.json index a372b0c..0c5a7dd 100644 --- a/data/familynfriend/g1/F1S.json +++ b/data/familynfriend/g1/F1S.json @@ -60,18 +60,11 @@ "phonics": null, "grammar": [ "One apple", - "Two apples", - "Count and say." + "Two apples" ] }, { "grade": "010005", - "vocab": [ - "boy", - "bag", - "bat", - "Billy" - ], "phonics": [ "/b/" ], diff --git a/data/familynfriend/g5/F510.json b/data/familynfriend/g5/F510.json index 39544e1..75729ee 100644 --- a/data/familynfriend/g5/F510.json +++ b/data/familynfriend/g5/F510.json @@ -1,7 +1,7 @@ [ { "grade": "051001", - "vocab": ["headache", "fever", "toothache", "cold", "cough", "earache", "stomachache", "sore", "throat"], + "vocab": ["headache", "fever", "toothache", "cold", "cough", "earache", "stomachache", "sore throat"], "phonics": null, "grammar": ["What's the matter?", "I have a ...", "He has a ...", "She has a ..."], "target": "Identify words for illness, understand a short story about feeling unwell." diff --git a/models/Categories.js b/models/Categories.js index e254064..c32cab5 100644 --- a/models/Categories.js +++ b/models/Categories.js @@ -17,7 +17,7 @@ const Categories = sequelize.define('Categories', { created_at: { type: DataTypes.DATE, allowNull: false, defaultValue: DataTypes.NOW }, updated_at: { type: DataTypes.DATE, allowNull: false, defaultValue: DataTypes.NOW }, }, { - tableName: 'Categories', + tableName: 'categories', timestamps: true, underscored: true, indexes: [ diff --git a/models/Vocab.js b/models/Vocab.js index 7e1c6dc..0f35a17 100644 --- a/models/Vocab.js +++ b/models/Vocab.js @@ -1,5 +1,6 @@ const { DataTypes } = require('sequelize'); const { sequelize } = require('../config/database'); +const Grade = require('./Grade'); const Vocab = sequelize.define('Vocab', { vocab_id: { @@ -36,6 +37,11 @@ const Vocab = sequelize.define('Vocab', { defaultValue: '', comment: 'Vietnamese meaning' }, + Grade_number: { + type: DataTypes.INTEGER, + defaultValue: 0, + comment: 'Numeric representation of grade unit lesson as GG UU LL for easier querying and sorting' + }, category: { type: DataTypes.STRING(100), comment: 'Category of the word (e.g., Action Verbs, Nouns)'