diff --git a/src/models/post.ts b/src/models/post.ts index 31db0a1..8b49115 100644 --- a/src/models/post.ts +++ b/src/models/post.ts @@ -142,11 +142,13 @@ PostSchema.method('formatScreenshot', function formatScree } }); -PostSchema.method('formatTopicTag', function formatTopicTag(): PostTopicTag { - return { - name: this.topic_tag, - title_id: this.title_id - }; +PostSchema.method('formatTopicTag', function formatTopicTag(): PostTopicTag | undefined { + if (this.topic_tag?.trim()) { + return { + name: this.topic_tag, + title_id: this.title_id + }; + } }); PostSchema.method('json', function json(options: PostToJSONOptions, community?: HydratedCommunityDocument): PostData { diff --git a/src/types/mongoose/post.ts b/src/types/mongoose/post.ts index 49731c9..f13b7c1 100644 --- a/src/types/mongoose/post.ts +++ b/src/types/mongoose/post.ts @@ -48,7 +48,7 @@ export interface IPostMethods { cleanedAppData(): string; formatPainting(): PostPainting | undefined; formatScreenshot(): PostScreenshot | undefined; - formatTopicTag(): PostTopicTag; + formatTopicTag(): PostTopicTag | undefined; json(options: PostToJSONOptions, community?: HydratedCommunityDocument): PostData; }