@prisma/client#MediaType TypeScript Examples

The following examples show how to use @prisma/client#MediaType. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: modify.ts    From frames with Mozilla Public License 2.0 6 votes vote down vote up
/**
     * @desc get new contents to add to the database
     * @param userId - the user requesting the contents
     */
    public async getNewContent(userId: string) {
        if (await this.userIsAdmin(userId)) {
            const dbase = await this.prisma.media.findMany();
            const trending = await this.tmdb?.getTrending(4) || {movies: [], shows: []};
            const popular = await this.tmdb?.getPopular(4) || {movies: [], shows: []};
            const topRated = await this.tmdb?.getTopRated(4) || {movies: [], shows: []};

            const moviesToDownload = this.uniqueId(trending.movies.concat(popular.movies, topRated.movies), 'id');
            const showsToDownload = this.uniqueId(trending.shows.concat(popular.shows, topRated.shows), 'id');

            const sortedMovies = this.sortArray(moviesToDownload, 'popularity', 'desc');
            const sortedShows = this.sortArray(showsToDownload, 'popularity', 'desc');

            const missingMovies = sortedMovies.filter(movie => !dbase.find(e => e.tmdbId === movie.id && e.type === MediaType.MOVIE));
            const missingShows = sortedShows.filter(show => !dbase.find(e => e.tmdbId === show.id && e.type === MediaType.SHOW));

            const promises: any[] = missingMovies.map(e => this.deluge.addMagnet(e.id, MediaType.MOVIE)).concat(missingShows.map(e => this.deluge.addMagnet(e.id, MediaType.SHOW)));
            await Promise.all(promises);
            await this.deluge.parseFeed();
        }
    }