Skip to content

Commit d7b0e91

Browse files
committed
feat: update ItemService and StatsAggregatedItemService to utilize live item status enum for filtering
1 parent ec9748e commit d7b0e91

File tree

2 files changed

+30
-9
lines changed

2 files changed

+30
-9
lines changed

src/services/item/item.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { ItemValueTimeSplitRemoteItemService } from './itemValueTimeSplitRemoteI
2424
import { ItemValueTimeSplit } from '@orm/entities/item/itemValueTimeSplit';
2525
import { ItemFlagStatusService } from './itemFlagStatus';
2626
import { ItemFlagStatusStatusEnum } from '@orm/entities/item/itemFlagStatus';
27+
import { getLiveItemStatusEnumValue } from '@orm/entities/liveItem/liveItemStatus';
2728

2829
type ItemDto = {
2930
title: string | null
@@ -220,8 +221,10 @@ export class ItemService {
220221
medium_id: MediumEnum | null,
221222
category_id: number | null,
222223
itemType: 'normal' | 'live-item',
223-
liveItemType: LiveItemStatusEnum | null
224+
liveItemType: 'pending' | 'live' | 'ended' | null
224225
): Promise<Item[]> {
226+
const live_item_status_id = getLiveItemStatusEnumValue(liveItemType);
227+
225228
return this.repositoryRead.find({
226229
...config,
227230
where: {
@@ -237,7 +240,7 @@ export class ItemService {
237240
},
238241
live_item: {
239242
id: itemType === 'live-item' ? Not(IsNull()) : IsNull(),
240-
...(liveItemType ? { live_item_status_id: Equal(liveItemType) } : {})
243+
...(live_item_status_id ? { live_item_status_id: Equal(live_item_status_id) } : {})
241244
}
242245
}
243246
});
@@ -392,12 +395,20 @@ export class ItemService {
392395
});
393396
}
394397

395-
async getManyByChannels(channels: Channel[], options?: FindManyOptions<Item>): Promise<Item[]> {
398+
async getManyByChannels(
399+
channels: Channel[],
400+
itemType: 'normal' | 'live-item',
401+
liveItemType: 'pending' | 'live' | 'ended' | null,
402+
options?: FindManyOptions<Item>
403+
): Promise<Item[]> {
404+
const live_item_status_id = getLiveItemStatusEnumValue(liveItemType);
405+
396406
return this.repositoryRead.find({
397407
where: {
398408
channel: In(channels),
399409
live_item: {
400-
id: IsNull()
410+
id: itemType === 'live-item' ? Not(IsNull()) : IsNull(),
411+
...(live_item_status_id ? { live_item_status_id: Equal(live_item_status_id) } : {})
401412
},
402413
item_flag_status: {
403414
id: ItemFlagStatusStatusEnum.Active

src/services/stats/statsAggregatedItem.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ import { MediumEnum } from 'podverse-helpers';
22
import { StatsAggregatedItem } from '@orm/entities/stats/statsAggregatedItem';
33
import { StatsTrackEventItemService } from './statsTrackEventItem';
44
import { BaseStatsAggregatedService, UpdateHistoricalOptions } from './baseStatsAggregated';
5-
import { FindManyOptions, IsNull, Not } from 'typeorm';
5+
import { Equal, FindManyOptions, IsNull, Not } from 'typeorm';
66
import { getActiveFeedWhere } from '@orm/lib/feedFlagHelpers';
7+
import { getLiveItemStatusEnumValue } from '@orm/index';
78

89
export class StatsAggregatedItemService extends BaseStatsAggregatedService<StatsAggregatedItem, number> {
910
private statsTrackEventItemService: StatsTrackEventItemService;
@@ -21,8 +22,11 @@ export class StatsAggregatedItemService extends BaseStatsAggregatedService<Stats
2122
config: FindManyOptions<StatsAggregatedItem>,
2223
medium_id: MediumEnum | null,
2324
category_id: number | null,
24-
itemType: 'normal' | 'live-item'
25+
itemType: 'normal' | 'live-item',
26+
liveItemType: 'pending' | 'live' | 'ended' | null
2527
): Promise<StatsAggregatedItem[]> {
28+
const live_item_status_id = getLiveItemStatusEnumValue(liveItemType);
29+
2630
return this.repositoryRead.find({
2731
where: {
2832
item: {
@@ -32,7 +36,9 @@ export class StatsAggregatedItemService extends BaseStatsAggregatedService<Stats
3236
category_id
3337
}),
3438
live_item: {
35-
id: itemType === 'live-item' ? Not(IsNull()) : IsNull()
39+
id: itemType === 'live-item' ? Not(IsNull()) : IsNull(),
40+
...(live_item_status_id ? { live_item_status_id: Equal(live_item_status_id) } : {})
41+
3642
}
3743
}
3844
},
@@ -43,8 +49,11 @@ export class StatsAggregatedItemService extends BaseStatsAggregatedService<Stats
4349
async getManyByChannelsAndCount(
4450
config: FindManyOptions<StatsAggregatedItem>,
4551
channel_ids: number[],
46-
itemType: 'normal' | 'live-item'
52+
itemType: 'normal' | 'live-item',
53+
liveItemType: 'pending' | 'live' | 'ended' | null
4754
): Promise<[StatsAggregatedItem[], number]> {
55+
const live_item_status_id = getLiveItemStatusEnumValue(liveItemType);
56+
4857
return this.repositoryRead.findAndCount({
4958
where: {
5059
item: {
@@ -54,7 +63,8 @@ export class StatsAggregatedItemService extends BaseStatsAggregatedService<Stats
5463
category_id: null
5564
}),
5665
live_item: {
57-
id: itemType === 'live-item' ? Not(IsNull()) : IsNull()
66+
id: itemType === 'live-item' ? Not(IsNull()) : IsNull(),
67+
...(live_item_status_id ? { live_item_status_id: Equal(live_item_status_id) } : {})
5868
}
5969
}
6070
},

0 commit comments

Comments
 (0)