-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
merge :: apply friend list api (#16)
* add : apply friend list * chore :: code format * fix :: find element
- Loading branch information
Showing
5 changed files
with
65 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export class QueryApplyFriendListResponse { | ||
users: FriendListElement[] | ||
} | ||
|
||
export class FriendListElement { | ||
nickname: string | ||
profile: string | ||
isTurnOn: boolean | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,55 @@ | ||
import { HttpException, Injectable } from "@nestjs/common"; | ||
import { HttpException, HttpStatus, Injectable } from "@nestjs/common"; | ||
import { InjectRepository } from "@nestjs/typeorm"; | ||
import { Repository } from "typeorm"; | ||
import { FriendApplyEntity } from "../../../../infrastructure/domain/user/persistence/friend.apply.entity"; | ||
import { FriendListElement, QueryApplyFriendListResponse } from "../dto/user.dto"; | ||
import { UserEntity } from "../../../../infrastructure/domain/user/persistence/user.entity"; | ||
|
||
@Injectable() | ||
export class UserService { | ||
constructor( | ||
@InjectRepository(FriendApplyEntity) | ||
private friendApplyRepository: Repository<FriendApplyEntity> | ||
private friendApplyRepository: Repository<FriendApplyEntity>, | ||
@InjectRepository(UserEntity) | ||
private userRepository: Repository<UserEntity>, | ||
) { | ||
} | ||
|
||
async applyFriend(req) { | ||
async applyFriend(id, req) { | ||
let friendApply = new FriendApplyEntity(); | ||
let friend = await this.userRepository.findOne({ where: id }) | ||
|
||
if (!friend) { | ||
throw new HttpException('User(Friend) Not Found', HttpStatus.NOT_FOUND) | ||
} | ||
|
||
if (await this.friendApplyRepository.existsBy({ requestUserId: req, receiveUserId: friend })) { | ||
throw new HttpException('Already Apply', HttpStatus.CONFLICT) | ||
} | ||
|
||
friendApply.status = 'WAIT' | ||
friendApply.requestUserId = req.authInfo.id | ||
friendApply.receiveUserId = req.user.id | ||
friendApply.requestUserId = req | ||
friendApply.receiveUserId = friend | ||
|
||
await this.friendApplyRepository.save(friendApply) | ||
} | ||
|
||
async queryApplyFriend(req) { | ||
|
||
let friendList = await this.friendApplyRepository.findBy({ receiveUserId: req }) | ||
let friendListResponse = new QueryApplyFriendListResponse(); | ||
|
||
friendListResponse.users = await Promise.all(friendList.map(async (friend) => { | ||
let requestUser = await this.userRepository.findOneBy(friend.requestUserId); | ||
let element = new FriendListElement(); | ||
|
||
element.nickname = requestUser.nickname | ||
element.profile = requestUser.profile | ||
element.isTurnOn = requestUser.isTurnOn | ||
|
||
return element | ||
})) | ||
|
||
return friendListResponse | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters