|
@@ -93,12 +93,20 @@ serve(async (req) => {
|
|
|
)
|
|
)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // Transform phone_numbers array to phone_number string for backward compatibility
|
|
|
|
|
- const transformedStores = stores?.map(store => ({
|
|
|
|
|
- ...store,
|
|
|
|
|
- phone_number: store.phone_numbers?.[0]?.phone_number || null,
|
|
|
|
|
- phone_number_details: store.phone_numbers?.[0] || null
|
|
|
|
|
- })) || []
|
|
|
|
|
|
|
+ // Transform phone_numbers to phone_number string for backward compatibility
|
|
|
|
|
+ // Note: For many-to-one relationships, Supabase returns an object, not an array
|
|
|
|
|
+ const transformedStores = stores?.map(store => {
|
|
|
|
|
+ // Handle both object (many-to-one) and array (one-to-many) formats
|
|
|
|
|
+ const phoneData = Array.isArray(store.phone_numbers)
|
|
|
|
|
+ ? store.phone_numbers[0]
|
|
|
|
|
+ : store.phone_numbers;
|
|
|
|
|
+
|
|
|
|
|
+ return {
|
|
|
|
|
+ ...store,
|
|
|
|
|
+ phone_number: phoneData?.phone_number || null,
|
|
|
|
|
+ phone_number_details: phoneData || null
|
|
|
|
|
+ };
|
|
|
|
|
+ }) || []
|
|
|
|
|
|
|
|
return new Response(
|
|
return new Response(
|
|
|
JSON.stringify({
|
|
JSON.stringify({
|