login and db work
All checks were successful
Deploy to Web Server flyer-crawler.projectium.com / deploy (push) Successful in 20s
All checks were successful
Deploy to Web Server flyer-crawler.projectium.com / deploy (push) Successful in 20s
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { createClient, SupabaseClient } from '@supabase/supabase-js';
|
||||
import type { Flyer, FlyerItem, MasterGroceryItem, Profile, ShoppingList, ShoppingListItem, Store } from '../types';
|
||||
import type { Flyer, FlyerItem, MasterGroceryItem, Profile, ShoppingList, ShoppingListItem, Store, SuggestedCorrection } from '../types';
|
||||
import { Database } from '../types/supabase';
|
||||
|
||||
// In a Vite project, environment variables are exposed on the `import.meta.env` object.
|
||||
@@ -692,6 +692,62 @@ export const invokeSeedDatabaseFunction = async (): Promise<{ message: string }>
|
||||
return data;
|
||||
};
|
||||
|
||||
/**
|
||||
* Fetches all pending suggested corrections from the database.
|
||||
* This is an admin-only function.
|
||||
* @returns An array of suggested correction objects with related user and item data.
|
||||
*/
|
||||
export const getSuggestedCorrections = async (): Promise<SuggestedCorrection[]> => {
|
||||
if (!supabase) throw new Error("Supabase client not initialized");
|
||||
|
||||
const { data, error } = await supabase
|
||||
.from('suggested_corrections')
|
||||
.select(`
|
||||
*,
|
||||
user:profiles(email),
|
||||
item:flyer_items(item, price_display)
|
||||
`)
|
||||
.eq('status', 'pending')
|
||||
.order('created_at', { ascending: true });
|
||||
|
||||
if (error) throw new Error(`Failed to fetch suggested corrections: ${error.message}`);
|
||||
|
||||
return (data || []).map((c: any) => ({
|
||||
...c,
|
||||
user_email: c.user?.email,
|
||||
flyer_item_name: c.item?.item,
|
||||
flyer_item_price_display: c.item?.price_display,
|
||||
}));
|
||||
};
|
||||
|
||||
/**
|
||||
* Approves a suggested correction by calling the `approve_correction` RPC.
|
||||
* This is an admin-only function.
|
||||
* @param correctionId The ID of the correction to approve.
|
||||
*/
|
||||
export const approveCorrection = async (correctionId: number): Promise<void> => {
|
||||
if (!supabase) throw new Error("Supabase client not initialized");
|
||||
|
||||
const { error } = await supabase.rpc('approve_correction', { p_correction_id: correctionId });
|
||||
|
||||
if (error) {
|
||||
throw new Error(`Failed to approve correction: ${error.message}`);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Rejects a suggested correction.
|
||||
* This is an admin-only function.
|
||||
* @param correctionId The ID of the correction to reject.
|
||||
*/
|
||||
export const rejectCorrection = async (correctionId: number): Promise<void> => {
|
||||
if (!supabase) throw new Error("Supabase client not initialized");
|
||||
|
||||
const { error } = await supabase.from('suggested_corrections').update({ status: 'rejected', reviewed_at: new Date().toISOString() }).eq('id', correctionId);
|
||||
|
||||
if (error) throw new Error(`Failed to reject correction: ${error.message}`);
|
||||
};
|
||||
|
||||
|
||||
// =============================================
|
||||
// SHOPPING LIST FUNCTIONS
|
||||
|
||||
Reference in New Issue
Block a user