-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(rest-api): Added episodes to the shows
- Loading branch information
Showing
14 changed files
with
370 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"extends": "../../../.eslintrc.json", | ||
"ignorePatterns": ["!**/*"], | ||
"rules": {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# api-episodes | ||
|
||
This library was generated with [Nx](https://nx.dev). | ||
|
||
## Running unit tests | ||
|
||
Run `nx test api-episodes` to execute the unit tests via [Jest](https://jestjs.io). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
module.exports = { | ||
displayName: 'api-episodes', | ||
preset: '../../../jest.preset.js', | ||
globals: { | ||
'ts-jest': { | ||
tsConfig: '<rootDir>/tsconfig.spec.json', | ||
}, | ||
}, | ||
transform: { | ||
'^.+\\.[tj]sx?$': 'ts-jest', | ||
}, | ||
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'], | ||
coverageDirectory: '../../../coverage/libs/api/episodes', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { Model, Document } from 'mongoose' | ||
|
||
import { Episode } from './episode.object-type' | ||
|
||
export interface EpisodeDocument extends Episode, Document { | ||
|
||
_id: string | ||
|
||
} | ||
|
||
export type EpisodeModel = Model<EpisodeDocument> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { Field, ObjectType } from '@nestjs/graphql' | ||
|
||
import { Show } from '@pct-org/api/shows' | ||
import { Torrent, Images, Watched, DownloadInfo } from '@pct-org/api/shared' | ||
|
||
@ObjectType() | ||
export class Episode { | ||
|
||
@Field({ description: 'The id of the episode.' }) | ||
_id: string | ||
|
||
@Field({ description: 'The imdb id of the show.' }) | ||
showImdbId: string | ||
|
||
@Field({ description: 'The tmdb_id of the episode.' }) | ||
tmdbId: number | ||
|
||
@Field({ description: 'The episode number of the current episode.' }) | ||
number: number | ||
|
||
@Field({ description: 'Number of season the episode is in.' }) | ||
season: number | ||
|
||
@Field({ description: 'The title of the episode.' }) | ||
title: string | ||
|
||
@Field({ description: 'A brief summary of the episode.', nullable: true }) | ||
synopsis: string | ||
|
||
@Field({ description: 'The date on which the episode was first aired.' }) | ||
firstAired: number | ||
|
||
@Field(type => Watched, { description: 'Did the user watched this episode already.' }) | ||
watched: Watched | ||
|
||
@Field({ description: 'The type of the content.' }) | ||
type: string | ||
|
||
@Field(type => Images, { description: 'The still for the current episode.' }) | ||
images: Images | ||
|
||
@Field(type => [Torrent], { description: 'The episode\'s torrents.' }) | ||
torrents: Torrent[] | ||
|
||
@Field(type => [Torrent], { | ||
description: 'The episode\'s torrents that where found by search.', | ||
defaultValue: [] | ||
}) | ||
searchedTorrents: Torrent[] | ||
|
||
@Field(type => DownloadInfo, { description: 'Download info' }) | ||
download: DownloadInfo | ||
|
||
@Field({ description: 'The time at which the content was created.' }) | ||
createdAt: number | ||
|
||
@Field({ description: 'The time at which the content was last updated.' }) | ||
updatedAt: number | ||
|
||
@Field(tye => Show, { description: 'The show this episode belongs to.' }) | ||
show?: Show | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { Schema } from 'mongoose' | ||
|
||
import { torrentSchema, watchedSchema, imagesSchema, downloadInfoSchema } from '@pct-org/api/shared' | ||
|
||
export const episodeSchema = (new Schema( | ||
{ | ||
_id: { | ||
type: String, | ||
required: true | ||
}, | ||
showImdbId: String, | ||
tmdbId: Number, | ||
number: Number, | ||
season: Number, | ||
title: String, | ||
synopsis: String, | ||
firstAired: Number, | ||
type: String, | ||
...watchedSchema, | ||
...downloadInfoSchema, | ||
images: imagesSchema, | ||
torrents: { | ||
type: [torrentSchema] | ||
}, | ||
searchedTorrents: { | ||
type: [torrentSchema] | ||
}, | ||
createdAt: Number, | ||
updatedAt: Number | ||
}, | ||
{ | ||
collection: 'episodes' | ||
} | ||
)).index({ | ||
showImdbId: 1, | ||
season: 1, | ||
number: 1 | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
import { Injectable } from '@nestjs/common' | ||
import { InjectModel } from '@nestjs/mongoose' | ||
|
||
import { Episode } from './episode.object-type' | ||
import { EpisodeModel } from './episode.model' | ||
|
||
// import { BookmarksService } from '../bookmarks/bookmarks.service' | ||
|
||
@Injectable() | ||
export class EpisodesService { | ||
|
||
@InjectModel('Episodes') | ||
private readonly episodeModel: EpisodeModel | ||
|
||
/** | ||
* Returns all the episodes for the user that he did not watch | ||
* from shows he bookmarked | ||
*/ | ||
// async findMyEpisodes(bookmarksService: BookmarksService, lean = true): Promise<Episode[]> { | ||
// const shows = await bookmarksService.findAllShows({ | ||
// offset: 0, | ||
// limit: 1000, | ||
// query: null | ||
// }) | ||
// | ||
// const eightDaysAgo = new Date(new Date().getTime() - (8 * 24 * 60 * 60 * 1000)).getTime() | ||
// | ||
// return this.episodeModel.find( | ||
// { | ||
// showImdbId: { | ||
// $in: shows.map(show => show._id) | ||
// }, | ||
// firstAired: { | ||
// $gt: eightDaysAgo | ||
// }, | ||
// $where: 'this.torrents.length > 0' | ||
// }, | ||
// {}, | ||
// { | ||
// sort: { | ||
// firstAired: -1 | ||
// }, | ||
// lean | ||
// } | ||
// ) | ||
// } | ||
|
||
public async findOne(id: string, lean = true): Promise<Episode> { | ||
return this.episodeModel.findById( | ||
id, | ||
{}, | ||
{ | ||
lean | ||
} | ||
) | ||
} | ||
|
||
public async findAllForShow(imdbId: string, lean = true): Promise<Episode[]> { | ||
return this.episodeModel.find( | ||
{ | ||
showImdbId: imdbId, | ||
firstAired: { | ||
$gt: 0 | ||
} | ||
}, | ||
{}, | ||
{ | ||
// skip: showsArgs.offset, | ||
// limit: showsArgs.limit, | ||
sort: { | ||
season: 0, | ||
number: 0 // Sort on episode number | ||
}, | ||
lean | ||
} | ||
) | ||
} | ||
|
||
public async findAllForSeason(imdbId: string, seasonNumber: number, lean = true): Promise<Episode[]> { | ||
return this.episodeModel.find( | ||
{ | ||
showImdbId: imdbId, | ||
season: seasonNumber, | ||
firstAired: { | ||
$gt: 0 | ||
} | ||
}, | ||
{}, | ||
{ | ||
// skip: showsArgs.offset, | ||
// limit: showsArgs.limit, | ||
sort: { | ||
number: 0 // Sort on episode number | ||
}, | ||
lean | ||
} | ||
) | ||
} | ||
|
||
public async findAllWithIDS(ids: string[], lean = true): Promise<Episode[]> { | ||
return this.episodeModel.find( | ||
{ | ||
_id: { | ||
$in: ids | ||
} | ||
}, | ||
{}, | ||
{ | ||
// skip: showsArgs.offset, | ||
// limit: showsArgs.limit, | ||
sort: { | ||
number: 0 // Sort on episode number | ||
}, | ||
lean | ||
} | ||
) | ||
} | ||
|
||
public async findForCalendar(showImdbId: string, lean = true): Promise<Episode[]> { | ||
const fourteenDaysAgo = new Date(new Date().getTime() - (14 * 24 * 60 * 60 * 1000)).getTime() | ||
|
||
return this.episodeModel.find( | ||
{ | ||
showImdbId, | ||
firstAired: { | ||
$gt: fourteenDaysAgo | ||
} | ||
}, | ||
{}, | ||
{ | ||
sort: { | ||
number: 0 // Sort on episode number | ||
}, | ||
lean | ||
} | ||
) | ||
} | ||
|
||
public async updateOne(episode: Partial<Episode>): Promise<Episode> { | ||
return this.episodeModel.findByIdAndUpdate( | ||
episode._id, | ||
episode, | ||
{ | ||
new: true | ||
} | ||
) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { MongooseModule } from '@nestjs/mongoose' | ||
|
||
export { EpisodesService } from './episodes.service' | ||
|
||
import { episodeSchema } from './episode.schema' | ||
|
||
export const EPISODES_MONGOOSE_FEATURE = MongooseModule.forFeature([{ name: 'Episodes', schema: episodeSchema }]) |
Oops, something went wrong.