File tree 2 files changed +14
-9
lines changed
2 files changed +14
-9
lines changed Original file line number Diff line number Diff line change @@ -379,9 +379,12 @@ export class PostApiService implements Service {
379
379
return false
380
380
}
381
381
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
385
388
}
386
389
private async isPostLimitReached ( signedUserId : string ) : Promise < boolean > {
387
390
const recentPostCount = await this . db . post . count ( {
Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ interface Service {
14
14
tagLoader ( ) : DataLoader < string , Tag [ ] >
15
15
getOriginTag ( tagname : string ) : Promise < Tag | null >
16
16
getUserTags ( username : string , signedUserId ?: string ) : Promise < GetUserTagsResult >
17
- findOrCreate ( name : string ) : Promise < Tag >
17
+ findOrCreate ( name : string ) : Promise < Tag | null >
18
18
}
19
19
20
20
@injectable ( )
@@ -73,9 +73,11 @@ export class TagService implements Service {
73
73
] ,
74
74
} )
75
75
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
+ )
79
81
. map ( ( array ) => array . map ( ( pt ) => pt . tag ! ) )
80
82
} )
81
83
}
@@ -157,7 +159,7 @@ export class TagService implements Service {
157
159
return rawData . map ( ( data ) => ( { ...data , posts_count : Number ( data . posts_count ) } ) )
158
160
}
159
161
160
- public async findOrCreate ( name : string ) : Promise < Tag > {
162
+ public async findOrCreate ( name : string ) : Promise < Tag | null > {
161
163
const tag = await this . findByName ( name )
162
164
if ( tag ) return tag
163
165
@@ -179,7 +181,7 @@ export class TagService implements Service {
179
181
name : name ,
180
182
} ,
181
183
} )
182
- return tag !
184
+ return tag
183
185
}
184
186
}
185
187
}
You can’t perform that action at this time.
0 commit comments