@@ -7,29 +7,28 @@ import type { HydratedCommunityDocument } from '@/types/mongoose/community';
77import type { PostToJSONOptions } from '@/types/mongoose/post-to-json-options' ;
88import type { PostData , PostPainting , PostScreenshot , PostTopicTag } from '@/types/miiverse/post' ;
99
10+ /* Constraints here (default, required etc.) apply to new documents being added
11+ * See IPost for expected shape of query results
12+ * If you add default: or required:, please also update IPost and IPostInput!
13+ */
1014const PostSchema = new Schema < IPost , PostModel , IPostMethods > ( {
11- id : String ,
12- title_id : String ,
13- screen_name : String ,
14- body : String ,
15- app_data : String ,
16- painting : String ,
17- screenshot : String ,
18- screenshot_length : Number ,
19- search_key : {
20- type : [ String ] ,
21- default : undefined
22- } ,
23- topic_tag : {
24- type : String ,
25- default : undefined
26- } ,
27- community_id : {
28- type : String ,
29- default : undefined
30- } ,
31- created_at : Date ,
32- feeling_id : Number ,
15+ id : { type : String , required : true } ,
16+ title_id : { type : String } ,
17+ screen_name : { type : String , required : true } ,
18+ body : { type : String , required : true } ,
19+ app_data : { type : String } ,
20+
21+ painting : { type : String } ,
22+ screenshot : { type : String } ,
23+ screenshot_length : { type : Number } ,
24+
25+ search_key : { type : [ String ] } ,
26+ topic_tag : { type : String } ,
27+
28+ community_id : { type : String , required : true } ,
29+ created_at : { type : Date , required : true } ,
30+ feeling_id : { type : Number } ,
31+
3332 is_autopost : {
3433 type : Number ,
3534 default : 0
@@ -46,6 +45,7 @@ const PostSchema = new Schema<IPost, PostModel, IPostMethods>({
4645 type : Number ,
4746 default : 0
4847 } ,
48+
4949 empathy_count : {
5050 type : Number ,
5151 default : 0 ,
@@ -59,12 +59,15 @@ const PostSchema = new Schema<IPost, PostModel, IPostMethods>({
5959 type : Number ,
6060 default : 1
6161 } ,
62- mii : String ,
63- mii_face_url : String ,
64- pid : Number ,
65- platform_id : Number ,
66- region_id : Number ,
67- parent : String ,
62+
63+ mii : { type : String , required : true } ,
64+ mii_face_url : { type : String , required : true } ,
65+
66+ pid : { type : Number , required : true } ,
67+ platform_id : { type : Number } ,
68+ region_id : { type : Number } ,
69+ parent : { type : String } ,
70+
6871 reply_count : {
6972 type : Number ,
7073 default : 0
@@ -73,17 +76,21 @@ const PostSchema = new Schema<IPost, PostModel, IPostMethods>({
7376 type : Boolean ,
7477 default : false
7578 } ,
79+
7680 message_to_pid : {
7781 type : String ,
7882 default : null
7983 } ,
84+
8085 removed : {
8186 type : Boolean ,
8287 default : false
8388 } ,
84- removed_reason : String ,
85- yeahs : [ Number ] ,
86- number : Number
89+ removed_reason : { type : String } ,
90+ removed_by : { type : Number } ,
91+ removed_at : { type : Date } ,
92+
93+ yeahs : { type : [ Number ] , default : [ ] }
8794} , {
8895 id : false // * Disables the .id() getter used by Mongoose in TypeScript. Needed to have our own .id field
8996} ) ;
@@ -114,12 +121,12 @@ PostSchema.method<HydratedPostDocument>('cleanedMiiData', function cleanedMiiDat
114121 return this . mii . replace ( / [ ^ A - Z a - z 0 - 9 + / = ] / g, '' ) . replace ( / [ \n \r ] + / gm, '' ) . trim ( ) ;
115122} ) ;
116123
117- PostSchema . method < HydratedPostDocument > ( 'cleanedPainting' , function cleanedPainting ( ) : string {
118- return this . painting . replace ( / [ \n \r ] + / gm, '' ) . trim ( ) ;
124+ PostSchema . method < HydratedPostDocument > ( 'cleanedPainting' , function cleanedPainting ( ) : string | undefined {
125+ return this . painting ? .replace ( / [ \n \r ] + / gm, '' ) . trim ( ) ;
119126} ) ;
120127
121- PostSchema . method < HydratedPostDocument > ( 'cleanedAppData' , function cleanedAppData ( ) : string {
122- return this . app_data . replace ( / [ ^ A - Z a - z 0 - 9 + / = ] / g, '' ) . replace ( / [ \n \r ] + / gm, '' ) . trim ( ) ;
128+ PostSchema . method < HydratedPostDocument > ( 'cleanedAppData' , function cleanedAppData ( ) : string | undefined {
129+ return this . app_data ? .replace ( / [ ^ A - Z a - z 0 - 9 + / = ] / g, '' ) . replace ( / [ \n \r ] + / gm, '' ) . trim ( ) ;
123130} ) ;
124131
125132PostSchema . method < HydratedPostDocument > ( 'formatPainting' , function formatPainting ( ) : PostPainting | undefined {
@@ -146,7 +153,7 @@ PostSchema.method<HydratedPostDocument>('formatTopicTag', function formatTopicTa
146153 if ( this . topic_tag ?. trim ( ) ) {
147154 return {
148155 name : this . topic_tag ,
149- title_id : this . title_id
156+ title_id : this . title_id ?? ''
150157 } ;
151158 }
152159} ) ;
@@ -158,26 +165,26 @@ PostSchema.method<HydratedPostDocument>('json', function json(options: PostToJSO
158165 community_id : this . community_id , // TODO - This sucks
159166 country_id : this . country_id ,
160167 created_at : moment ( this . created_at ) . format ( 'YYYY-MM-DD HH:MM:SS' ) ,
161- feeling_id : this . feeling_id ,
168+ feeling_id : this . feeling_id ?? 0 ,
162169 id : this . id ,
163170 is_autopost : this . is_autopost ? 1 : 0 ,
164171 is_community_private_autopost : this . is_community_private_autopost ? 1 : 0 ,
165172 is_spoiler : this . is_spoiler ? 1 : 0 ,
166173 is_app_jumpable : this . is_app_jumpable ? 1 : 0 ,
167- empathy_count : this . empathy_count || 0 ,
174+ empathy_count : this . empathy_count ,
168175 language_id : this . language_id ,
169176 mii : undefined , // * Conditionally set later
170177 mii_face_url : undefined , // * Conditionally set later
171178 number : 0 ,
172179 painting : this . formatPainting ( ) ,
173180 pid : this . pid ,
174- platform_id : this . platform_id ,
175- region_id : this . region_id ,
176- reply_count : this . reply_count || 0 ,
181+ platform_id : this . platform_id ?? 1 ,
182+ region_id : this . region_id ?? 0 ,
183+ reply_count : this . reply_count ,
177184 screen_name : this . screen_name ,
178185 screenshot : this . formatScreenshot ( ) ,
179186 topic_tag : undefined , // * Conditionally set later
180- title_id : this . title_id
187+ title_id : this . title_id ?? ''
181188 } ;
182189
183190 if ( options . app_data ) {
0 commit comments