import { EntityRepository , Repository } from 'typeorm' ; import ProductEntity from '@/entity/product' ; import UserEntity from '@/entity/user' ; import LikeEntity from '@/entity/like' ; @ EntityRepository ( LikeEntity ) class LikeRepository extends Repository < LikeEntity > { async findByIdxOfProductAndUser ( userIdx , productIdx ) { const like = await this . findOne ( { where : { user : { idx : userIdx } , product : { idx : productIdx } , } , } ) ; return like ; } async getCntByProductIdx ( productIdx ) { const likeCnt = await this . count ( { where : { product : { idx : productIdx } , } , } ) ; return likeCnt ; } async findByIdxOfUser ( userIdx ) { const likes = await this . find ( { where : { user : userIdx , } , relations : [ 'product' ] , } ) ; return likes ; } async findByIdx ( likeIdx ) { const likes = await this . findOne ( { where : { idx : likeIdx , } , relations : [ 'user' ] , } ) ; return likes ; } async deleteItem ( item ) { await this . remove ( item ) ; } async addItem ( user , product ) { const like = new LikeEntity ( ) ; like . user = user ; like . product = product ; const savedView = await this . save ( like ) ; return savedView ; } async findByProductAndUser ( product , user ) { const like = await this . findOne ( { where : { user , product , } , } ) ; return like ; } } export default LikeRepository ;