Refactor: Approve lovable tool use

This commit is contained in:
gpt-engineer-app[bot]
2025-10-10 13:15:12 +00:00
parent c0cc91a0dd
commit a30511fb50
5 changed files with 276 additions and 26 deletions

View File

@@ -220,35 +220,57 @@ export async function clearTestData(): Promise<{ deleted: number }> {
.eq('content->metadata->>is_test_data', 'true');
if (fetchError) throw fetchError;
if (!testSubmissions || testSubmissions.length === 0) {
return { deleted: 0 };
const submissionCount = testSubmissions?.length || 0;
// Delete submissions if found
if (submissionCount > 0) {
const batchSize = 100;
let totalDeleted = 0;
for (let i = 0; i < testSubmissions.length; i += batchSize) {
const batch = testSubmissions.slice(i, i + batchSize);
const ids = batch.map(s => s.id);
const { error: deleteError } = await supabase
.from('content_submissions')
.delete()
.in('id', ids);
if (deleteError) throw deleteError;
totalDeleted += ids.length;
}
}
// Delete in batches of 100
const batchSize = 100;
let totalDeleted = 0;
for (let i = 0; i < testSubmissions.length; i += batchSize) {
const batch = testSubmissions.slice(i, i + batchSize);
const ids = batch.map(s => s.id);
const { error: deleteError } = await supabase
.from('content_submissions')
.delete()
.in('id', ids);
if (deleteError) throw deleteError;
totalDeleted += ids.length;
// Clear the test data registry
const { error: registryError } = await supabase
.from('test_data_registry')
.delete()
.neq('id', '00000000-0000-0000-0000-000000000000'); // Delete all records
if (registryError) {
console.error('Error clearing test data registry:', registryError);
}
return { deleted: totalDeleted };
return { deleted: submissionCount };
} catch (error) {
console.error('Error clearing test data:', error);
throw error;
}
}
export async function getTestDataStats(): Promise<{ total: number; pending: number; approved: number }> {
export async function getTestDataStats(): Promise<{
total: number;
pending: number;
approved: number;
operators: number;
property_owners: number;
manufacturers: number;
designers: number;
parks: number;
rides: number;
ride_models: number;
}> {
// Use proper JSON path query for nested metadata
const { data, error } = await supabase
.from('content_submissions')
@@ -257,10 +279,27 @@ export async function getTestDataStats(): Promise<{ total: number; pending: numb
if (error) throw error;
// Get registry counts for available dependencies
const { data: registryData } = await supabase
.from('test_data_registry')
.select('entity_type');
const registryCounts = registryData?.reduce((acc, row) => {
acc[row.entity_type] = (acc[row.entity_type] || 0) + 1;
return acc;
}, {} as Record<string, number>) || {};
const stats = {
total: data?.length || 0,
pending: data?.filter(s => s.status === 'pending').length || 0,
approved: data?.filter(s => s.status === 'approved').length || 0
approved: data?.filter(s => s.status === 'approved').length || 0,
operators: registryCounts['operator'] || 0,
property_owners: registryCounts['property_owner'] || 0,
manufacturers: registryCounts['manufacturer'] || 0,
designers: registryCounts['designer'] || 0,
parks: registryCounts['park'] || 0,
rides: registryCounts['ride'] || 0,
ride_models: registryCounts['ride_model'] || 0
};
return stats;