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

This commit is contained in:
silverpro89
2026-02-26 15:00:58 +07:00
parent 68308743ff
commit 9af45a7875
8 changed files with 49 additions and 28 deletions

View File

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

View File

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

View File

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

View File

@@ -97,9 +97,7 @@
{
"grade": "010508",
"vocab": null,
"phonics": [
"letters and sounds from unit"
],
"phonics": null,
"grammar": [
"This is...",
"These are...",

View File

@@ -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/"
],

View File

@@ -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."

View File

@@ -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: [

View File

@@ -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)'