diff --git a/dump.rdb b/dump.rdb index 1b767f7..be9ceff 100644 Binary files a/dump.rdb and b/dump.rdb differ diff --git a/src/api/routes/admin/sheets/helpers/mapSheetProduct.ts b/src/api/routes/admin/sheets/helpers/mapSheetProduct.ts index 02b454c..2751209 100644 --- a/src/api/routes/admin/sheets/helpers/mapSheetProduct.ts +++ b/src/api/routes/admin/sheets/helpers/mapSheetProduct.ts @@ -18,7 +18,7 @@ export type UpdateProductResponse = UpdateProductInput & { id: string, rowNumber export const mapSheetProduct = (product: CreateProduct): CreateProductResponse | UpdateProductResponse => { - const options = product.options?.length ? [{ id: product.options[0].id, value: 'one size' }] : undefined + const options = product.options?.length ? [{ option_id: product.options[0].id, value: 'one size' }] : undefined return ({ id: product.id, rowNumber: product.rowNumber, diff --git a/src/api/routes/admin/sheets/index.ts b/src/api/routes/admin/sheets/index.ts index 22c23ff..50f4d03 100644 --- a/src/api/routes/admin/sheets/index.ts +++ b/src/api/routes/admin/sheets/index.ts @@ -26,7 +26,7 @@ export const SheetsRouter = (router: Router) => { const promises = sheetData.map(async (entry) => { const location = await categoryService.getCategoryByName(entry.Location.split('/').pop().trim()); const category = await categoryService.getCategoryByName(entry.Category); - let options; + let options: ProductOption[]; try { const product = await productService.retrieve(entry["Product ID"], { relations: ['options'] }) options = product.options; diff --git a/src/services/google-sheet-api.ts b/src/services/google-sheet-api.ts index 371ef12..7f4cb48 100644 --- a/src/services/google-sheet-api.ts +++ b/src/services/google-sheet-api.ts @@ -54,13 +54,15 @@ class GoogleSheetAPIService extends TransactionBaseService { const csvDataArray = []; // Filter and process the data to create the array of objects - const filteredData = response.data.values?.filter(row => row.slice(1).every((cell) => cell !== '' && cell !== null)); - - filteredData.slice(1).forEach((row, index) => { + response.data.values?.slice(1).forEach((row, index) => { const itemData = { rowNumber: index + 2 // 1 for index, 2nd for header. so adding 2. }; + if (!row[1] || !row[2]) { + return; + } + row.forEach((cell, columnIndex) => { const header = headers[columnIndex]; diff --git a/src/services/product.ts b/src/services/product.ts index 15a9e5c..5e276d0 100644 --- a/src/services/product.ts +++ b/src/services/product.ts @@ -66,6 +66,7 @@ class ProductService extends BaseProductService { async addBulkProducts(products: ((CreateProductInput | UpdateProductInput) & { id: string; rowNumber: number; })[]) { await this.loginAdmin(); + const promises = products.map((product, i) => { return new Promise>(async (resolve, reject) => { if (product.id) { @@ -79,18 +80,16 @@ class ProductService extends BaseProductService { try { if (productExists) { const { id, rowNumber, ...updateProduct } = product as UpdateProductInput & { id: string; rowNumber: number; }; + const { product: updatedProduct } = await this.updateProductWithFetch(id, updateProduct) resolve({ ...updatedProduct, rowNumber }); } else { - const { id, rowNumber, ...createProduct } = product as CreateProductInput & { id: string; rowNumber: number; } - const { product: createdProduct } = await this.createProductWithFetch(createProduct); - resolve({ ...createdProduct, rowNumber }) } } catch (error) { - console.log('An error occurred!', error.response.data); + console.log('An error occurred!\n', error.response.data); } } else { const { id, rowNumber, ...createProduct } = product as CreateProductInput & { id: string, rowNumber: number; }