From fc4a27971641e876886db26c92a2e55dfbe7cd3a Mon Sep 17 00:00:00 2001 From: wibus-wee <1596355173@qq.com> Date: Wed, 3 Aug 2022 13:38:52 +0800 Subject: [PATCH] perf(category): change merge api path and method --- src/modules/category/category.controller.ts | 23 +++++++++++---------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/modules/category/category.controller.ts b/src/modules/category/category.controller.ts index c4b19fb80..eeac6f588 100644 --- a/src/modules/category/category.controller.ts +++ b/src/modules/category/category.controller.ts @@ -153,27 +153,28 @@ export class CategoryController { return this.categoryService.model.create({ name, slug: slug ?? name }); // 创建分类 } - @Put("/:from/to/:to") + @Post("/merge") @ApiOperation({ summary: "合并分类或标签 (Beta)" }) @Auth() - @ApiParam({ name: "from", type: "string", required: true }) - @ApiParam({ name: "to", type: "string", required: true }) async merge( - @Param() { from, to }, - @Query() { tag }: MultiQueryTagAndCategoryDto + @Body() body: { + type: CategoryType; + from: string; + to: string; + } ) { - if (!from || !to) { + if (!body.from || !body.to) { throw new BadRequestException("from and to are required"); } - if (from === to) { + if (body.from === body.to) { throw new BadRequestException("from and to are same"); } - if (tag) { + if (body.type === CategoryType.Tag) { // 合并标签 - await this.categoryService.mergeTag(from, to); - } else { + await this.categoryService.mergeTag(body.from, body.to); + } else if (body.type === CategoryType.Category) { // 合并分类 - await this.categoryService.mergeCategory(from, to); + await this.categoryService.mergeCategory(body.from, body.to); } return { message: "success" }; }