|
@@ -4,9 +4,10 @@
|
|
|
* Provides a simple query interface for ShopRenter orders and customers.
|
|
* Provides a simple query interface for ShopRenter orders and customers.
|
|
|
* Supports filtering by email or order_id with automatic token refresh.
|
|
* Supports filtering by email or order_id with automatic token refresh.
|
|
|
*
|
|
*
|
|
|
|
|
+ * Method: POST
|
|
|
* Authentication: Bearer token using internal_api_keys table
|
|
* Authentication: Bearer token using internal_api_keys table
|
|
|
*
|
|
*
|
|
|
- * Query Parameters:
|
|
|
|
|
|
|
+ * JSON Body Parameters:
|
|
|
* - stores_uuid: UUID of the store (required)
|
|
* - stores_uuid: UUID of the store (required)
|
|
|
* - query_type: "order" or "customer" (required)
|
|
* - query_type: "order" or "customer" (required)
|
|
|
* - filter_by: "email" or "order_id" (required for orders)
|
|
* - filter_by: "email" or "order_id" (required for orders)
|
|
@@ -29,7 +30,7 @@ import {
|
|
|
const corsHeaders = {
|
|
const corsHeaders = {
|
|
|
'Access-Control-Allow-Origin': '*',
|
|
'Access-Control-Allow-Origin': '*',
|
|
|
'Access-Control-Allow-Headers': 'authorization, x-client-info, apikey, content-type',
|
|
'Access-Control-Allow-Headers': 'authorization, x-client-info, apikey, content-type',
|
|
|
- 'Access-Control-Allow-Methods': 'GET, POST, OPTIONS'
|
|
|
|
|
|
|
+ 'Access-Control-Allow-Methods': 'POST, OPTIONS'
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
// Initialize Supabase client
|
|
// Initialize Supabase client
|
|
@@ -43,10 +44,10 @@ serve(async (req: Request) => {
|
|
|
return new Response(null, { headers: corsHeaders });
|
|
return new Response(null, { headers: corsHeaders });
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // Only allow GET requests
|
|
|
|
|
- if (req.method !== 'GET') {
|
|
|
|
|
|
|
+ // Only allow POST requests
|
|
|
|
|
+ if (req.method !== 'POST') {
|
|
|
return new Response(
|
|
return new Response(
|
|
|
- JSON.stringify({ error: 'Method not allowed. Use GET.' }),
|
|
|
|
|
|
|
+ JSON.stringify({ error: 'Method not allowed. Use POST.' }),
|
|
|
{
|
|
{
|
|
|
status: 405,
|
|
status: 405,
|
|
|
headers: { ...corsHeaders, 'Content-Type': 'application/json' }
|
|
headers: { ...corsHeaders, 'Content-Type': 'application/json' }
|
|
@@ -62,12 +63,30 @@ serve(async (req: Request) => {
|
|
|
return createInternalApiKeyErrorResponse(authResult);
|
|
return createInternalApiKeyErrorResponse(authResult);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // Parse query parameters
|
|
|
|
|
- const url = new URL(req.url);
|
|
|
|
|
- const stores_uuid = url.searchParams.get('stores_uuid');
|
|
|
|
|
- const query_type = url.searchParams.get('query_type');
|
|
|
|
|
- const filter_by = url.searchParams.get('filter_by');
|
|
|
|
|
- const filter_value = url.searchParams.get('filter_value');
|
|
|
|
|
|
|
+ // Parse JSON body
|
|
|
|
|
+ const rawBody = await req.text();
|
|
|
|
|
+ console.log('[Query ShopRenter] Raw POST body:', rawBody);
|
|
|
|
|
+
|
|
|
|
|
+ let body: any;
|
|
|
|
|
+ try {
|
|
|
|
|
+ body = JSON.parse(rawBody);
|
|
|
|
|
+ console.log('[Query ShopRenter] Parsed JSON body:', body);
|
|
|
|
|
+ } catch (parseError: any) {
|
|
|
|
|
+ console.error('[Query ShopRenter] Failed to parse JSON body:', parseError.message);
|
|
|
|
|
+ return new Response(
|
|
|
|
|
+ JSON.stringify({ error: 'Invalid JSON in request body' }),
|
|
|
|
|
+ {
|
|
|
|
|
+ status: 400,
|
|
|
|
|
+ headers: { ...corsHeaders, 'Content-Type': 'application/json' }
|
|
|
|
|
+ }
|
|
|
|
|
+ );
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // Extract parameters from body
|
|
|
|
|
+ const stores_uuid = body.stores_uuid;
|
|
|
|
|
+ const query_type = body.query_type;
|
|
|
|
|
+ const filter_by = body.filter_by;
|
|
|
|
|
+ const filter_value = body.filter_value;
|
|
|
|
|
|
|
|
// Validate required parameters
|
|
// Validate required parameters
|
|
|
if (!stores_uuid) {
|
|
if (!stores_uuid) {
|