Skip to content

Commit 709336f

Browse files
authored
Merge pull request #53 from velog-io/development
태그 길이 제한
2 parents 72ed1a3 + 371fee4 commit 709336f

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

Diff for: apps/server/src/services/PostApiService/index.mts

+6-3
Original file line numberDiff line numberDiff line change
@@ -379,9 +379,12 @@ export class PostApiService implements Service {
379379
return false
380380
}
381381
private async handleTags(tags: string[], postId: string): Promise<Tag[]> {
382-
const tagsData = await Promise.all(tags.map((tag) => this.tagService.findOrCreate(tag)))
383-
await this.postTagService.syncPostTags(postId, tagsData)
384-
return tagsData
382+
const tagsData = await Promise.all(
383+
tags.map((tag) => this.tagService.findOrCreate(tag.trim().slice(0, 255))),
384+
)
385+
const validTags = tagsData.filter((tag): tag is Tag => !!tag)
386+
await this.postTagService.syncPostTags(postId, validTags)
387+
return validTags
385388
}
386389
private async isPostLimitReached(signedUserId: string): Promise<boolean> {
387390
const recentPostCount = await this.db.post.count({

Diff for: apps/server/src/services/TagService/index.ts

+8-6
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ interface Service {
1414
tagLoader(): DataLoader<string, Tag[]>
1515
getOriginTag(tagname: string): Promise<Tag | null>
1616
getUserTags(username: string, signedUserId?: string): Promise<GetUserTagsResult>
17-
findOrCreate(name: string): Promise<Tag>
17+
findOrCreate(name: string): Promise<Tag | null>
1818
}
1919

2020
@injectable()
@@ -73,9 +73,11 @@ export class TagService implements Service {
7373
],
7474
})
7575
return this.utils
76-
.groupById<
77-
Prisma.PostTagGetPayload<{ include: { tag: true } }>
78-
>(postIds as string[], postsTags, (pt) => pt.fk_post_id!)
76+
.groupById<Prisma.PostTagGetPayload<{ include: { tag: true } }>>(
77+
postIds as string[],
78+
postsTags,
79+
(pt) => pt.fk_post_id!,
80+
)
7981
.map((array) => array.map((pt) => pt.tag!))
8082
})
8183
}
@@ -157,7 +159,7 @@ export class TagService implements Service {
157159
return rawData.map((data) => ({ ...data, posts_count: Number(data.posts_count) }))
158160
}
159161

160-
public async findOrCreate(name: string): Promise<Tag> {
162+
public async findOrCreate(name: string): Promise<Tag | null> {
161163
const tag = await this.findByName(name)
162164
if (tag) return tag
163165

@@ -179,7 +181,7 @@ export class TagService implements Service {
179181
name: name,
180182
},
181183
})
182-
return tag!
184+
return tag
183185
}
184186
}
185187
}

0 commit comments

Comments
 (0)