Skip to content

Commit

Permalink
Merge pull request #610 from boostcampwm2023/BE-checkChatBlock-#004
Browse files Browse the repository at this point in the history
  • Loading branch information
koomin1227 authored Jan 21, 2024
2 parents 00adc4e + 27d9f32 commit 56804b3
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
5 changes: 5 additions & 0 deletions BE/src/users-block/users-block.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ export class UsersBlockController {
return this.usersBlockService.getBlockUser(userId);
}

@Get('/:id')
async blockUserCheck(@Param('id') id: string, @UserHash() userId: string) {
return await this.usersBlockService.checkBlockUser(id, userId);
}

@Post('/:id')
async blockUserAdd(@Param('id') id: string, @UserHash() userId: string) {
await this.usersBlockService.addBlockUser(id, userId);
Expand Down
31 changes: 31 additions & 0 deletions BE/src/users-block/users-block.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,37 @@ export class UsersBlockService {
return await this.blockUserRepository.save(blockUserEntity);
}

async checkBlockUser(oppId: string, userId: string) {
const isExistUser = await this.userRepository.findOne({
where: { user_hash: oppId },
withDeleted: true,
});

if (!isExistUser) {
throw new HttpException('존재하지 않는 유저입니다', 404);
}

const checkBlock = await this.blockUserRepository.findOne({
where: { blocker: userId, blocked_user: oppId },
withDeleted: true,
});

if (checkBlock !== null) {
return { block: 'block' };
}

const checkBlocked = await this.blockUserRepository.findOne({
where: { blocker: oppId, blocked_user: userId },
withDeleted: true,
});

if (checkBlocked !== null) {
return { block: 'blocked' };
}

return { block: 'none' };
}

async getBlockUser(id: string) {
const res = await this.blockUserRepository.find({
where: { blocker: id },
Expand Down

0 comments on commit 56804b3

Please sign in to comment.