nikolayneykov

Untitled

Dec 5th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. async findUserById(userId: number, loggedUserId: number): Promise<UserDTO> {
  2.     const foundUser: User = await this.usersRepository
  3.       .findOne({ where: { id: userId, isDeleted: false }, relations: ['followers'] });
  4.  
  5.     if (!foundUser) {
  6.       throw new NotFoundUserError();
  7.     }
  8.  
  9.     const isFollowed: boolean = loggedUserId !== -1 &&
  10.       foundUser['followers'].some((u: User) => u.id === loggedUserId);
  11.  
  12.     return {
  13.       ...this.mapper.toUserDTO({ ...foundUser }),
  14.       isFollowed,
  15.     };
  16.   }
Add Comment
Please, Sign In to add comment