1- import { MediumEnum } from 'podverse-helpers' ;
2- import { EntityManager , Equal , FindManyOptions } from 'typeorm' ;
1+ import { getMediumIdArrayFromType , MediumEnum , QueryParamsMedium } from 'podverse-helpers' ;
2+ import { EntityManager , Equal , FindManyOptions , In } from 'typeorm' ;
33import { AccountFollowingChannel } from '@orm/entities/account/accountFollowingChannel' ;
44import { BaseManyService } from '@orm/services/base/baseManyService' ;
55import { AccountService } from '@orm/services/account/account' ;
@@ -15,20 +15,22 @@ export class AccountFollowingChannelService extends BaseManyService<AccountFollo
1515 this . channelService = new ChannelService ( ) ;
1616 }
1717
18- async getFollowedChannels ( account_id : number , medium_id : MediumEnum | null ,
18+ async getFollowedChannels ( account_id : number , mediumType : QueryParamsMedium | null ,
1919 config ?: FindManyOptions < AccountFollowingChannel > ) : Promise < AccountFollowingChannel [ ] > {
20+ const medium_ids = mediumType ? getMediumIdArrayFromType ( mediumType ) : null ;
21+
2022 const account = await this . accountService . get ( account_id ) ;
2123 if ( ! account ) {
2224 throw new Error ( "Account not found." ) ;
2325 }
2426
2527 const finalConfig = {
2628 ...config ,
27- ...( medium_id ? {
29+ ...( medium_ids ? {
2830 where : {
2931 ...config ?. where ,
3032 channel : {
31- medium_id : Equal ( medium_id )
33+ medium_id : In ( medium_ids )
3234 }
3335 }
3436 } : { } )
@@ -37,9 +39,11 @@ export class AccountFollowingChannelService extends BaseManyService<AccountFollo
3739 return this . _getAll ( account , finalConfig ) ;
3840 }
3941
40- async getFollowedChannelsWithCount ( account_id : number , medium_id : MediumEnum | null ,
42+ async getFollowedChannelsWithCount ( account_id : number , mediumType : QueryParamsMedium | null ,
4143 config ?: FindManyOptions < AccountFollowingChannel > ) : Promise < {
4244 count : number ; results : AccountFollowingChannel [ ] } > {
45+ const medium_ids = mediumType ? getMediumIdArrayFromType ( mediumType ) : null ;
46+
4347 const account = await this . accountService . get ( account_id ) ;
4448 if ( ! account ) {
4549 throw new Error ( "Account not found." ) ;
@@ -49,8 +53,8 @@ export class AccountFollowingChannelService extends BaseManyService<AccountFollo
4953 account_id : Equal ( account . id ) ,
5054 } ;
5155
52- if ( medium_id ) {
53- where [ 'channel' ] = { medium_id : Equal ( medium_id ) } ;
56+ if ( medium_ids ) {
57+ where [ 'channel' ] = { medium_id : In ( medium_ids ) } ;
5458 }
5559
5660 const finalConfig = {
0 commit comments