fix: ban duration >= not >, auto-prefill min duration
This commit is contained in:
@@ -19,6 +19,13 @@ router.get('/active', authenticate, async (req, res) => {
|
||||
res.json(await query("SELECT * FROM bans WHERE status = 'active' ORDER BY created_at DESC"));
|
||||
});
|
||||
|
||||
router.get('/min-duration', authenticate, async (req, res) => {
|
||||
const { player_name, player_uid, type } = req.query;
|
||||
const prev = await getRow('SELECT * FROM bans WHERE (player_name = ? OR player_uid = ?) AND type = ? AND status = ? ORDER BY created_at DESC LIMIT 1',
|
||||
[player_name||'', player_uid||'', type||'ban', 'active']);
|
||||
res.json({ minDays: prev ? parseDuration(prev.duration) : 0 });
|
||||
});
|
||||
|
||||
router.post('/', authenticate, requireRole('owner'), async (req, res) => {
|
||||
const { player_name, player_uid, reason, type, duration, ticket_id, expires_at } = req.body;
|
||||
if (!player_name) return res.status(400).json({ error: '玩家名为必填' });
|
||||
@@ -26,8 +33,8 @@ router.post('/', authenticate, requireRole('owner'), async (req, res) => {
|
||||
const durDays = parseDuration(duration);
|
||||
const prev = await getRow('SELECT * FROM bans WHERE (player_name = ? OR player_uid = ?) AND type = ? AND status = ? ORDER BY created_at DESC LIMIT 1',
|
||||
[player_name, player_uid||'', type||'ban', 'active']);
|
||||
if (prev && durDays > 0 && parseDuration(prev.duration) >= durDays) {
|
||||
return res.status(400).json({ error: `该玩家已有${parseDuration(prev.duration)}天处罚记录,新处罚时长不可低于上次(需 > ${parseDuration(prev.duration)}天)` });
|
||||
if (prev && durDays > 0 && parseDuration(prev.duration) > durDays) {
|
||||
return res.status(400).json({ error: `该玩家已有${parseDuration(prev.duration)}天处罚记录,新处罚时长不可少于上次(需 ≥ ${parseDuration(prev.duration)}天)` });
|
||||
}
|
||||
|
||||
const r = await query('INSERT INTO bans(player_name, player_uid, reason, type, duration, ticket_id, created_by, expires_at) VALUES (?,?,?,?,?,?,?,?)',
|
||||
|
||||
Reference in New Issue
Block a user