Skip to content

fix: cannot create notification for self #28

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { BadRequestError } from '@errors/BadRequestErrors.js'
import { ConfilctError } from '@errors/ConfilctError'
import { ForbiddenError } from '@errors/ForbiddenError.js'
import { NotFoundError } from '@errors/NotfoundError.js'
import { UnauthorizedError } from '@errors/UnauthorizedError.js'
Expand Down Expand Up @@ -128,6 +129,10 @@ export class NotificationService implements Service {
throw new BadRequestError('Not found action')
}

if (fkUserId === actor.id) {
throw new ConfilctError('Cannot target the same user as actor')
}

const action = (actionInfo as any)[type]

const validate = this.notificationActionValidate(type, action)
Expand Down
40 changes: 21 additions & 19 deletions packages/velog-server/src/services/PostLikeService/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,26 +92,28 @@ export class PostLikeService implements Service {
},
})

// create notification
await this.notificationService.createOrUpdate({
fkUserId: post.fk_user_id,
actorId: signedUserId,
actionId: post.id,
type: 'postLike',
action: {
postLike: {
post_like_id: postLike.id,
actor_display_name: signedUser.profile?.display_name || '',
actor_thumbnail: signedUser.profile?.thumbnail || '',
actor_username: signedUser.username,
post_id: likesPost.id,
post_title: likesPost.title || '',
post_url_slug: likesPost.url_slug || '',
post_writer_username: likesPost.user.username,
type: 'postLike',
if (post.fk_user_id !== signedUserId) {
// create notification
await this.notificationService.createOrUpdate({
fkUserId: post.fk_user_id,
actorId: signedUserId,
actionId: post.id,
type: 'postLike',
action: {
postLike: {
post_like_id: postLike.id,
actor_display_name: signedUser.profile?.display_name || '',
actor_thumbnail: signedUser.profile?.thumbnail || '',
actor_username: signedUser.username,
post_id: likesPost.id,
post_title: likesPost.title || '',
post_url_slug: likesPost.url_slug || '',
post_writer_username: likesPost.user.username,
type: 'postLike',
},
},
},
})
})
}

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