import { Db } from 'mongodb' ; import { computeHappinessByYear , computeTermAggregationByYear } from '../compute' ; import { useCache } from '../caching' ; import { RequestContext , SurveyConfig } from '../types' ; import { Filters } from '../filters' ; import { YearAggregations } from '../compute/generic' ; interface CategoryConfig { survey : SurveyConfig ; id : string ; filters ? : Filters ; } const computeOtherTools = async ( db , survey , id , filters ? ) => useCache ( computeTermAggregationByYear , db , [ survey , `tools_others.${ id }.others.normalized` , { filters } ] ) ; export default { CategoryOtherTools : { all_years : async ( { survey , id , filters } , args , { db } ) => computeOtherTools ( db , survey , id , filters ) , year : async ( { survey , id , filters } , { year } , { db } ) => { const allYears = await computeOtherTools ( db , survey , id , filters ) ; return allYears . find ( ( yearItem ) => yearItem . year === year ) ; } } , CategoryHappiness : { all_years : async ( { survey , id , filters } , args , { db } ) => useCache ( computeHappinessByYear , db , [ survey , id , filters ] ) , year : async ( { survey , id , filters } , { year } , { db } ) => { const allYears = await useCache ( computeHappinessByYear , db , [ survey , id , filters ] ) ; return allYears . find ( ( yearItem ) => yearItem . year === year ) ; } } } ;