Skip to content

Commit

Permalink
Merge pull request #526 from boostcampwm2023/BE-ChangeBlockUser-#524
Browse files Browse the repository at this point in the history
[BE/#524] 탈퇴한 사용자도 차단할 수 있도록 수정
  • Loading branch information
namewhat99 authored Dec 13, 2023
2 parents e58d846 + b962cc5 commit 554fe12
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
1 change: 1 addition & 0 deletions BE/src/post/post.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export class PostService {
await this.blockUserRepository.find({
where: { blocker: userId },
relations: ['blockedUser'],
withDeleted: true,
})
).map((blockedUser) => blockedUser.blockedUser.user_hash);

Expand Down
25 changes: 18 additions & 7 deletions BE/src/users-block/users-block.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ import { Repository } from 'typeorm';
import { UserEntity } from 'src/entities/user.entity';
import { ConfigService } from '@nestjs/config';

interface BlockedUser {
user_id: string;
nickname?: string;
profile_img?: string;
}

@Injectable()
export class UsersBlockService {
constructor(
Expand All @@ -18,6 +24,7 @@ export class UsersBlockService {
async addBlockUser(id: string, userId: string) {
const isExistUser = await this.userRepository.findOne({
where: { user_hash: id },
withDeleted: true,
});

if (!isExistUser) {
Expand Down Expand Up @@ -51,15 +58,19 @@ export class UsersBlockService {
});

const blockedUsers = res.reduce((acc, cur) => {
const user = {
nickname: cur.blockedUser.nickname,
profile_img:
const user: BlockedUser = {
user_id: cur.blocked_user,
};
if (cur.blockedUser === null) {
user.nickname = null;
user.profile_img = null;
} else {
user.nickname = cur.blockedUser.nickname;
user.profile_img =
cur.blockedUser.profile_img === null
? this.configService.get('DEFAULT_PROFILE_IMAGE')
: cur.blockedUser.profile_img,
user_id: cur.blockedUser.user_hash,
};

: cur.blockedUser.profile_img;
}
acc.push(user);
return acc;
}, []);
Expand Down
1 change: 0 additions & 1 deletion BE/src/users/users.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ export class UsersService {
async deleteCascadingUser(userId, userHash) {
await this.blockPostRepository.softDelete({ blocker: userHash });
await this.blockUserRepository.softDelete({ blocker: userHash });
await this.blockUserRepository.softDelete({ blocked_user: userHash });
await this.userRepository.softDelete({ id: userId });
}

Expand Down

0 comments on commit 554fe12

Please sign in to comment.