Skip to content

Commit

Permalink
perf(page): delete page also delete comments
Browse files Browse the repository at this point in the history
  • Loading branch information
wibus-wee committed Aug 18, 2022
1 parent dde359a commit e4be78a
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/modules/page/page.controller.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { InjectModel } from "@app/db/model.transformer";
import {
Body,
Controller,
Expand All @@ -17,6 +18,7 @@ import { ApiName } from "~/common/decorator/openapi.decorator";
import { CannotFindException } from "~/common/exceptions/cant-find.exception";
import { MongoIdDto } from "~/shared/dto/id.dto";
import { PagerDto } from "~/shared/dto/pager.dto";
import { CommentModel, CommentType } from "../comments/comments.model";

import { PageModel, PartialPageModel } from "./page.model";
import { PageService } from "./page.service";
Expand All @@ -25,6 +27,8 @@ import { PageService } from "./page.service";
@ApiName
export class PageController {
constructor(
@InjectModel(CommentModel)
private readonly commentModel: MongooseModel<CommentModel>,
private readonly pageService: PageService // @Inject(forwardRef(() => PluginsService)) // private readonly pluginService: PluginsService,
) {}

Expand Down Expand Up @@ -102,9 +106,12 @@ export class PageController {
@ApiOperation({ summary: "删除页面" })
@Auth()
async deletePage(@Param() params: MongoIdDto) {
await this.pageService.model.deleteOne({
_id: params.id,
});
await Promise.all([
this.pageService.model.deleteOne({
_id: params.id,
}),
this.commentModel.deleteMany({ ref: params.id, refType: CommentType.Page }),
])
return;
}
}

0 comments on commit e4be78a

Please sign in to comment.