refactor: standardize quotation marks across all files and improve code consistency
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
import { PrismaClient } from "@prisma/client"
|
||||
import { defaultCategories, defaultRootFolder } from "../lib/defaults"
|
||||
import { PrismaClient } from "@prisma/client";
|
||||
import { defaultCategories, defaultRootFolder } from "../lib/defaults";
|
||||
|
||||
const prisma = new PrismaClient()
|
||||
const prisma = new PrismaClient();
|
||||
|
||||
async function main() {
|
||||
console.log("🌱 Seeding database...")
|
||||
console.log("🌱 Seeding database...");
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════════════
|
||||
// Créer le dossier racine
|
||||
@@ -13,22 +13,22 @@ async function main() {
|
||||
where: { id: defaultRootFolder.id },
|
||||
update: {},
|
||||
create: defaultRootFolder,
|
||||
})
|
||||
console.log("📁 Root folder:", rootFolder.name)
|
||||
});
|
||||
console.log("📁 Root folder:", rootFolder.name);
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════════════
|
||||
// Créer les catégories (hiérarchiques)
|
||||
// ═══════════════════════════════════════════════════════════════════════════
|
||||
const slugToId = new Map<string, string>()
|
||||
const slugToId = new Map<string, string>();
|
||||
|
||||
// D'abord les parents
|
||||
const parents = defaultCategories.filter((c) => c.parentSlug === null)
|
||||
console.log(`\n🏷️ Création de ${parents.length} catégories parentes...`)
|
||||
const parents = defaultCategories.filter((c) => c.parentSlug === null);
|
||||
console.log(`\n🏷️ Création de ${parents.length} catégories parentes...`);
|
||||
|
||||
for (const category of parents) {
|
||||
const existing = await prisma.category.findFirst({
|
||||
where: { name: category.name, parentId: null },
|
||||
})
|
||||
});
|
||||
|
||||
if (!existing) {
|
||||
const created = await prisma.category.create({
|
||||
@@ -39,29 +39,29 @@ async function main() {
|
||||
keywords: JSON.stringify(category.keywords),
|
||||
parentId: null,
|
||||
},
|
||||
})
|
||||
slugToId.set(category.slug, created.id)
|
||||
console.log(` ✅ ${category.name}`)
|
||||
});
|
||||
slugToId.set(category.slug, created.id);
|
||||
console.log(` ✅ ${category.name}`);
|
||||
} else {
|
||||
slugToId.set(category.slug, existing.id)
|
||||
slugToId.set(category.slug, existing.id);
|
||||
}
|
||||
}
|
||||
|
||||
// Puis les enfants
|
||||
const children = defaultCategories.filter((c) => c.parentSlug !== null)
|
||||
console.log(`\n📂 Création de ${children.length} sous-catégories...`)
|
||||
const children = defaultCategories.filter((c) => c.parentSlug !== null);
|
||||
console.log(`\n📂 Création de ${children.length} sous-catégories...`);
|
||||
|
||||
for (const category of children) {
|
||||
const parentId = slugToId.get(category.parentSlug!)
|
||||
const parentId = slugToId.get(category.parentSlug!);
|
||||
|
||||
if (!parentId) {
|
||||
console.log(` ⚠️ Parent non trouvé pour: ${category.name}`)
|
||||
continue
|
||||
console.log(` ⚠️ Parent non trouvé pour: ${category.name}`);
|
||||
continue;
|
||||
}
|
||||
|
||||
const existing = await prisma.category.findFirst({
|
||||
where: { name: category.name, parentId },
|
||||
})
|
||||
});
|
||||
|
||||
if (!existing) {
|
||||
const created = await prisma.category.create({
|
||||
@@ -72,24 +72,24 @@ async function main() {
|
||||
keywords: JSON.stringify(category.keywords),
|
||||
parentId,
|
||||
},
|
||||
})
|
||||
slugToId.set(category.slug, created.id)
|
||||
console.log(` ✅ ${category.name}`)
|
||||
});
|
||||
slugToId.set(category.slug, created.id);
|
||||
console.log(` ✅ ${category.name}`);
|
||||
} else {
|
||||
slugToId.set(category.slug, existing.id)
|
||||
slugToId.set(category.slug, existing.id);
|
||||
}
|
||||
}
|
||||
|
||||
// Stats
|
||||
const totalCategories = await prisma.category.count()
|
||||
console.log(`\n✨ Seeding terminé! ${totalCategories} catégories en base.`)
|
||||
const totalCategories = await prisma.category.count();
|
||||
console.log(`\n✨ Seeding terminé! ${totalCategories} catégories en base.`);
|
||||
}
|
||||
|
||||
main()
|
||||
.catch((e) => {
|
||||
console.error(e)
|
||||
process.exit(1)
|
||||
console.error(e);
|
||||
process.exit(1);
|
||||
})
|
||||
.finally(async () => {
|
||||
await prisma.$disconnect()
|
||||
})
|
||||
await prisma.$disconnect();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user