Skip to content

Commit ca4deaf

Browse files
committed
feat: refactor services to utilize new medium type handling for improved filtering
1 parent d7b0e91 commit ca4deaf

File tree

11 files changed

+63
-45
lines changed

11 files changed

+63
-45
lines changed

src/lib/feedFlagHelpers.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
1-
import { MediumEnum } from "podverse-helpers";
1+
import { getMediumIdArrayFromType, QueryParamsMedium } from "podverse-helpers";
22
import { Equal, In } from "typeorm";
33
import { FeedFlagStatusStatusEnum } from "@orm/entities/feed/feedFlagStatus";
44

55
type ActiveFeedWhere = {
66
channel_ids: number[] | null;
7-
medium_id: MediumEnum | null;
7+
mediumType: QueryParamsMedium | null;
88
category_id: number | null;
99
}
1010

11-
export function getActiveFeedWhere({ channel_ids, medium_id, category_id }: ActiveFeedWhere) {
11+
export function getActiveFeedWhere({ channel_ids, mediumType, category_id }: ActiveFeedWhere) {
12+
const medium_ids = getMediumIdArrayFromType(mediumType);
1213
return {
1314
channel: {
1415
...(channel_ids?.length ? { id: In(channel_ids) } : {}),
15-
...(medium_id ? { medium_id: Equal(medium_id) } : {}),
16+
...(medium_ids ? { medium_id: In(medium_ids) } : {}),
1617
...(category_id ? { channel_categories: { category_id: Equal(category_id) } } : {}),
1718
feed: {
1819
feed_flag_status: In([FeedFlagStatusStatusEnum.Active, FeedFlagStatusStatusEnum.AlwaysParse])

src/services/account/accountFollowingChannel.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
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';
33
import { AccountFollowingChannel } from '@orm/entities/account/accountFollowingChannel';
44
import { BaseManyService } from '@orm/services/base/baseManyService';
55
import { 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 = {

src/services/account/accountFollowingPlaylist.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { EntityManager, FindManyOptions, Not } from 'typeorm';
1+
import { EntityManager, Equal, FindManyOptions, Not } from 'typeorm';
22
import { AccountFollowingPlaylist } from '@orm/entities/account/accountFollowingPlaylist';
33
import { BaseManyService } from '@orm/services/base/baseManyService';
44
import { AccountService } from '@orm/services/account/account';
55
import { PlaylistService } from '../playlist/playlist';
6-
import { SharableStatusEnum } from 'podverse-helpers';
6+
import { getQueueMediumIdFromType, QueryParamsQueueMedium, SharableStatusEnum } from 'podverse-helpers';
77

88
export class AccountFollowingPlaylistService extends BaseManyService<AccountFollowingPlaylist, 'account'> {
99
private accountService: AccountService;
@@ -26,15 +26,17 @@ export class AccountFollowingPlaylistService extends BaseManyService<AccountFoll
2626

2727
async getFollowedPlaylistsPrivateWithCount(
2828
account_id: number,
29-
medium_id: number | null,
29+
queueMediumType: QueryParamsQueueMedium | null,
3030
config?: FindManyOptions<AccountFollowingPlaylist>):
3131
Promise<[AccountFollowingPlaylist[], number]> {
32+
const medium_id = getQueueMediumIdFromType(queueMediumType);
33+
3234
return this.repositoryRead.findAndCount({
3335
...config,
3436
where: {
3537
...config?.where,
3638
account_id,
37-
...(medium_id ? { playlist: { medium_id } } : {})
39+
...(medium_id ? { playlist: { medium_id: Equal(medium_id) } } : {})
3840
},
3941
relations: [
4042
'playlist',

src/services/channel/channel.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { MediumEnum } from 'podverse-helpers';
1+
import { getMediumIdArrayFromType, MediumEnum, QueryParamsMedium } from 'podverse-helpers';
22
import { FindManyOptions, FindOptionsRelations, FindOptionsWhere, In, Repository, Equal } from 'typeorm';
33
import { Channel } from '@orm/entities/channel/channel';
44
import { Feed } from '@orm/entities/feed/feed';
@@ -251,15 +251,17 @@ export class ChannelService {
251251

252252
async getMany(
253253
config: FindManyOptions<Channel>,
254-
medium_id: MediumEnum | null,
254+
mediumType: QueryParamsMedium,
255255
category_id: number | null
256256
): Promise<Channel[]> {
257+
const medium_ids = mediumType ? getMediumIdArrayFromType(mediumType) : null;
258+
257259
return this.repositoryRead.find({
258260
where: {
259261
feed: {
260262
feed_flag_status: In([FeedFlagStatusStatusEnum.Active, FeedFlagStatusStatusEnum.AlwaysParse])
261263
},
262-
...(medium_id ? { medium_id: Equal(medium_id) } : {}),
264+
...(medium_ids ? { medium_id: In(medium_ids) } : {}),
263265
...(category_id ? { channel_categories: { category_id: Equal(category_id) } } : {})
264266
},
265267
...config

src/services/clip.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Clip } from '@orm/entities/clip';
33
import { BaseManyService } from '@orm/services/base/baseManyService';
44
import { AccountService } from '@orm/services/account/account';
55
import { ItemService } from './item/item';
6-
import { MediumEnum, SharableStatusEnum } from 'podverse-helpers';
6+
import { getMediumIdArrayFromType, QueryParamsMedium, SharableStatusEnum } from 'podverse-helpers';
77
import { FeedFlagStatusStatusEnum } from '../';
88

99
export type ClipDto = {
@@ -106,10 +106,11 @@ export class ClipService extends BaseManyService<Clip, 'account'> {
106106
}
107107

108108
async getManyPublic(
109-
medium_id: MediumEnum | null,
109+
mediumType: QueryParamsMedium | null,
110110
category_id: number | null,
111111
config: FindManyOptions<Clip>
112112
): Promise<Clip[]> {
113+
const medium_ids = mediumType ? getMediumIdArrayFromType(mediumType) : null;
113114
return this.repositoryRead.find({
114115
where: {
115116
sharable_status_id: SharableStatusEnum.Public,
@@ -118,7 +119,7 @@ export class ClipService extends BaseManyService<Clip, 'account'> {
118119
feed: {
119120
feed_flag_status: In([FeedFlagStatusStatusEnum.Active, FeedFlagStatusStatusEnum.AlwaysParse])
120121
},
121-
...(medium_id ? { medium_id: Equal(medium_id) } : {}),
122+
...(medium_ids ? { medium_id: In(medium_ids) } : {}),
122123
...(category_id ? { channel_categories: { category_id: Equal(category_id) } } : {})
123124
}
124125
},

src/services/item/item.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { LiveItemStatusEnum, MediumEnum } from 'podverse-helpers';
1+
import { getMediumIdArrayFromType, QueryParamsMedium } from 'podverse-helpers';
22
import { FindManyOptions, FindOptionsRelations, FindOptionsWhere,
33
In, IsNull, Not, Repository, MoreThan, LessThan,
44
Equal} from 'typeorm';
@@ -218,11 +218,12 @@ export class ItemService {
218218

219219
async getMany(
220220
config: FindManyOptions<Item>,
221-
medium_id: MediumEnum | null,
221+
mediumType: QueryParamsMedium | null,
222222
category_id: number | null,
223223
itemType: 'normal' | 'live-item',
224224
liveItemType: 'pending' | 'live' | 'ended' | null
225225
): Promise<Item[]> {
226+
const medium_ids = mediumType ? getMediumIdArrayFromType(mediumType) : null;
226227
const live_item_status_id = getLiveItemStatusEnumValue(liveItemType);
227228

228229
return this.repositoryRead.find({
@@ -232,7 +233,7 @@ export class ItemService {
232233
feed: {
233234
feed_flag_status: In([1, 2])
234235
},
235-
...(medium_id ? { medium_id: Equal(medium_id) } : {}),
236+
...(medium_ids ? { medium_id: In(medium_ids) } : {}),
236237
...(category_id ? { channel_categories: { category_id: Equal(category_id) } } : {})
237238
},
238239
item_flag_status: {

src/services/playlist/playlist.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { MediumEnum, SharableStatusEnum } from 'podverse-helpers';
1+
import { getQueueMediumIdFromType, MediumEnum, QueryParamsQueueMedium,
2+
SharableStatusEnum } from 'podverse-helpers';
23
import { EntityManager, Equal, FindManyOptions, FindOneOptions, Not } from 'typeorm';
34
import { Playlist } from '@orm/entities/playlist/playlist';
45
import { BaseManyService } from '@orm/services/base/baseManyService';
@@ -88,9 +89,11 @@ export class PlaylistService extends BaseManyService<Playlist, 'account'> {
8889

8990
async getManyPrivate(
9091
account_id: number,
91-
medium_id: MediumEnum | null,
92+
queueMediumType: QueryParamsQueueMedium | null,
9293
options?: FindManyOptions<Playlist>
9394
): Promise<[Playlist[], number] > {
95+
const medium_id = getQueueMediumIdFromType(queueMediumType);
96+
9497
return this.repositoryRead.findAndCount({
9598
...options,
9699
where: {

src/services/stats/statsAggregatedChannel.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { MediumEnum } from 'podverse-helpers';
1+
import { MediumEnum, QueryParamsMedium } from 'podverse-helpers';
22
import { FindManyOptions } from 'typeorm';
33
import { StatsAggregatedChannel } from '@orm/entities/stats/statsAggregatedChannel';
44
import { StatsTrackEventChannelService } from './statsTrackEventChannel';
@@ -23,12 +23,12 @@ export class StatsAggregatedChannelService extends BaseStatsAggregatedService<St
2323

2424
async getMany(
2525
config: FindManyOptions<StatsAggregatedChannel>,
26-
medium_id: MediumEnum | null,
26+
mediumType: QueryParamsMedium | null,
2727
category_id: number | null
2828
): Promise<StatsAggregatedChannel[]> {
2929
const feedWhere = getActiveFeedWhere({
3030
channel_ids: null,
31-
medium_id,
31+
mediumType,
3232
category_id
3333
});
3434
return this.repositoryRead.find({
@@ -43,7 +43,7 @@ export class StatsAggregatedChannelService extends BaseStatsAggregatedService<St
4343
): Promise<[StatsAggregatedChannel[], number]> {
4444
const feedWhere = getActiveFeedWhere({
4545
channel_ids,
46-
medium_id: null,
46+
mediumType: null,
4747
category_id: null
4848
});
4949
return this.repositoryRead.findAndCount({

src/services/stats/statsAggregatedClip.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { MediumEnum, SharableStatusEnum } from 'podverse-helpers';
1+
import { QueryParamsMedium, SharableStatusEnum } from 'podverse-helpers';
22
import { StatsAggregatedClip } from '@orm/entities/stats/statsAggregatedClip';
33
import { StatsTrackEventClipService } from './statsTrackEventClip';
44
import { BaseStatsAggregatedService, UpdateHistoricalOptions } from './baseStatsAggregated';
@@ -19,7 +19,7 @@ export class StatsAggregatedClipService extends BaseStatsAggregatedService<Stats
1919

2020
async getManyPublic(
2121
config: FindManyOptions<StatsAggregatedClip>,
22-
medium_id: MediumEnum | null,
22+
mediumType: QueryParamsMedium | null,
2323
category_id: number | null
2424
): Promise<StatsAggregatedClip[]> {
2525
return this.repositoryRead.find({
@@ -29,7 +29,7 @@ export class StatsAggregatedClipService extends BaseStatsAggregatedService<Stats
2929
item: {
3030
...getActiveFeedWhere({
3131
channel_ids: null,
32-
medium_id,
32+
mediumType,
3333
category_id
3434
})
3535
}
@@ -41,7 +41,7 @@ export class StatsAggregatedClipService extends BaseStatsAggregatedService<Stats
4141

4242
async getManyAndCountPublic(
4343
config: FindManyOptions<StatsAggregatedClip>,
44-
medium_id: MediumEnum | null,
44+
mediumType: QueryParamsMedium | null,
4545
category_id: number | null,
4646
): Promise<[StatsAggregatedClip[], number]> {
4747
return this.repositoryRead.findAndCount({
@@ -51,7 +51,7 @@ export class StatsAggregatedClipService extends BaseStatsAggregatedService<Stats
5151
item: {
5252
...getActiveFeedWhere({
5353
channel_ids: null,
54-
medium_id,
54+
mediumType,
5555
category_id
5656
})
5757
}
@@ -72,7 +72,7 @@ export class StatsAggregatedClipService extends BaseStatsAggregatedService<Stats
7272
item: {
7373
...getActiveFeedWhere({
7474
channel_ids,
75-
medium_id: null,
75+
mediumType: null,
7676
category_id: null
7777
})
7878
}
@@ -94,7 +94,7 @@ export class StatsAggregatedClipService extends BaseStatsAggregatedService<Stats
9494
id: item_id,
9595
...getActiveFeedWhere({
9696
channel_ids: null,
97-
medium_id: null,
97+
mediumType: null,
9898
category_id: null
9999
})
100100
}

src/services/stats/statsAggregatedItem.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { MediumEnum } from 'podverse-helpers';
1+
import { QueryParamsMedium } from 'podverse-helpers';
22
import { StatsAggregatedItem } from '@orm/entities/stats/statsAggregatedItem';
33
import { StatsTrackEventItemService } from './statsTrackEventItem';
44
import { BaseStatsAggregatedService, UpdateHistoricalOptions } from './baseStatsAggregated';
@@ -20,7 +20,7 @@ export class StatsAggregatedItemService extends BaseStatsAggregatedService<Stats
2020

2121
async getMany(
2222
config: FindManyOptions<StatsAggregatedItem>,
23-
medium_id: MediumEnum | null,
23+
mediumType: QueryParamsMedium | null,
2424
category_id: number | null,
2525
itemType: 'normal' | 'live-item',
2626
liveItemType: 'pending' | 'live' | 'ended' | null
@@ -32,7 +32,7 @@ export class StatsAggregatedItemService extends BaseStatsAggregatedService<Stats
3232
item: {
3333
...getActiveFeedWhere({
3434
channel_ids: null,
35-
medium_id,
35+
mediumType,
3636
category_id
3737
}),
3838
live_item: {
@@ -59,7 +59,7 @@ export class StatsAggregatedItemService extends BaseStatsAggregatedService<Stats
5959
item: {
6060
...getActiveFeedWhere({
6161
channel_ids,
62-
medium_id: null,
62+
mediumType: null,
6363
category_id: null
6464
}),
6565
live_item: {

0 commit comments

Comments
 (0)