import { IQuizFull , IReportFilter , IResult } from '../types' ; import { applyNumberOperator } from './applyNumberOperator' ; export function applyReportFilters ( allQuizzesMap , results , reportFilter ) { const { excluded_types , excluded_quizzes , excluded_difficulty , verdict , hints_used , time_taken , score , excluded_subjects , excluded_topics } = reportFilter ; const filteredResults = results . filter ( ( result ) => { const quiz = allQuizzesMap . get ( result . question . quiz ) ! ; return ( ! excluded_types . includes ( result . question . type ) && ! excluded_difficulty . includes ( result . question . difficulty ) && ! excluded_topics . includes ( quiz . topic ) && ! excluded_subjects . includes ( quiz . subject ) && ( verdict === 'any' || verdict . toString ( ) === result . verdict . toString ( ) ) && applyNumberOperator ( hints_used , result . hints_used ) && applyNumberOperator ( time_taken , result . time_taken ) && applyNumberOperator ( score , result . score . amount ) && ! excluded_quizzes . includes ( quiz . _id ) ) ; } ) ; return filteredResults ; }