fix: delete article with delete comment

This commit is contained in:
Innei
2022-05-16 13:23:18 +08:00
parent 66e882b2dd
commit 4e39690fda
2 changed files with 14 additions and 6 deletions

View File

@@ -13,6 +13,8 @@ import { TextMacroService } from '~/processors/helper/helper.macro.service'
import { InjectModel } from '~/transformers/model.transformer'
import { deleteKeys } from '~/utils'
import { CommentRefTypes } from '../comment/comment.model'
import { CommentService } from '../comment/comment.service'
import { NoteModel } from './note.model'
@Injectable()
@@ -22,6 +24,7 @@ export class NoteService {
private readonly noteModel: MongooseModel<NoteModel>,
private readonly imageService: ImageService,
private readonly eventManager: EventManagerService,
private readonly commentService: CommentService,
private readonly textMacrosService: TextMacroService,
) {
@@ -177,10 +180,15 @@ export class NoteService {
throw new CannotFindException()
}
await this.noteModel.deleteOne({
_id: id,
})
await Promise.all([
this.noteModel.deleteOne({
_id: id,
}),
this.commentService.model.deleteMany({
ref: id,
refType: CommentRefTypes.Note,
}),
])
process.nextTick(async () => {
await Promise.all([
this.eventManager.broadcast(BusinessEvents.NOTE_DELETE, id, {

View File

@@ -21,7 +21,7 @@ import { TextMacroService } from '~/processors/helper/helper.macro.service'
import { InjectModel } from '~/transformers/model.transformer'
import { CategoryService } from '../category/category.service'
import { CommentModel } from '../comment/comment.model'
import { CommentModel, CommentRefTypes } from '../comment/comment.model'
import { PostModel } from './post.model'
@Injectable()
@@ -175,7 +175,7 @@ export class PostService {
async deletePost(id: string) {
await Promise.all([
this.model.deleteOne({ _id: id }),
this.commentModel.deleteMany({ pid: id }),
this.commentModel.deleteMany({ ref: id, refType: CommentRefTypes.Post }),
])
await this.eventManager.broadcast(BusinessEvents.POST_DELETE, id, {
scope: EventScope.TO_SYSTEM_VISITOR,