Skip to content

Commit 11f5d2d

Browse files
authored
Merge pull request #28 from velog-io/fix/notification-by-self
fix: cannot create notification for self
2 parents 01f8562 + d2ab1ba commit 11f5d2d

File tree

2 files changed

+26
-19
lines changed
  • packages/velog-server/src/services

2 files changed

+26
-19
lines changed

packages/velog-server/src/services/NotificationService/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { BadRequestError } from '@errors/BadRequestErrors.js'
2+
import { ConfilctError } from '@errors/ConfilctError'
23
import { ForbiddenError } from '@errors/ForbiddenError.js'
34
import { NotFoundError } from '@errors/NotfoundError.js'
45
import { UnauthorizedError } from '@errors/UnauthorizedError.js'
@@ -128,6 +129,10 @@ export class NotificationService implements Service {
128129
throw new BadRequestError('Not found action')
129130
}
130131

132+
if (fkUserId === actor.id) {
133+
throw new ConfilctError('Cannot target the same user as actor')
134+
}
135+
131136
const action = (actionInfo as any)[type]
132137

133138
const validate = this.notificationActionValidate(type, action)

packages/velog-server/src/services/PostLikeService/index.ts

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -92,26 +92,28 @@ export class PostLikeService implements Service {
9292
},
9393
})
9494

95-
// create notification
96-
await this.notificationService.createOrUpdate({
97-
fkUserId: post.fk_user_id,
98-
actorId: signedUserId,
99-
actionId: post.id,
100-
type: 'postLike',
101-
action: {
102-
postLike: {
103-
post_like_id: postLike.id,
104-
actor_display_name: signedUser.profile?.display_name || '',
105-
actor_thumbnail: signedUser.profile?.thumbnail || '',
106-
actor_username: signedUser.username,
107-
post_id: likesPost.id,
108-
post_title: likesPost.title || '',
109-
post_url_slug: likesPost.url_slug || '',
110-
post_writer_username: likesPost.user.username,
111-
type: 'postLike',
95+
if (post.fk_user_id !== signedUserId) {
96+
// create notification
97+
await this.notificationService.createOrUpdate({
98+
fkUserId: post.fk_user_id,
99+
actorId: signedUserId,
100+
actionId: post.id,
101+
type: 'postLike',
102+
action: {
103+
postLike: {
104+
post_like_id: postLike.id,
105+
actor_display_name: signedUser.profile?.display_name || '',
106+
actor_thumbnail: signedUser.profile?.thumbnail || '',
107+
actor_username: signedUser.username,
108+
post_id: likesPost.id,
109+
post_title: likesPost.title || '',
110+
post_url_slug: likesPost.url_slug || '',
111+
post_writer_username: likesPost.user.username,
112+
type: 'postLike',
113+
},
112114
},
113-
},
114-
})
115+
})
116+
}
115117

116118
const unscored = this.utils.checkUnscore(post.body!.concat(post.title || ''))
117119
if (!unscored) {

0 commit comments

Comments
 (0)