fix: delete article with delete comment
This commit is contained in:
@@ -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, {
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user