import { IProduct } from '@/entities/Product' ; import CartRepository from '@/repositories/CartRepository' ; import ProductRepository from '@/repositories/ProductRepository' ; export interface IPresenter { productRepository : ProductRepository ; cartRepository : CartRepository ; } export interface IPresenterState { item : IProduct ; isInCart : boolean ; } const isInCart = ( productRepository , cartRepository ) => { const item = productRepository . getItem ( ) ; const cartItems = cartRepository . getItems ( ) ; if ( ! item || cartItems . length < 1 ) return false ; const targetItem = cartItems . find ( cartItem => cartItem . id === item . id ) ; return targetItem ? true : false ; } ; export default ( { productRepository , cartRepository } ) : IPresenterState => { return { item : productRepository . getItem ( ) , isInCart : isInCart ( productRepository , cartRepository ) } ; } ;