Skip to content
This repository has been archived by the owner on May 14, 2024. It is now read-only.

Commit

Permalink
feat : 여행 규칙 나가기
Browse files Browse the repository at this point in the history
  • Loading branch information
yewonahn committed Feb 11, 2024
1 parent c12aa97 commit bdcbc5a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 13 deletions.
13 changes: 3 additions & 10 deletions src/rule/rule.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,33 +161,26 @@ export class RuleController {
}

// [7] 여행 규칙 나가기
/*
@Delete('/:ruleId')
@UseGuards(UserGuard)
async deleteInvitation(@Req() req: Request, @Param('ruleId') ruleId: number){
// 현재 로그인한 사용자 ID
// const userId = req.user.id;
const userId = 2;
try {
await this.ruleService.deleteInvitation(ruleId, userId);
await this.ruleService.deleteInvitation(ruleId, req.user.id);
return new ResponseDto(
ResponseCode.DELETE_INVITATION_SUCCESS,
true,
"여행 규칙 나가기 성공",
null
);
} catch (error) {
} catch (e) {
return new ResponseDto(
ResponseCode.DELETE_INVITATION_FAIL,
false,
"여행 규칙 나가기 실패",
e.message,
null
);
}
}
*/

// [8] 여행 규칙 전체 리스트 조회
@Get()
Expand Down
27 changes: 24 additions & 3 deletions src/rule/rule.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,33 @@ export class RuleService {
return new CursorPageDto(result, cursorPageMetaDto);
}

// [3] 여행 규칙 나가기
// [4] 여행 규칙 나가기
// -1) 초대 받은 팀원 -> 초대 삭제
async deleteInvitation(ruleId: number, userId: number): Promise<RuleInvitationEntity> {
const invitation : RuleInvitationEntity = await RuleInvitationEntity.findInvitationByRuleAndUser(ruleId, userId);
try {
// 검증1) 사용자가 존재하지 않는 경우
const user = await UserEntity.findOne({
where: {id : userId},
});
if (!user) throw new Error('사용자를 찾을 수 없습니다');

return invitation.softRemove();
// 검증2) 규칙이 존재하지 않는 경우
const ruleMain = await RuleMainEntity.findOne({
where : {id : ruleId},
});
if (!ruleMain) throw new Error('규칙을 찾을 수 없습니다');

// 검증3) 규칙에 참여하는 사용자가 아닌 경우
const invitation = await RuleInvitationEntity.findOne({
where: {member: {id: userId}, rule: {id: ruleId}},
})
if (!!invitation) {
return invitation.softRemove();
} else throw new Error('사용자가 참여하는 규칙이 아닙니다');
} catch (e) {
console.log('여행 규칙 나가기 실패');
throw new Error(e.message);
}
}

// [4] 여행 규칙 멤버 리스트 조회
Expand Down

0 comments on commit bdcbc5a

Please sign in to comment.