feat(api/games): add GET /types endpoint
All checks were successful
Deploy to Production / deploy (push) Successful in 21s

This commit is contained in:
vuongps38770
2026-01-28 09:50:11 +07:00
parent 9055b2b611
commit c8af2e268d
2 changed files with 38 additions and 0 deletions

View File

@@ -1,5 +1,6 @@
const { Game } = require('../models');
const { cacheUtils } = require('../config/redis');
const { sequelize } = require('../config/database');
/**
* Game Controller - Quản lý trò chơi giáo dục
@@ -393,6 +394,40 @@ class GameController {
}
}
/**
* Get all unique game types
*/
async getGameTypes(req, res, next) {
try {
const cacheKey = 'games:types';
const cached = await cacheUtils.get(cacheKey);
if (cached) {
return res.json({
success: true,
data: cached,
cached: true,
});
}
// Get distinct types
const types = await Game.aggregate('type', 'DISTINCT', { plain: false });
// Format response as array of objects
const result = types.map(t => ({ type: t.type }));
await cacheUtils.set(cacheKey, result, 3600);
res.json({
success: true,
data: result,
cached: false,
});
} catch (error) {
next(error);
}
}
/**
* Get game statistics
*/