diff --git a/src/features/items-sync/lib/SyncedItems.service.ts b/src/features/items-sync/lib/SyncedItems.service.ts index bb4f0a5..d16cbd5 100644 --- a/src/features/items-sync/lib/SyncedItems.service.ts +++ b/src/features/items-sync/lib/SyncedItems.service.ts @@ -152,7 +152,7 @@ class SyncedItemsService extends AuthenticatedXeroService { for (const price of prices) { const productMap = await this.copilot.getProductsMapById([price.productId]) - const product = productMap?.[price.productId] + const product = productMap[price.productId] if (!product) { throw new APIError('Could not find product for mapping', status.BAD_REQUEST) } @@ -300,9 +300,9 @@ class SyncedItemsService extends AuthenticatedXeroService { copilotPriceMapPromise, xeroItemMapPromise, ]) - const copilotProduct = copilotProductMap?.[productId] || null - const copilotPrice = copilotPriceMap?.[priceId] || null - const xeroItem = xeroItemMap?.[itemId] || null + const copilotProduct = copilotProductMap[productId] + const copilotPrice = copilotPriceMap[priceId] + const xeroItem = xeroItemMap[itemId] return { copilotProduct, copilotPrice, xeroItem } } catch (_) { return { copilotProduct: null, copilotPrice: null, xeroItem: null } diff --git a/src/features/settings/lib/ProductMappings.service.ts b/src/features/settings/lib/ProductMappings.service.ts index 46e43d8..d2b0953 100644 --- a/src/features/settings/lib/ProductMappings.service.ts +++ b/src/features/settings/lib/ProductMappings.service.ts @@ -41,8 +41,6 @@ class ProductMappingsService extends AuthenticatedXeroService { this.copilot.getPricesMapById('all'), ]) - if (!copilotPrices || !copilotProducts) return [] - const mappings = Object.values(copilotPrices) // Sort by decreasing createdAt date .sort((a, b) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime()) diff --git a/src/lib/copilot/CopilotAPI.ts b/src/lib/copilot/CopilotAPI.ts index 68a3a2e..2011d5c 100644 --- a/src/lib/copilot/CopilotAPI.ts +++ b/src/lib/copilot/CopilotAPI.ts @@ -145,10 +145,10 @@ export class CopilotAPI { async _getProducts( productIds: string[] | 'all', args: CopilotListArgs = { limit: MAX_FETCH_COPILOT_RESOURCES }, - ): Promise | null> { + ): Promise> { const allProductsResponse = await this.copilot.listProducts(args) - if (!allProductsResponse.data) return null + if (!allProductsResponse.data) return {} const allProducts = z.array(CopilotProductSchema).parse(allProductsResponse.data) return allProducts.reduce>((acc, product) => { @@ -166,10 +166,10 @@ export class CopilotAPI { async _getPrices( priceIds: string[] | 'all', args = { limit: '10_000' }, - ): Promise | null> { + ): Promise> { const allPricesResponse = await this.copilot.listPrices(args) - if (!allPricesResponse.data) return null + if (!allPricesResponse.data) return {} const allPrices = z.array(CopilotPriceSchema).parse(allPricesResponse.data) return allPrices.reduce>((acc, price) => {