Skip to content

Commit be47415

Browse files
committed
refactor: update item relations to include channel information for improved data retrieval
1 parent 4836b3d commit be47415

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

src/controllers/item.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import { Request, Response } from 'express';
22
import Joi from 'joi';
33
import { itemGetOneRelations, itemGetManyRelations, ItemChapterService, ItemService, Item,
44
StatsAggregatedItem, FindManyOptions, subItemGetManyRelations,
5-
StatsAggregatedItemService, ChannelService } from 'podverse-orm';
5+
StatsAggregatedItemService, ChannelService,
6+
itemGetManyRelationsWithChannel} from 'podverse-orm';
67
import { parseChapters } from 'podverse-parser';
78
import { handleReturnDataOrNotFound } from '@api/controllers/helpers/data';
89
import { handleGenericErrorResponse } from '@api/controllers/helpers/error';
@@ -13,6 +14,7 @@ import { ApiListResponse, CATEGORY_MAPPING_KEYS, CategoryMappingKeys, emptyApiLi
1314
QUERY_PARAMS_DIRECTION_VALUES,
1415
QUERY_PARAMS_MEDIUMS,
1516
QUERY_PARAMS_STATS_RANGE_VALUES,
17+
QueryParamsDirection,
1618
QueryParamsMedium, QueryParamsStatsRange } from 'podverse-helpers';
1719
import { getStatsOrder } from '@api/lib/stats';
1820
import { ensureAuthenticated } from '@api/lib/auth';
@@ -115,7 +117,7 @@ export class ItemController {
115117
order: { pub_date: 'DESC' },
116118
skip: offset,
117119
take: limit,
118-
relations: itemGetManyRelations
120+
relations: itemGetManyRelationsWithChannel
119121
};
120122
const items = await ItemController.itemService.getMany(
121123
recentConfig,
@@ -152,7 +154,7 @@ export class ItemController {
152154
order: { [order]: 'DESC' },
153155
skip: offset,
154156
take: limit,
155-
relations: subItemGetManyRelations
157+
relations: itemGetManyRelationsWithChannel
156158
};
157159

158160
const statsResults = await ItemController.statsAggregatedItemService.getMany(
@@ -186,13 +188,11 @@ export class ItemController {
186188
const medium_id = getMediumFromQueryParam(selectedMedium);
187189
const category_id = getCategoryEnumValue(category);
188190

189-
const itemWhere = { channel: { channel_categories: { category_id } } };
190191
const recentConfig: FindManyOptions<Item> = {
191192
order: { pub_date: 'DESC' },
192193
skip: offset,
193194
take: limit,
194-
relations: itemGetManyRelations,
195-
where: itemWhere
195+
relations: itemGetManyRelationsWithChannel
196196
};
197197
const recentResults = await ItemController.itemService.getMany(
198198
recentConfig,
@@ -231,7 +231,7 @@ export class ItemController {
231231
order: { [order]: 'DESC' },
232232
skip: offset,
233233
take: limit,
234-
relations: subItemGetManyRelations
234+
relations: itemGetManyRelationsWithChannel
235235
};
236236

237237
const statsResults = await ItemController.statsAggregatedItemService.getMany(
@@ -275,7 +275,7 @@ export class ItemController {
275275
order: { pub_date: 'DESC' },
276276
skip: offset,
277277
take: limit,
278-
relations: itemGetManyRelations,
278+
relations: itemGetManyRelationsWithChannel,
279279
};
280280
const items = await ItemController.itemService.getManyByChannels(channel_ids, config);
281281

@@ -315,7 +315,7 @@ export class ItemController {
315315
order: { [order]: 'DESC' },
316316
skip: offset,
317317
take: limit,
318-
relations: subItemGetManyRelations
318+
relations: itemGetManyRelationsWithChannel
319319
};
320320
const statsResults = await ItemController.statsAggregatedItemService.getManyByChannels(
321321
config,

0 commit comments

Comments
 (0)