import { Updoot } from "../entities/Updoot" ; import DataLoader from "dataloader" ; export const createUpdootLoader = ( ) => new DataLoader < { postId : number ; userId : number ; } , Updoot | null > ( async ( keys ) => { const updoots = await Updoot . findByIds ( keys as any ) ; const updootIdsToUpdoot = { } ; updoots . forEach ( ( updoot ) => { updootIdsToUpdoot [ `${ updoot . userId }|${ updoot . postId }` ] = updoot ; } ) ; return keys . map ( ( key ) => updootIdsToUpdoot [ `${ key . userId }|${ key . postId }` ] ) ; } ) ;