import Post from '../infra/typeorm/entities/Post' ; import { inject , injectable } from 'tsyringe' ; import IPostsRepository from '@modules/posts/repositories/IPostRepository' ; import IPostLikesRepository from '@modules/posts/repositories/IPostLikesRepository' ; import INotificationsRepository from '@modules/notifications/repositories/INotificationsRepository' ; import AppError from '@shared/errors/AppError' ; interface Request { postId : string ; userId : string ; } @ injectable ( ) export default class FavoritePostSevice { constructor ( @ inject ( 'PostLikesRepository' ) private postLikeRepository , @ inject ( 'PostsRepository' ) private postsRepository ) { } public async execute ( { postId , userId } ) { const post = await this . postsRepository . findById ( postId ) ; if ( ! post ) throw new AppError ( 'A publicação a ser curtida não existe' ) ; await this . postLikeRepository . create ( { postId , userId , } ) ; post . favorite_count = post . favorite_count + 1 ; await this . postsRepository . save ( post ) ; return post ; } }