|
1 |
| -import { Controller, Get } from '@nestjs/common' |
| 1 | +import { Controller, Get, Inject, Param, Query } from '@nestjs/common' |
| 2 | +import { ShowsArgs, ShowsService } from '@pct-org/api/shows' |
2 | 3 |
|
3 |
| -@Controller('/shows') |
| 4 | +import { Show, ShowClean } from '../../shared/show.interface' |
| 5 | + |
| 6 | +@Controller() |
4 | 7 | export class ShowsController {
|
5 | 8 |
|
6 |
| - @Get('') |
7 |
| - public watch() { |
8 |
| - return 'ok' |
| 9 | + @Inject() |
| 10 | + private readonly showsService: ShowsService |
| 11 | + |
| 12 | + @Get('/shows') |
| 13 | + public async getShows(): Promise<string[]> { |
| 14 | + const totalShows = await this.showsService.count() |
| 15 | + |
| 16 | + return Array(Math.round(totalShows / 50)).fill(null).map((empty, index) => ( |
| 17 | + `/shows/${index + 1}` |
| 18 | + )) |
9 | 19 | }
|
10 | 20 |
|
| 21 | + @Get('/shows/:page') |
| 22 | + public async getShowsPage( |
| 23 | + @Param('page') page: number, |
| 24 | + @Query() args: ShowsArgs |
| 25 | + ): Promise<ShowClean[]> { |
| 26 | + args.offset = (page - 1) * args.limit |
| 27 | + args.query = args.keywords |
| 28 | + |
| 29 | + const shows = await this.showsService.findAll(args) |
| 30 | + |
| 31 | + return shows.map((show) => ({ |
| 32 | + _id: show._id, |
| 33 | + imdb_id: show._id, |
| 34 | + tvdb_id: `${show.tvdbId}`, |
| 35 | + title: show.title, |
| 36 | + year: `${(new Date(show.released)).getFullYear()}`, |
| 37 | + slug: show.slug, |
| 38 | + num_seasons: show.numSeasons, |
| 39 | + images: { |
| 40 | + poster: show.images.poster.medium, |
| 41 | + fanart: show.images.backdrop.medium, |
| 42 | + banner: show.images.poster.medium |
| 43 | + }, |
| 44 | + rating: { |
| 45 | + percentage: show.rating.percentage, |
| 46 | + watching: show.rating.watching, |
| 47 | + votes: show.rating.votes, |
| 48 | + loved: 100, |
| 49 | + hated: 100 |
| 50 | + } |
| 51 | + })) |
| 52 | + } |
| 53 | + |
| 54 | + @Get('/show/:imdbId') |
| 55 | + public async getShow( |
| 56 | + @Param('imdbId') imdbId: string |
| 57 | + ): Promise<Show> { |
| 58 | + const show = await this.showsService.findOne(imdbId) |
| 59 | + |
| 60 | + return ({ |
| 61 | + _id: show._id, |
| 62 | + imdb_id: show._id, |
| 63 | + tvdb_id: `${show.tvdbId}`, |
| 64 | + title: show.title, |
| 65 | + year: `${(new Date(show.released)).getFullYear()}`, |
| 66 | + slug: show.slug, |
| 67 | + runtime: `${(show.runtime.hours * 60) + show.runtime.minutes}`, |
| 68 | + synopsis: show.synopsis, |
| 69 | + num_seasons: show.numSeasons, |
| 70 | + country: show.airInfo.country, |
| 71 | + network: show.airInfo.network, |
| 72 | + air_day: show.airInfo.day, |
| 73 | + air_time: show.airInfo.time, |
| 74 | + status: show.airInfo.status, |
| 75 | + genres: show.genres, |
| 76 | + images: { |
| 77 | + poster: show.images.poster.medium, |
| 78 | + fanart: show.images.backdrop.medium, |
| 79 | + banner: show.images.poster.medium |
| 80 | + }, |
| 81 | + rating: { |
| 82 | + percentage: show.rating.percentage, |
| 83 | + watching: show.rating.watching, |
| 84 | + votes: show.rating.votes, |
| 85 | + loved: 100, |
| 86 | + hated: 100 |
| 87 | + }, |
| 88 | + last_updated: show.updatedAt, |
| 89 | + episodes: [] |
| 90 | + }) |
| 91 | + } |
11 | 92 | }
|
0 commit comments