import Post from '../infra/typeorm/entities/Post' ; import IPostRepository from '../repositories/IPostRepository' ; import IRelationshipsRepository from '@modules/users/repositories/IRelationshipsRepository' ; import { inject , injectable } from 'tsyringe' ; @ injectable ( ) class ShowPostService { constructor ( @ inject ( 'RelationshipsRepository' ) private relationshipsRepository , @ inject ( 'PostsRepository' ) private postsRepository ) { } public async execute ( id ) { const relationships = await this . relationshipsRepository . getRelationships ( id , 'following' ) ; const relationshipsIds = relationships . map ( ( relation ) => relation . id ) ; console . log ( relationshipsIds ) ; const posts = await this . postsRepository . findByUser ( [ ... relationshipsIds , id , ] ) ; return posts ; } } export default ShowPostService ;