Skip to content

Commit

Permalink
fix(page-service): delete article no return resulting in an error req…
Browse files Browse the repository at this point in the history
…uest (#803)
  • Loading branch information
wibus-wee authored Jun 9, 2023
1 parent b24ecc0 commit 113c714
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ export class NotificationServiceController {
console.log('更新了一篇文章:', data.title);
}

@EventPattern(NotificationEvents.SystemPostDelete)
async systemPostDelete(data: PostModel) {
console.log('删除了一篇文章:', data.title);
}

@EventPattern(NotificationEvents.SystemPageCreate)
async systemPageCreate(data: PageModel) {
console.log('创建了一个页面:', data.title);
Expand Down
10 changes: 6 additions & 4 deletions apps/page-service/src/post-service.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,10 +311,12 @@ export class PostService {
* @returns void
**/
async deletePostById(id: string) {
await Promise.all([
this.model.deleteOne({ _id: id }),
// this.commentModel.deleteMany({ ref: id, refType: CommentType.Post }),
]);
return this.postModel.findByIdAndDelete(id).then((res) => {
if (res) {
this.notification.emit(NotificationEvents.SystemPostDelete, res);
}
return true;
});
}

async CreateDefaultPost(cateId: string) {
Expand Down
2 changes: 2 additions & 0 deletions shared/constants/event.constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,10 @@ export enum NotificationEvents {

SystemPostCreate = 'system.post.create',
SystemPostUpdate = 'system.post.update',
SystemPostDelete = 'system.post.delete',
SystemPageCreate = 'system.page.create',
SystemPageUpdate = 'system.page.update',
SystemPageDelete = 'system.page.delete',

Ping = 'notification.ping',

Expand Down

0 comments on commit 113c714

Please sign in to comment.