修复种子脚本:更新已有板块的名称/描述/图标
This commit is contained in:
@@ -162,19 +162,32 @@ async function createIndustryCategories() {
|
|||||||
});
|
});
|
||||||
console.log(` + ${cat.name}`);
|
console.log(` + ${cat.name}`);
|
||||||
} else {
|
} else {
|
||||||
if (!childCat.parentId) {
|
await prisma.forumCategory.update({
|
||||||
await prisma.forumCategory.update({
|
where: { id: childCat.id },
|
||||||
where: { id: childCat.id },
|
data: {
|
||||||
data: { parentId: parent.id },
|
name: cat.name,
|
||||||
});
|
icon: cat.icon,
|
||||||
}
|
description: cat.description,
|
||||||
console.log(` ✓ ${cat.name} (exists)`);
|
sortOrder: cat.sortOrder,
|
||||||
|
parentId: parent.id,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
console.log(` ↻ ${cat.name} (updated)`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const existingSlugs = new Set(childCat.children.map(c => c.slug));
|
const existingSlugs = new Set(childCat.children.map(c => c.slug));
|
||||||
for (const sub of cat.children) {
|
for (const sub of cat.children) {
|
||||||
if (existingSlugs.has(sub.slug)) {
|
if (existingSlugs.has(sub.slug)) {
|
||||||
console.log(` - ${sub.name} (exists)`);
|
await prisma.forumCategory.update({
|
||||||
|
where: { slug: sub.slug },
|
||||||
|
data: {
|
||||||
|
name: sub.name,
|
||||||
|
icon: sub.icon,
|
||||||
|
description: sub.description,
|
||||||
|
parentId: childCat.id,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
console.log(` ↻ ${sub.name} (updated)`);
|
||||||
} else {
|
} else {
|
||||||
const conflictSlug = await prisma.forumCategory.findUnique({
|
const conflictSlug = await prisma.forumCategory.findUnique({
|
||||||
where: { slug: sub.slug },
|
where: { slug: sub.slug },
|
||||||
|
|||||||
Reference in New Issue
Block a user