feat: user management — detail view, block/unblock, plan change

routes/admin.js: GET /users/:id (profile+channels+balance+transactions)
  PATCH /users/:id (is_blocked, plan_code, name)
  plan change: cancels active sub → creates new → credits reset
generate.js: check is_blocked before generation → 403 ACCOUNT_BLOCKED
DB: users.is_blocked BOOLEAN DEFAULT false
This commit is contained in:
Ник (Claude)
2026-06-13 00:14:11 +03:00
parent f18b83c59b
commit 05fa7644cc
2 changed files with 65 additions and 0 deletions
+6
View File
@@ -19,6 +19,12 @@ router.post('/', async (req, res) => {
if (type !== 'topics' && !topic) return res.status(400).json({ error: 'topic is required' });
if (type === 'post' && !channelId) return res.status(400).json({ error: 'channelId is required for posts' });
// Проверяем не заблокирован ли пользователь
if (userId) {
const { rows: [u] } = await require('../config/db').query('SELECT is_blocked FROM users WHERE id=$1', [userId]);
if (u?.is_blocked) return res.status(403).json({ error: 'Аккаунт заблокирован', code: 'ACCOUNT_BLOCKED' });
}
// Проверка и списание кредитов
const billingOp = BILLING_OP[type];
let billingResult = null;