fix: filter English API endpoints to only return approved translations
Previously, all English recipe API endpoints were returning any recipe with a translations.en object, regardless of approval status. This caused 218 recipes to appear instead of only approved ones. Updated all 9 English API endpoints to filter for translationStatus='approved': - /api/recipes/items/all_brief - /api/recipes/items/in_season/[month] - /api/recipes/items/category and /api/recipes/items/category/[category] - /api/recipes/items/tag and /api/recipes/items/tag/[tag] - /api/recipes/items/icon/[icon] - /api/recipes/search - /api/recipes/favorites/recipes
This commit is contained in:
@@ -23,10 +23,10 @@ export const GET: RequestHandler = async ({ locals }) => {
|
||||
return json([]);
|
||||
}
|
||||
|
||||
// Get recipes that are favorited AND have English translations
|
||||
// Get recipes that are favorited AND have approved English translations
|
||||
let recipes = await Recipe.find({
|
||||
_id: { $in: userFavorites.favorites },
|
||||
'translations.en': { $exists: true }
|
||||
'translations.en.translationStatus': 'approved'
|
||||
}).lean();
|
||||
|
||||
// Transform to English format
|
||||
|
||||
@@ -7,9 +7,9 @@ import { rand_array } from '$lib/js/randomize';
|
||||
export const GET: RequestHandler = async ({params}) => {
|
||||
await dbConnect();
|
||||
|
||||
// Find all recipes that have English translations
|
||||
// Find all recipes that have approved English translations
|
||||
const recipes = await Recipe.find(
|
||||
{ 'translations.en': { $exists: true } },
|
||||
{ 'translations.en.translationStatus': 'approved' },
|
||||
'_id translations.en short_name season dateModified icon'
|
||||
).lean();
|
||||
|
||||
|
||||
@@ -5,9 +5,9 @@ import { dbConnect } from '../../../../../utils/db';
|
||||
export const GET: RequestHandler = async ({params}) => {
|
||||
await dbConnect();
|
||||
|
||||
// Get distinct categories from English translations
|
||||
// Get distinct categories from approved English translations
|
||||
const categories = await Recipe.distinct('translations.en.category', {
|
||||
'translations.en': { $exists: true }
|
||||
'translations.en.translationStatus': 'approved'
|
||||
}).lean();
|
||||
|
||||
return json(JSON.parse(JSON.stringify(categories)));
|
||||
|
||||
@@ -7,11 +7,11 @@ import { rand_array } from '$lib/js/randomize';
|
||||
export const GET: RequestHandler = async ({params}) => {
|
||||
await dbConnect();
|
||||
|
||||
// Find recipes in this category that have English translations
|
||||
// Find recipes in this category that have approved English translations
|
||||
const recipes = await Recipe.find(
|
||||
{
|
||||
'translations.en.category': params.category,
|
||||
'translations.en': { $exists: true }
|
||||
'translations.en.translationStatus': 'approved'
|
||||
},
|
||||
'_id translations.en short_name images season dateModified icon'
|
||||
).lean();
|
||||
|
||||
@@ -7,11 +7,11 @@ import { rand_array } from '$lib/js/randomize';
|
||||
export const GET: RequestHandler = async ({params}) => {
|
||||
await dbConnect();
|
||||
|
||||
// Find recipes with this icon that have English translations
|
||||
// Find recipes with this icon that have approved English translations
|
||||
const recipes = await Recipe.find(
|
||||
{
|
||||
icon: params.icon,
|
||||
'translations.en': { $exists: true }
|
||||
'translations.en.translationStatus': 'approved'
|
||||
},
|
||||
'_id translations.en short_name images season dateModified icon'
|
||||
).lean();
|
||||
|
||||
@@ -6,12 +6,12 @@ import { rand_array } from '$lib/js/randomize';
|
||||
export const GET: RequestHandler = async ({params}) => {
|
||||
await dbConnect();
|
||||
|
||||
// Find recipes in season that have English translations
|
||||
// Find recipes in season that have approved English translations
|
||||
const recipes = await Recipe.find(
|
||||
{
|
||||
season: params.month,
|
||||
icon: {$ne: "🍽️"},
|
||||
'translations.en': { $exists: true }
|
||||
'translations.en.translationStatus': 'approved'
|
||||
},
|
||||
'_id translations.en short_name images season dateModified icon'
|
||||
).lean();
|
||||
|
||||
@@ -5,9 +5,9 @@ import { dbConnect } from '../../../../../utils/db';
|
||||
export const GET: RequestHandler = async ({params}) => {
|
||||
await dbConnect();
|
||||
|
||||
// Get all recipes with English translations
|
||||
// Get all recipes with approved English translations
|
||||
const recipes = await Recipe.find({
|
||||
'translations.en': { $exists: true }
|
||||
'translations.en.translationStatus': 'approved'
|
||||
}, 'translations.en.tags').lean();
|
||||
|
||||
// Extract and flatten all unique tags
|
||||
|
||||
@@ -7,11 +7,11 @@ import { rand_array } from '$lib/js/randomize';
|
||||
export const GET: RequestHandler = async ({params}) => {
|
||||
await dbConnect();
|
||||
|
||||
// Find recipes with this tag that have English translations
|
||||
// Find recipes with this tag that have approved English translations
|
||||
const recipes = await Recipe.find(
|
||||
{
|
||||
'translations.en.tags': params.tag,
|
||||
'translations.en': { $exists: true }
|
||||
'translations.en.translationStatus': 'approved'
|
||||
},
|
||||
'_id translations.en short_name images season dateModified icon'
|
||||
).lean();
|
||||
|
||||
@@ -14,9 +14,9 @@ export const GET: RequestHandler = async ({ url, locals }) => {
|
||||
const favoritesOnly = url.searchParams.get('favorites') === 'true';
|
||||
|
||||
try {
|
||||
// Build base query - only recipes with English translations
|
||||
// Build base query - only recipes with approved English translations
|
||||
let dbQuery: any = {
|
||||
'translations.en': { $exists: true }
|
||||
'translations.en.translationStatus': 'approved'
|
||||
};
|
||||
|
||||
// Apply filters based on context
|
||||
|
||||
Reference in New Issue
Block a user