Spaces:
Configuration error
Configuration error
Download scripts/seed_subcategories.js from sdsdsd55415/pcstore: direct link, hf CLI and curl.
- Browser
- Download file 2.72 kB
-
https://huggingface.co/spaces/sdsdsd55415/pcstore/resolve/main/scripts/seed_subcategories.js
- Command line
-
hf download hf://spaces/sdsdsd55415/pcstore/scripts/seed_subcategories.js
-
curl -L -o seed_subcategories.js https://huggingface.co/spaces/sdsdsd55415/pcstore/resolve/main/scripts/seed_subcategories.js
2.72 kB
| const mongoose = require('mongoose'); | |
| require('dotenv').config(); | |
| const Category = require('../src/models/Category'); | |
| // Root Categories | |
| const rootCategories = [ | |
| { id: "periferik_bu", name: "โจ๏ธ๐ฑ๏ธ Periferik qurilmalar B/U", description: "Ishlatilgan periferik qurilmalar" }, | |
| { id: "periferik_new", name: "๐๐ฑ๏ธ Periferik qurilmalar Yangi", description: "Yangi periferik qurilmalar" }, | |
| { id: "asosiy_bu", name: "โ๏ธ๐ง Kompyuterning asosiy qismlari B/U", description: "Ishlatilgan ehtiyot qismlar" }, | |
| { id: "asosiy_new", name: "๐โ๏ธ Kompyuterning asosiy qismlari Yangi", description: "Yangi ehtiyot qismlar" } | |
| ]; | |
| // Subcategories for "Asosiy" (Both B/U and New) | |
| const asosiyCats = [ | |
| "๐ง Protsessor (CPU)", | |
| "๐ Ona plata", | |
| "๐ฎ Videokarta (GPU)", | |
| "๐พ Operativ xotira (RAM)", | |
| "โก Quvvat bloki (PSU)", | |
| "๐ฝ Xotira qurilmalari (SSD / HDD)" | |
| ]; | |
| // Subcategories for "Periferik" (Both B/U and New) | |
| const periferikCats = [ | |
| "โจ๏ธ Klaviatura", | |
| "๐ฑ๏ธ Sichqoncha", | |
| "๐ง Quloqchin", | |
| "๐ค Mikrofon", | |
| "๐ฅ๏ธ Monitor", | |
| "๐น Veb-kamera" | |
| ]; | |
| async function seedCategories() { | |
| try { | |
| await mongoose.connect(process.env.MONGO_URI); | |
| console.log('MongoDB Connected'); | |
| // Clear all categories | |
| await Category.deleteMany({}); | |
| console.log('Cleared existing categories.'); | |
| // Insert Roots | |
| for (const root of rootCategories) { | |
| await new Category({ | |
| id: root.id, | |
| name: root.name, | |
| description: root.description, | |
| parent: null | |
| }).save(); | |
| console.log(`Created Root: ${root.name}`); | |
| let subList = []; | |
| if (root.id.startsWith('asosiy_')) { | |
| subList = asosiyCats; | |
| } else if (root.id.startsWith('periferik_')) { | |
| subList = periferikCats; | |
| } | |
| // Add subcategories | |
| for (const subName of subList) { | |
| const subId = `${root.id}_${subName.toLowerCase().replace(/[^a-z0-9]/g, '_')}`; // e.g. periferik_new_monitor | |
| await new Category({ | |
| id: subId, | |
| name: subName, | |
| description: `${root.name} - ${subName}`, | |
| parent: root.id | |
| }).save(); | |
| console.log(` > Added Sub: ${subName}`); | |
| } | |
| } | |
| console.log('Re-seeding complete!'); | |
| process.exit(); | |
| } catch (err) { | |
| console.error(err); | |
| process.exit(1); | |
| } | |
| } | |
| seedCategories(); | |