feat(categories): CRUD endpoints + is_active for archiving

Endpoints under /api/admin/categories:
  GET    — list all with metrics (article_count, topic_count, autogen status)
  POST   — create + auto-create autogen_settings row (defaults: enabled, 1/day, 12:00 MSK)
  PATCH  — update name/desc/icon/color/sort_order/is_active (slug is immutable FK)
  DELETE — soft (is_active=false) by default; ?force=true tries hard delete
           but refuses if any articles/topics still reference the slug

Migration: ALTER TABLE categories ADD COLUMN IF NOT EXISTS is_active BOOLEAN DEFAULT true
Public GET /api/categories now filters WHERE COALESCE(is_active,true)=true.
This commit is contained in:
Aleksei Pavlov
2026-06-19 11:55:04 +03:00
parent 2f7af84ddc
commit 59e604a67b
4 changed files with 176 additions and 1 deletions
+4
View File
@@ -221,6 +221,10 @@ const migrate = async () => {
CREATE INDEX IF NOT EXISTS idx_zero_notes_published ON zero_notes(published_at DESC) WHERE status='published';
`);
// safe column alters (existing tables on prod may lack newer columns)
await query(`ALTER TABLE categories ADD COLUMN IF NOT EXISTS is_active BOOLEAN DEFAULT true`);
console.log('[DB] Migrations applied');
};