Skip to content

태그 길이 제한 #53

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 2 commits into from
Sep 3, 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
9 changes: 6 additions & 3 deletions apps/server/src/services/PostApiService/index.mts
Original file line number Diff line number Diff line change
Expand Up @@ -379,9 +379,12 @@ export class PostApiService implements Service {
return false
}
private async handleTags(tags: string[], postId: string): Promise<Tag[]> {
const tagsData = await Promise.all(tags.map((tag) => this.tagService.findOrCreate(tag)))
await this.postTagService.syncPostTags(postId, tagsData)
return tagsData
const tagsData = await Promise.all(
tags.map((tag) => this.tagService.findOrCreate(tag.trim().slice(0, 255))),
)
const validTags = tagsData.filter((tag): tag is Tag => !!tag)
await this.postTagService.syncPostTags(postId, validTags)
return validTags
}
private async isPostLimitReached(signedUserId: string): Promise<boolean> {
const recentPostCount = await this.db.post.count({
Expand Down
14 changes: 8 additions & 6 deletions apps/server/src/services/TagService/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ interface Service {
tagLoader(): DataLoader<string, Tag[]>
getOriginTag(tagname: string): Promise<Tag | null>
getUserTags(username: string, signedUserId?: string): Promise<GetUserTagsResult>
findOrCreate(name: string): Promise<Tag>
findOrCreate(name: string): Promise<Tag | null>
}

@injectable()
Expand Down Expand Up @@ -73,9 +73,11 @@ export class TagService implements Service {
],
})
return this.utils
.groupById<
Prisma.PostTagGetPayload<{ include: { tag: true } }>
>(postIds as string[], postsTags, (pt) => pt.fk_post_id!)
.groupById<Prisma.PostTagGetPayload<{ include: { tag: true } }>>(
postIds as string[],
postsTags,
(pt) => pt.fk_post_id!,
)
.map((array) => array.map((pt) => pt.tag!))
})
}
Expand Down Expand Up @@ -157,7 +159,7 @@ export class TagService implements Service {
return rawData.map((data) => ({ ...data, posts_count: Number(data.posts_count) }))
}

public async findOrCreate(name: string): Promise<Tag> {
public async findOrCreate(name: string): Promise<Tag | null> {
const tag = await this.findByName(name)
if (tag) return tag

Expand All @@ -179,7 +181,7 @@ export class TagService implements Service {
name: name,
},
})
return tag!
return tag
}
}
}
Expand Down