Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/features/items-sync/lib/SyncedItems.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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 }
Expand Down
2 changes: 0 additions & 2 deletions src/features/settings/lib/ProductMappings.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
8 changes: 4 additions & 4 deletions src/lib/copilot/CopilotAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,10 @@ export class CopilotAPI {
async _getProducts(
productIds: string[] | 'all',
args: CopilotListArgs = { limit: MAX_FETCH_COPILOT_RESOURCES },
): Promise<Record<string, CopilotProduct> | null> {
): Promise<Record<string, CopilotProduct>> {
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<Record<string, CopilotProduct>>((acc, product) => {
Expand All @@ -166,10 +166,10 @@ export class CopilotAPI {
async _getPrices(
priceIds: string[] | 'all',
args = { limit: '10_000' },
): Promise<Record<string, CopilotPrice> | null> {
): Promise<Record<string, CopilotPrice>> {
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<Record<string, CopilotPrice>>((acc, price) => {
Expand Down