49 lines
1.3 KiB
TypeScript
49 lines
1.3 KiB
TypeScript
import { pool } from './src/db/migrate';
|
|
import { dutchieTemplate } from './src/scrapers/templates/dutchie';
|
|
|
|
async function fixCategoryUrls() {
|
|
console.log('🔧 Fixing category URLs for Dutchie stores\n');
|
|
|
|
try {
|
|
// Get all categories with /shop/ in the URL
|
|
const result = await pool.query(`
|
|
SELECT id, store_id, name, slug, dutchie_url
|
|
FROM categories
|
|
WHERE dutchie_url LIKE '%/shop/%'
|
|
ORDER BY store_id, id
|
|
`);
|
|
|
|
console.log(`Found ${result.rows.length} categories to fix:\n`);
|
|
|
|
for (const category of result.rows) {
|
|
console.log(`Category: ${category.name}`);
|
|
console.log(` Old URL: ${category.dutchie_url}`);
|
|
|
|
// Extract base URL (everything before /shop/)
|
|
const baseUrl = category.dutchie_url.split('/shop/')[0];
|
|
|
|
// Use template to build correct URL
|
|
const newUrl = dutchieTemplate.buildCategoryUrl(baseUrl, category.name);
|
|
|
|
console.log(` New URL: ${newUrl}`);
|
|
|
|
// Update the category
|
|
await pool.query(`
|
|
UPDATE categories
|
|
SET dutchie_url = $1
|
|
WHERE id = $2
|
|
`, [newUrl, category.id]);
|
|
|
|
console.log(` ✅ Updated\n`);
|
|
}
|
|
|
|
console.log(`\n✅ All category URLs fixed!`);
|
|
} catch (error) {
|
|
console.error('❌ Error:', error);
|
|
} finally {
|
|
await pool.end();
|
|
}
|
|
}
|
|
|
|
fixCategoryUrls();
|