diff --git a/controllers/gameController.js b/controllers/gameController.js index e261cd7..cca3bef 100644 --- a/controllers/gameController.js +++ b/controllers/gameController.js @@ -1,6 +1,7 @@ const { Game } = require('../models'); const { cacheUtils } = require('../config/redis'); const { sequelize } = require('../config/database'); +const { Op, Sequelize } = require('sequelize'); /** * Game Controller - Quản lý trò chơi giáo dục @@ -410,11 +411,22 @@ class GameController { }); } - // Get distinct types - const types = await Game.aggregate('type', 'DISTINCT', { plain: false }); + // Get all games with only type field + const games = await Game.findAll({ + attributes: [[Sequelize.fn('DISTINCT', Sequelize.col('type')), 'type']], + where: { + type: { + [Op.and]: [ + { [Op.ne]: null }, + { [Op.notIn]: ['', ' '] } + ] + } + }, + raw: true, + }); - // Format response as array of objects - const result = types.map(t => ({ type: t.type })); + // Get distinct types + const result = games.filter(g => g.type); await cacheUtils.set(cacheKey, result, 3600);