Skip to content

Commit a443980

Browse files
authored
Merge pull request #189 from tebanieo/master
Modernizr: Updated Readme
2 parents 5cb3c24 + fbb4b21 commit a443980

File tree

13 files changed

+1459
-616
lines changed

13 files changed

+1459
-616
lines changed

workshops/modernizr/README.md

Lines changed: 339 additions & 267 deletions
Large diffs are not rendered by default.

workshops/modernizr/backend/README.md

Lines changed: 183 additions & 192 deletions
Large diffs are not rendered by default.

workshops/modernizr/backend/src/database/seed.ts

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -183,20 +183,36 @@ async function seedProducts(): Promise<void> {
183183
return;
184184
}
185185

186-
// Get category IDs
187-
const [laptopRows] = await pool.execute('SELECT id FROM categories WHERE name = ?', ['Laptops']);
188-
const [booksRows] = await pool.execute('SELECT id FROM categories WHERE name = ?', ['Fiction']);
189-
const [kitchenRows] = await pool.execute('SELECT id FROM categories WHERE name = ?', ['Kitchen Appliances']);
190-
const [clothingRows] = await pool.execute('SELECT id FROM categories WHERE name = ?', ['Men\'s Clothing']);
191-
const [sportsRows] = await pool.execute('SELECT id FROM categories WHERE name = ?', ['Fitness Equipment']);
192-
const [gardenRows] = await pool.execute('SELECT id FROM categories WHERE name = ?', ['Tools']);
193-
194-
const laptopCategoryId = (laptopRows as any[])[0]?.id;
195-
const booksCategoryId = (booksRows as any[])[0]?.id;
196-
const kitchenCategoryId = (kitchenRows as any[])[0]?.id;
197-
const clothingCategoryId = (clothingRows as any[])[0]?.id;
198-
const sportsCategoryId = (sportsRows as any[])[0]?.id;
199-
const gardenCategoryId = (gardenRows as any[])[0]?.id;
186+
// Get category IDs with better error handling
187+
const getCategoryId = async (categoryName: string): Promise<number | null> => {
188+
try {
189+
const [rows] = await pool.execute('SELECT id FROM categories WHERE name = ?', [categoryName]);
190+
const id = (rows as any[])[0]?.id;
191+
if (!id) {
192+
console.warn(`Warning: Category '${categoryName}' not found`);
193+
}
194+
return id || null;
195+
} catch (error) {
196+
console.error(`Error finding category '${categoryName}':`, error);
197+
return null;
198+
}
199+
};
200+
201+
const laptopCategoryId = await getCategoryId('Laptops');
202+
const booksCategoryId = await getCategoryId('Fiction');
203+
const kitchenCategoryId = await getCategoryId('Kitchen Appliances');
204+
const clothingCategoryId = await getCategoryId('Men\'s Clothing');
205+
const sportsCategoryId = await getCategoryId('Fitness Equipment');
206+
const gardenCategoryId = await getCategoryId('Tools');
207+
208+
console.log('Category IDs found:', {
209+
laptopCategoryId,
210+
booksCategoryId,
211+
kitchenCategoryId,
212+
clothingCategoryId,
213+
sportsCategoryId,
214+
gardenCategoryId
215+
});
200216

201217
const products = [
202218
{
@@ -265,9 +281,12 @@ async function seedProducts(): Promise<void> {
265281
product.inventory_quantity
266282
]
267283
);
284+
console.log(`✓ Inserted product: ${product.name} (category_id: ${product.category_id})`);
268285
} catch (error) {
269-
console.warn(`Warning: Could not insert product ${product.name}:`, error);
286+
console.warn(` Could not insert product ${product.name}:`, error);
270287
}
288+
} else {
289+
console.warn(`✗ Skipping product ${product.name} - no category_id`);
271290
}
272291
}
273292

workshops/modernizr/backend/src/models/Product.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,10 @@ export function toProductResponse(product: ProductWithDetails): any {
8383
description: product.description,
8484
price: Number(product.price),
8585
inventory_quantity: product.inventory_quantity,
86-
category: product.category_name ? {
86+
category: {
8787
id: product.category_id,
88-
name: product.category_name
89-
} : undefined,
88+
name: product.category_name || 'Uncategorized'
89+
},
9090
seller_username: product.seller_username,
9191
seller_email: product.seller_email,
9292
created_at: product.created_at,
-75.1 KB
Binary file not shown.
74.6 KB
Binary file not shown.

0 commit comments

Comments
 (0)