Skip to content

Commit

Permalink
feat: 모임 중복 초대시 예외처리
Browse files Browse the repository at this point in the history
  • Loading branch information
w8385 committed May 25, 2024
1 parent a42cd8e commit 6c61f3c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/group/group.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ export class GroupService {
async inviteEditor(senderId: string, groupId: string, receiverId: string) {
const group = await this.groupRepository.findOne(groupId);
this.groupValidator.validateGroupOwner(group, senderId);
this.groupValidator.validateGroupInvite(group, receiverId);

group.auth.editors.push(receiverId);
await this.userService.pushEditor(receiverId, groupId);
Expand All @@ -251,6 +252,7 @@ export class GroupService {
async inviteViewer(senderId: string, groupId: string, receiverId: string) {
const group = await this.groupRepository.findOne(groupId);
this.groupValidator.validateGroupViewer(group, senderId);
this.groupValidator.validateGroupInvite(group, receiverId);

group.auth.viewers.push(receiverId);
await this.userService.pushViewer(receiverId, groupId);
Expand Down
14 changes: 13 additions & 1 deletion src/group/group.validator.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Injectable, NotFoundException, UnauthorizedException } from '@nestjs/common';
import { ConflictException, Injectable, NotFoundException, UnauthorizedException } from '@nestjs/common';

import { Group } from './entities/group.entity';

Expand Down Expand Up @@ -28,6 +28,18 @@ export class GroupValidator {
}
}

validateGroupInvite(group: Group, receiverId: string) {
this.validateGroup(group);

if (
group.auth.owner === receiverId ||
group.auth.editors.includes(receiverId) ||
group.auth.viewers.includes(receiverId)
) {
throw new ConflictException('이미 초대된 사용자입니다.');
}
}

private validateGroup(group: Group) {
if (!group) {
throw new NotFoundException('모임을 찾을 수 없습니다.');
Expand Down

0 comments on commit 6c61f3c

Please sign in to comment.