feat: add untranslated recipes page for recipe admins
Add new page at /rezepte/untranslated for recipe admins to view and manage recipes without approved English translations. Includes translation status tracking, statistics dashboard, and visual badges. Changes: - Add API endpoint to fetch recipes without approved translations - Create untranslated recipes page with auth checks for rezepte_users group - Add translation status badges to Card component (pending, needs_update, none) - Add database index on translations.en.translationStatus for performance - Create layout for /rezepte route with header navigation - Add "Unübersetzt" link to navigation for authorized users
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
import { json, type RequestHandler, error } from '@sveltejs/kit';
|
||||
import { Recipe } from '../../../../../models/Recipe';
|
||||
import { dbConnect } from '../../../../../utils/db';
|
||||
|
||||
export const GET: RequestHandler = async ({ locals }) => {
|
||||
const session = await locals.auth();
|
||||
|
||||
if (!session?.user?.nickname) {
|
||||
throw error(401, 'Anmeldung erforderlich');
|
||||
}
|
||||
|
||||
if (!session.user.groups?.includes('rezepte_users')) {
|
||||
throw error(403, 'Zugriff verweigert');
|
||||
}
|
||||
|
||||
await dbConnect();
|
||||
|
||||
try {
|
||||
// Find recipes without approved English translation
|
||||
const untranslated = await Recipe.find({
|
||||
$or: [
|
||||
{ 'translations.en': { $exists: false } },
|
||||
{ 'translations.en.translationStatus': { $ne: 'approved' } }
|
||||
]
|
||||
}, 'name short_name category icon description tags season dateModified translations.en.translationStatus')
|
||||
.sort({ dateModified: 1 }) // Oldest first - highest priority
|
||||
.lean();
|
||||
|
||||
// Transform to include translationStatus at top level for easier UI handling
|
||||
const result = untranslated.map(recipe => ({
|
||||
_id: recipe._id,
|
||||
name: recipe.name,
|
||||
short_name: recipe.short_name,
|
||||
category: recipe.category,
|
||||
icon: recipe.icon,
|
||||
description: recipe.description,
|
||||
tags: recipe.tags || [],
|
||||
season: recipe.season || [],
|
||||
dateModified: recipe.dateModified,
|
||||
translationStatus: recipe.translations?.en?.translationStatus || undefined
|
||||
}));
|
||||
|
||||
return json(JSON.parse(JSON.stringify(result)));
|
||||
} catch (e) {
|
||||
console.error('Error fetching untranslated recipes:', e);
|
||||
throw error(500, 'Fehler beim Laden der unübersetzten Rezepte');
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user