|
1 | 1 | import { Args, Parent, Query, ResolveField, Resolver } from '@nestjs/graphql'
|
2 | 2 | import { Show, Season } from '@pct-org/mongo-models'
|
3 |
| -import * as Trakt from 'trakt.tv' |
4 | 3 |
|
5 | 4 | import { ShowArgs } from './dto/show.args'
|
6 | 5 | import { ShowsArgs } from './dto/shows.args'
|
7 | 6 | import { ShowsService } from './shows.service'
|
8 | 7 |
|
9 |
| -import { ConfigService } from '../shared/config/config.service' |
10 | 8 | import { SeasonsService } from '../seasons/seasons.service'
|
11 | 9 | import { DownloadsService } from '../downloads/downloads.service'
|
| 10 | +import { TraktService } from '../shared/trakt/trakt.service' |
12 | 11 |
|
13 | 12 | @Resolver(of => Show)
|
14 | 13 | export class ShowsResolver {
|
15 | 14 |
|
16 |
| - private readonly trakt |
17 |
| - |
18 | 15 | constructor(
|
19 | 16 | private readonly showsService: ShowsService,
|
20 | 17 | private readonly seasonsService: SeasonsService,
|
21 | 18 | private readonly downloadsService: DownloadsService,
|
22 |
| - private readonly configService: ConfigService |
| 19 | + private readonly traktService: TraktService |
23 | 20 | ) {
|
24 |
| - this.trakt = new Trakt({ |
25 |
| - // eslint-disable-next-line @typescript-eslint/camelcase |
26 |
| - client_id: this.configService.get(ConfigService.TRAKT_KEY) |
27 |
| - }) |
28 | 21 | }
|
29 | 22 |
|
30 | 23 | /**
|
@@ -60,26 +53,7 @@ export class ShowsResolver {
|
60 | 53 | */
|
61 | 54 | @Query(returns => [Show], { description: 'Get most watched shows.' })
|
62 | 55 | async mostWatchedShows(): Promise<Show[]> {
|
63 |
| - let showIds = [] |
64 |
| - |
65 |
| - try { |
66 |
| - const traktMostWatched = await this.trakt.shows.watched({ |
67 |
| - period: 'weekly' |
68 |
| - }) |
69 |
| - |
70 |
| - showIds = traktMostWatched.map((item) => item.show.ids.imdb) |
71 |
| - } catch (e) { |
72 |
| - } |
73 |
| - |
74 |
| - if (showIds.length === 0) { |
75 |
| - return [] |
76 |
| - } |
77 |
| - |
78 |
| - const shows = await this.showsService.findAllWithIDS(showIds) |
79 |
| - |
80 |
| - return shows.sort((showA, showB) => |
81 |
| - showIds.indexOf(showA._id) - showIds.indexOf(showB._id), |
82 |
| - ) |
| 56 | + return this.traktService.mostWatchedWeeklyShows() |
83 | 57 | }
|
84 | 58 |
|
85 | 59 | /**
|
|
0 commit comments