Browse Source

fix: correct ShopRenter API pagination to start from page 0 #86

Fixed pagination bug in _shared/shoprenter-client.ts where page
parameter defaulted to 1, but ShopRenter API uses 0-based pagination
(starts at page 0).

Changes:
- fetchProducts: changed default page from 1 to 0
- fetchCustomers: changed default page from 1 to 0
- fetchOrders: changed default page from 1 to 0
- shoprenter-sync/index.ts: updated comment to clarify 0-based pagination

This ensures the first page of results is properly retrieved from the
ShopRenter API.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Claude 5 months ago
parent
commit
36abf85be5

+ 3 - 3
supabase/functions/_shared/shoprenter-client.ts

@@ -598,7 +598,7 @@ export async function shopRenterApiRequest(
 }
 }
 
 
 // Fetch products from ShopRenter
 // Fetch products from ShopRenter
-export async function fetchProducts(storeId: string, page: number = 1, limit: number = 25): Promise<any> {
+export async function fetchProducts(storeId: string, page: number = 0, limit: number = 25): Promise<any> {
   return shopRenterApiRequest(
   return shopRenterApiRequest(
     storeId,
     storeId,
     `/productExtend?page=${page}&limit=${limit}&full=1`,
     `/productExtend?page=${page}&limit=${limit}&full=1`,
@@ -625,7 +625,7 @@ export interface ShopRenterCustomerFilters {
 // Fetch customers from ShopRenter
 // Fetch customers from ShopRenter
 export async function fetchCustomers(
 export async function fetchCustomers(
   storeId: string,
   storeId: string,
-  page: number = 1,
+  page: number = 0,
   limit: number = 25,
   limit: number = 25,
   filters?: ShopRenterCustomerFilters
   filters?: ShopRenterCustomerFilters
 ): Promise<any> {
 ): Promise<any> {
@@ -646,7 +646,7 @@ export async function fetchCustomers(
 // Fetch orders from ShopRenter
 // Fetch orders from ShopRenter
 export async function fetchOrders(
 export async function fetchOrders(
   storeId: string,
   storeId: string,
-  page: number = 1,
+  page: number = 0,
   limit: number = 25,
   limit: number = 25,
   filters?: ShopRenterOrderFilters
   filters?: ShopRenterOrderFilters
 ): Promise<any> {
 ): Promise<any> {

+ 1 - 1
supabase/functions/shoprenter-sync/index.ts

@@ -744,7 +744,7 @@ serve(wrapHandler('shoprenter-sync', async (req) => {
         console.log('[ShopRenter] Product sync disabled by store permissions')
         console.log('[ShopRenter] Product sync disabled by store permissions')
       } else {
       } else {
         console.log('[ShopRenter] Syncing products...')
         console.log('[ShopRenter] Syncing products...')
-        let page = 0  // ShopRenter API uses zero-based pagination
+        let page = 0  // ShopRenter API uses zero-based pagination (starts at 0)
         let hasMore = true
         let hasMore = true
         const limit = 50
         const limit = 50