Add languages, user_names, users_public tables and routes; fix _se→_sv rename

- Fix broken rename migration array (sed had corrupted from values to _sv)
- Add languages table with status lifecycle and trilingual titles
- Add user_names table with unique lowercase index
- Add users_public table linking to user_names and languages (native/target)
- Wire all three new routes under /api/languages, /api/user-names, /api/users-public

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-21 13:47:52 +02:00
parent 217aab7dcd
commit 10570786e9
9 changed files with 332 additions and 29 deletions

View File

@@ -31,11 +31,11 @@ router.get('/:id', async (req, res, next) => {
// POST /api/questions
router.post('/', async (req, res, next) => {
try {
const { sentence_de, sentence_en, sentence_se, blocked_topic } = req.body;
const { sentence_de, sentence_en, sentence_sv, blocked_topic } = req.body;
const result = await query(
`INSERT INTO questions (sentence_de, sentence_en, sentence_se, blocked_topic)
`INSERT INTO questions (sentence_de, sentence_en, sentence_sv, blocked_topic)
VALUES ($1, $2, $3, $4) RETURNING *`,
[sentence_de || null, sentence_en || null, sentence_se || null, blocked_topic || null]
[sentence_de || null, sentence_en || null, sentence_sv || null, blocked_topic || null]
);
res.status(201).json(result.rows[0]);
} catch (err) { next(err); }
@@ -44,7 +44,7 @@ router.post('/', async (req, res, next) => {
// PATCH /api/questions/:id
router.patch('/:id', async (req, res, next) => {
try {
const allowed = ['status', 'sentence_de', 'sentence_en', 'sentence_se',
const allowed = ['status', 'sentence_de', 'sentence_en', 'sentence_sv',
'blocked_topic', 'published_at', 'blocked_at'];
const fields = Object.keys(req.body).filter(k => allowed.includes(k));
if (!fields.length) return res.status(400).json({ error: 'No valid fields provided' });