Skip to content
This repository was archived by the owner on Jan 20, 2025. It is now read-only.

Commit

Permalink
Merge pull request #10 from pedro-mealha/fix-missing-product
Browse files Browse the repository at this point in the history
fix missing product
  • Loading branch information
pedro-mealha authored May 2, 2024
2 parents 28d5001 + 2e55b87 commit e146e1b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
23 changes: 19 additions & 4 deletions assets/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,22 +92,37 @@ window.onload = () => {
continue;
}

products[index] = { id, name, oldPrice: row[PRODUCT_PRICE_INDEX] };
products[index] = { id, name, oldPrice: parseFloat(row[PRODUCT_PRICE_INDEX]) };
}

for (const row of newCsvData) {
const { id, index } = getProductBasicDetails(row);
const { id, name, index } = getProductBasicDetails(row);
const newPrice = parseFloat(row[PRODUCT_PRICE_INDEX]);

if (!id || row[PRODUCT_PRICING_OPTION_INDEX] === EXCHANGE_PRICE) {
continue;
}

if (products[index].oldPrice === row[PRODUCT_PRICE_INDEX]) {
if (!products[index]) {
products[index] = { id, name, oldPrice: null, newPrice };
continue;
}

if (products[index].oldPrice === newPrice) {
delete products[index];
continue;
}

products[index].newPrice = row[PRODUCT_PRICE_INDEX];
products[index].newPrice = newPrice;
}

for (const product of Object.values(products)) {
const index = `${product.name} ${product.id}`;

if (!product.newPrice || (!product.oldPrice && product.oldPrice !== null)) {
delete products[index];
continue;
}
}

return Object.values(products);
Expand Down
9 changes: 5 additions & 4 deletions assets/js/populate.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
export async function populateHtml(products) {
new DataTable('#products-table', {
autoWidth: false,
data: products,
columns: [
{ data: 'id', title: 'ID' },
{ data: 'name', title: 'Name' },
{ data: 'oldPrice', title: 'Old Price' },
{ data: 'newPrice', title: 'New Price' }
{ data: 'id', title: 'ID', width: '20%' },
{ data: 'name', title: 'Name', width: '60%' },
{ data: 'oldPrice', title: 'Old Price', type: 'num-fmt', width: '10%' },
{ data: 'newPrice', title: 'New Price', type: 'num-fmt', width: '10%' }
]
});

Expand Down

0 comments on commit e146e1b

Please sign in to comment.