@@ -10,13 +10,16 @@ import {
1010 PersonSubjectsRepo ,
1111 SubjectRelationRepo ,
1212 SubjectRepo ,
13+ SubjectTopicRepo ,
1314} from '@app/lib/orm/index.ts' ;
1415import { subjectCover } from '@app/lib/response.ts' ;
1516import { platforms } from '@app/lib/subject/index.ts' ;
17+ import { ListTopicDisplays } from '@app/lib/topic/display.ts' ;
1618
1719import { convertCharacter } from './character.ts' ;
1820import { InfoboxItem } from './common.ts' ;
1921import { convertPerson } from './person.ts' ;
22+ import { convertUser } from './user.ts' ;
2023
2124const Episode = objectType ( {
2225 name : 'Episode' ,
@@ -127,6 +130,22 @@ const SubjectAirtime = objectType({
127130 } ,
128131} ) ;
129132
133+ const SubjectTopic = objectType ( {
134+ name : 'SubjectTopic' ,
135+ definition ( t ) {
136+ t . nonNull . int ( 'id' ) ;
137+ t . nonNull . field ( 'creator' , {
138+ type : 'User' ,
139+ } ) ;
140+ t . nonNull . string ( 'title' ) ;
141+ t . nonNull . int ( 'created_at' ) ;
142+ t . nonNull . int ( 'updated_at' ) ;
143+ t . nonNull . int ( 'replies' ) ;
144+ t . nonNull . int ( 'state' ) ;
145+ t . nonNull . int ( 'display' ) ;
146+ } ,
147+ } ) ;
148+
130149const Subject = objectType ( {
131150 name : 'Subject' ,
132151 definition ( t ) {
@@ -321,6 +340,34 @@ const Subject = objectType({
321340 } ) ;
322341 } ,
323342 } ) ;
343+ t . list . nonNull . field ( 'topics' , {
344+ type : SubjectTopic ,
345+ args : {
346+ limit : nonNull ( intArg ( { default : 10 } ) ) ,
347+ offset : nonNull ( intArg ( { default : 0 } ) ) ,
348+ } ,
349+ async resolve (
350+ parent : { id : number } ,
351+ { limit, offset } : { limit : number ; offset : number } ,
352+ { auth : u } : Context ,
353+ ) {
354+ let query = SubjectTopicRepo . createQueryBuilder ( 't' )
355+ . innerJoinAndMapOne ( 't.creator' , entity . User , 'u' , 'u.id = t.creatorID' )
356+ . where ( 't.parentID = :id' , { id : parent . id } ) ;
357+ const displays = ListTopicDisplays ( u ) ;
358+ if ( displays . length > 0 ) {
359+ query = query . andWhere ( 't.display IN (:...displays)' , { displays } ) ;
360+ }
361+ const topics = await query
362+ . orderBy ( 't.createdAt' , 'DESC' )
363+ . skip ( offset )
364+ . take ( limit )
365+ . getMany ( ) ;
366+ return topics . map ( ( t ) => {
367+ return convertTopic ( t ) ;
368+ } ) ;
369+ } ,
370+ } ) ;
324371 } ,
325372} ) ;
326373
@@ -410,6 +457,19 @@ export function convertSubject(subject: entity.Subject) {
410457 } ;
411458}
412459
460+ export function convertTopic ( topic : entity . SubjectTopic ) {
461+ return {
462+ id : topic . id ,
463+ creator : convertUser ( topic . creator ) ,
464+ title : topic . title ,
465+ created_at : topic . createdAt ,
466+ updated_at : topic . updatedAt ,
467+ replies : topic . replies ,
468+ state : topic . state ,
469+ display : topic . display ,
470+ } ;
471+ }
472+
413473const SubjectByIDQuery = extendType ( {
414474 type : 'Query' ,
415475 definition ( t ) {
0 commit comments