server/services/SuggestionService.js
// better to hardcode so much business logic in the data models
better to hardcode so much business logic in the data models
better to hardcode so much business logic in the data models
async findMoviesMatchingUserFilters(genreFilters, ratingFilter, isDaily) {
        const genreIds = genreFilters.map((filter)=> filter.value);
        let date = isDaily ? moment().utc() : moment().utc().subtract(7,'days');
        date = date.format('YYYY-MM-DD');
        return db(Movie.TABLE)
                .distinct()
                .select(`${Movie.TABLE}.*`)
                .join(`${MovieGenre.TABLE}`, `${Movie.TABLE}.id`, '=', `${MovieGenre.TABLE}.movie_id`)
                .join(`${Genre.TABLE}`, `${MovieGenre.TABLE}.genre_id`, '=', `${Genre.TABLE}.id`)
                .whereIn(`${Genre.TABLE}.tmdb_id`, genreIds)
                .andWhere(`${Movie.TABLE}.rating`,'>=',ratingFilter.value)
                .andWhere(`${Movie.TABLE}.release_date`,'>=', date)
                .orderBy(`${Movie.TABLE}.rating`, 'desc');
    }
async findMoviesMatchingUserFilters ( genreFilters , ratingFilter , isDaily ) { const genreIds = genreFilters . map ( ( filter ) => filter . value ) ; let date = isDaily ? moment ( ) . utc ( ) : moment ( ) . utc ( ) . subtract ( 7 , 'days' ) ; date = date . format ( 'YYYY-MM-DD' ) ; return db ( Movie . TABLE ) . distinct ( ) . select ( ` ${ Movie . TABLE } ` ) . join ( ` ${ MovieGenre . TABLE } ` , ` ${ Movie . TABLE } ` , '=' , ` ${ MovieGenre . TABLE } ` ) . join ( ` ${ Genre . TABLE } ` , ` ${ MovieGenre . TABLE } ` , '=' , ` ${ Genre . TABLE } ` ) . whereIn ( ` ${ Genre . TABLE } ` , genreIds ) . andWhere ( ` ${ Movie . TABLE } ` , '>=' , ratingFilter . value ) . andWhere ( ` ${ Movie . TABLE } ` , '>=' , date ) . orderBy ( ` ${ Movie . TABLE } ` , 'desc' ) ; }
better to hardcode so much business logic in the data models
better to hardcode so much business logic in the data models