export const getAssignmentById = async (supabase: SupabaseClient, assignmentId: string) => {
try {
console.log('🚀 CALLING RPC FUNCTION:', 'get_assignment_by_id');
console.log('🚀 WITH PARAMETER:', { p_id: assignmentId });
console.log('🚀 ASSIGNMENT ID TYPE:', typeof assignmentId);
console.log('🚀 ASSIGNMENT ID VALUE:', assignmentId);
const result = await supabase.rpc("get_assignment_by_id", { p_id: assignmentId });
console.log('🔍 RAW RPC RESULT:', JSON.stringify(result, null, 2));
console.log('🔍 RESULT.ERROR:', result.error);
console.log('🔍 RESULT.DATA:', result.data);
if (result.data && Array.isArray(result.data)) {
console.log('🔍 FIRST ELEMENT:', result.data[0]);
}
if (result.error) {
console.error('❌ RPC Error in getAssignmentById:', result.error);
console.error('❌ ERROR CODE:', result.error.code);
console.error('❌ ERROR MESSAGE:', result.error.message);
console.error('❌ ERROR DETAILS:', result.error.details);
throw new Error(`RPC function failed: ${result.error.message}`);
}
return result;
} catch (error) {
console.error('💥 CATCH BLOCK - Error calling get_assignment_by_id:', error);
console.error('💥 ERROR TYPE:', typeof error);
if (error instanceof Error) {
console.error('💥 ERROR MESSAGE:', error.message);
}
throw error;
}
};
export const getAssignmentById = async (supabase: SupabaseClient, assignmentId: string) => {
try {
console.log('🚀 CALLING RPC FUNCTION:', 'get_assignment_by_id');
console.log('🚀 WITH PARAMETER:', { p_id: assignmentId });
console.log('🚀 ASSIGNMENT ID TYPE:', typeof assignmentId);
console.log('🚀 ASSIGNMENT ID VALUE:', assignmentId);
const result = await supabase.rpc("get_assignment_by_id", { p_id: assignmentId });
console.log('🔍 RAW RPC RESULT:', JSON.stringify(result, null, 2));
console.log('🔍 RESULT.ERROR:', result.error);
console.log('🔍 RESULT.DATA:', result.data);
if (result.data && Array.isArray(result.data)) {
console.log('🔍 FIRST ELEMENT:', result.data[0]);
}
if (result.error) {
console.error('❌ RPC Error in getAssignmentById:', result.error);
console.error('❌ ERROR CODE:', result.error.code);
console.error('❌ ERROR MESSAGE:', result.error.message);
console.error('❌ ERROR DETAILS:', result.error.details);
throw new Error(`RPC function failed: ${result.error.message}`);
}
return result;
} catch (error) {
console.error('💥 CATCH BLOCK - Error calling get_assignment_by_id:', error);
console.error('💥 ERROR TYPE:', typeof error);
if (error instanceof Error) {
console.error('💥 ERROR MESSAGE:', error.message);
}
throw error;
}
};