Skip to content

Commit

Permalink
fix(category): merge category with right field
Browse files Browse the repository at this point in the history
  • Loading branch information
wibus-wee committed Aug 10, 2022
1 parent eb454bf commit 381678a
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/modules/category/category.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,11 @@ export class CategoryService {
* @param to 目标分类名
*/
async mergeCategory(from: string, to: string) {
await this.postService.model.updateMany(
{ categoryId: from },
{ categoryId: to }
); // 更新文章的 categoryId 字段 为 to
await this.categoryModel.deleteOne({ _id: from }); // 删除 from 分类
const posts = await this.postService.model.find({ categoryId: from }); // 查找所有包含 from 分类的文章
for (const post of posts) {
await post.updateOne({ categoryId: to }); // 更新文章的 category 字段
}
return 1
}

/**
Expand Down

0 comments on commit 381678a

Please sign in to comment.