Skip to content

Commit 0a5be60

Browse files
authored
Merge pull request #29 from velog-io/development
알림기능 버그 수정 및 로직 변경
2 parents 2e4b2ad + 31c6913 commit 0a5be60

File tree

73 files changed

+544
-487
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+544
-487
lines changed

.github/workflows/velog-cron-build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
runs-on: ubuntu-latest
1212
strategy:
1313
matrix:
14-
node-version: [18.16]
14+
node-version: [18.18.2]
1515
defaults:
1616
run:
1717
working-directory: './packages/velog-cron'

.github/workflows/velog-server-build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
runs-on: ubuntu-latest
1212
strategy:
1313
matrix:
14-
node-version: [18.16]
14+
node-version: [18.18.2]
1515
defaults:
1616
run:
1717
working-directory: './packages/velog-server'

.github/workflows/velog-web-build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
runs-on: ubuntu-latest
1313
strategy:
1414
matrix:
15-
node-version: [18.16]
15+
node-version: [18.18.2]
1616
defaults:
1717
run:
1818
working-directory: './packages/velog-web'

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@
66
.env
77
.env.*
88
!**/**/.env.example
9+
10+
.vscode

.vscode/c_cpp_properties.json

Lines changed: 0 additions & 14 deletions
This file was deleted.

.vscode/launch.json

Lines changed: 0 additions & 13 deletions
This file was deleted.

.vscode/settings.json

Lines changed: 0 additions & 57 deletions
This file was deleted.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-- AlterTable
2+
ALTER TABLE "notifications" ADD COLUMN "is_noticed" BOOLEAN NOT NULL DEFAULT false;

packages/velog-prisma/prisma/schema.prisma

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -628,8 +628,9 @@ model Notification {
628628
action Json @default("{}")
629629
action_id String? @db.Uuid
630630
is_read Boolean @default(false)
631-
is_deleted Boolean @default(false)
632631
read_at DateTime?
632+
is_deleted Boolean @default(false)
633+
is_noticed Boolean @default(false)
633634
created_at DateTime @default(now()) @db.Timestamptz(6)
634635
user User @relation(fields: [fk_user_id], references: [id], onDelete: Cascade, onUpdate: Restrict)
635636

packages/velog-scripts/scripts/privatePostsOfSpamAccount.mts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ class Runner implements IRunner {
2626
const user = await this.findUsersByUsername(username)
2727
const posts = await this.findWritenPostsByUserId(user.id)
2828

29+
// add block list
30+
await this.redis.addBlockList(username)
31+
2932
if (posts.length === 0) {
3033
console.log(`${user.username} 유저의 비공개 처리 할 게시글이 없습니다.`)
3134
continue
@@ -44,9 +47,6 @@ class Runner implements IRunner {
4447
// set private = true
4548
await this.setIsPrivatePost(postIds)
4649

47-
// add block list
48-
await this.redis.addBlockList(username)
49-
5050
const blockUesrInfo: BlockUserInfo = {
5151
id: user.id,
5252
username: user.username,
@@ -62,7 +62,7 @@ class Runner implements IRunner {
6262
}
6363

6464
if (handledUser.length === 0) {
65-
console.log('게시글 비공개 처리된 유저가 존재하지 않습니다.')
65+
console.log('비공개 게시글 처리된 유저가 존재하지 않습니다.')
6666
process.exit(0)
6767
}
6868

packages/velog-server/src/common/plugins/global/errorHandlerPlugin.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ const errorHandlerPlugin: FastifyPluginCallback = (fastify, _, done) => {
1818
'error',
1919
JSON.stringify({
2020
type: 'fastify OnError',
21-
requestbody: request?.body,
21+
requestbody: request?.body || 'none',
22+
query: request?.query || 'none',
2223
error,
2324
user: request?.user,
2425
}),

packages/velog-server/src/graphql/Notification.gql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@ enum NotificationType {
1919

2020
type Query {
2121
notifications(input: NotificationsInput!): [Notification!]!
22-
notificationCount: Int!
22+
notNoticeNotificationCount: Int!
2323
}
2424

2525
type Mutation {
2626
createNotification(input: CreateNotificationInput!): Notification!
27+
updateNotNoticeNotification: Void
2728
readNotification(input: ReadNotificationInput!): Void
2829
readAllNotifications: Void
2930
removeAllNotifications: Void

packages/velog-server/src/graphql/helpers/generated.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ export type Mutation = {
205205
unregister?: Maybe<Scalars['Void']['output']>
206206
updateAbout?: Maybe<UserProfile>
207207
updateEmailRules?: Maybe<UserMeta>
208+
updateNotNoticeNotification?: Maybe<Scalars['Void']['output']>
208209
updateProfile?: Maybe<UserProfile>
209210
updateSocialInfo?: Maybe<UserProfile>
210211
updateThumbnail?: Maybe<UserProfile>
@@ -359,7 +360,7 @@ export type Query = {
359360
followers: Array<FollowResult>
360361
followings: Array<FollowResult>
361362
isLogged?: Maybe<Scalars['Boolean']['output']>
362-
notificationCount: Scalars['Int']['output']
363+
notNoticeNotificationCount: Scalars['Int']['output']
363364
notifications: Array<Notification>
364365
post?: Maybe<Post>
365366
posts: Array<Post>
@@ -1055,6 +1056,7 @@ export type MutationResolvers<
10551056
ContextType,
10561057
RequireFields<MutationUpdateEmailRulesArgs, 'input'>
10571058
>
1059+
updateNotNoticeNotification?: Resolver<Maybe<ResolversTypes['Void']>, ParentType, ContextType>
10581060
updateProfile?: Resolver<
10591061
Maybe<ResolversTypes['UserProfile']>,
10601062
ParentType,
@@ -1190,7 +1192,7 @@ export type QueryResolvers<
11901192
RequireFields<QueryFollowingsArgs, 'input'>
11911193
>
11921194
isLogged?: Resolver<Maybe<ResolversTypes['Boolean']>, ParentType, ContextType>
1193-
notificationCount?: Resolver<ResolversTypes['Int'], ParentType, ContextType>
1195+
notNoticeNotificationCount?: Resolver<ResolversTypes['Int'], ParentType, ContextType>
11941196
notifications?: Resolver<
11951197
Array<ResolversTypes['Notification']>,
11961198
ParentType,

packages/velog-server/src/graphql/resolvers/notificationResolvers.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ const notificationResolvers: Resolvers = {
99
const notificationService = container.resolve(NotificationService)
1010
return await notificationService.list(input, ctx.user?.id)
1111
},
12-
notificationCount: async (_, __, ctx) => {
12+
notNoticeNotificationCount: async (_, __, ctx) => {
1313
const notificationService = container.resolve(NotificationService)
14-
return await notificationService.getCount(ctx.user?.id)
14+
return await notificationService.getNotNoticeCount(ctx.user?.id)
1515
},
1616
},
1717
Mutation: {
@@ -28,6 +28,10 @@ const notificationResolvers: Resolvers = {
2828
signedUserId: ctx.user?.id,
2929
})
3030
},
31+
updateNotNoticeNotification: async (_, __, ctx) => {
32+
const notificationService = container.resolve(NotificationService)
33+
return await notificationService.updateNotNotice(ctx.user?.id)
34+
},
3135
readNotification: async (_, { input }, ctx) => {
3236
const notificationService = container.resolve(NotificationService)
3337
return await notificationService.read(input.notification_ids, ctx.user?.id)

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

Lines changed: 30 additions & 3 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.js'
23
import { ForbiddenError } from '@errors/ForbiddenError.js'
34
import { NotFoundError } from '@errors/NotfoundError.js'
45
import { UnauthorizedError } from '@errors/UnauthorizedError.js'
@@ -17,7 +18,8 @@ import { z } from 'zod'
1718

1819
interface Service {
1920
list(query?: NotificationsInput, signedUserId?: string): Promise<Notification[]>
20-
getCount(signedUserId?: string): Promise<number>
21+
getNotNoticeCount(signedUserId?: string): Promise<number>
22+
updateNotNotice(signedUserId?: string): Promise<void>
2123
create(args: CreateArgs): Promise<Notification>
2224
read(notificationIds: string[], signedUserId?: string): Promise<void>
2325
readAll(signedUserId?: string): Promise<void>
@@ -65,7 +67,7 @@ export class NotificationService implements Service {
6567
})
6668
return notifications as unknown as Notification[]
6769
}
68-
public async getCount(signedUserId?: string): Promise<number> {
70+
public async getNotNoticeCount(signedUserId?: string): Promise<number> {
6971
if (!signedUserId) {
7072
throw new UnauthorizedError('Not logged in')
7173
}
@@ -80,7 +82,28 @@ export class NotificationService implements Service {
8082
where: {
8183
fk_user_id: signedUserId,
8284
is_deleted: false,
83-
is_read: false,
85+
is_noticed: false,
86+
},
87+
})
88+
}
89+
public async updateNotNotice(signedUserId?: string): Promise<void> {
90+
if (!signedUserId) {
91+
throw new UnauthorizedError('Not logged in')
92+
}
93+
94+
const user = await this.userService.findById(signedUserId)
95+
96+
if (!user) {
97+
throw new NotFoundError('Not found user')
98+
}
99+
100+
await this.db.notification.updateMany({
101+
where: {
102+
fk_user_id: signedUserId,
103+
is_noticed: false,
104+
},
105+
data: {
106+
is_noticed: true,
84107
},
85108
})
86109
}
@@ -106,6 +129,10 @@ export class NotificationService implements Service {
106129
throw new BadRequestError('Not found action')
107130
}
108131

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

111138
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) {

packages/velog-web/next.config.mjs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ const nextConfig = {
66
reactStrictMode: true,
77
swcMinify: true,
88
images: {
9-
formats: ['image/avif', 'image/webp'],
109
domains: ['velog.velcdn.com', 'images.velog.io', 'media.vlpt.us'],
1110
unoptimized: true,
1211
},

packages/velog-web/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
"html-react-parser": "^5.0.6",
4444
"inquirer": "^9.2.7",
4545
"nanoid": "^4.0.2",
46-
"next": "^14.0.3",
46+
"next": "^14.1.0",
4747
"postcss-flexbugs-fixes": "^5.0.2",
4848
"postcss-preset-env": "^8.5.0",
4949
"prismjs": "^1.29.0",

packages/velog-web/src/app/(list)/layout.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ type Props = {
44
children: React.ReactNode
55
}
66

7-
export default async function HomeListLayout({ children }: Props) {
7+
export default function HomeListLayout({ children }: Props) {
88
return <HomeLayout>{children}</HomeLayout>
99
}

packages/velog-web/src/app/(list)/trending/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ export const metadata: Metadata = {
99
alternates: { canonical: 'https://velog.io/' },
1010
}
1111

12-
export default async function Trending({ params }: Props) {
12+
export default function Trending({ params }: Props) {
1313
return <TrendingHome params={params} />
1414
}

0 commit comments

Comments
 (0)