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

Commit

Permalink
Feature/#224 (#238)
Browse files Browse the repository at this point in the history
Feature/#224
[탈퇴한 회원 관련 처리 추가]

- 탈퇴한 회원 팔로우 요청이 들어온 경우 처리
- 회원 탈퇴 시, 팔로잉, 규칙 초대 테이블 삭제
  • Loading branch information
yewonahn authored Feb 16, 2024
2 parents cf93026 + 6921164 commit b0b6bd5
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 73 deletions.
14 changes: 11 additions & 3 deletions src/follow/follow.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,17 @@ export class FollowService {
async checkFollow(userId : number, followingId : number): Promise<UserFollowingEntity> {
try {
// case1) 유효한 유저인지 검증
const userEntity : UserEntity = await this.userService.findUserById(userId);
const followingUser = await UserEntity.findExistUser(followingId);
if (!followingUser) throw new NotFoundException('해당 사용자를 찾을 수 없습니다');
const userEntity : UserEntity = await UserEntity.findOne({
where: {id: userId}
});
if(!userEntity) throw new NotFoundException('요청을 보낸 사용자를 찾을 수 없습니다')
const followingUser = await UserEntity.findOne({
where: {
id: followingId
}
});
if (followingUser.isQuit == true) throw new BadRequestException('탈퇴한 회원 입니다');
if (!followingUser) throw new NotFoundException('대상 사용자를 찾을 수 없습니다');
console.log('현재 로그인한 유저 : ', userEntity);
console.log('팔로우 대상 유저 : ', followingUser);

Expand Down
2 changes: 0 additions & 2 deletions src/rule/dto/detail.rule.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@ export class RulePairDto {
}

export class DetailMemberDto {
@IsNotEmpty()
@IsNumber()
id: number;

@IsNotEmpty()
@IsString()
name: string;

Expand Down
11 changes: 6 additions & 5 deletions src/rule/dto/get-comment.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ export class GetCommentDto {
@IsNumber()
id: number;

@IsNotEmpty()
@IsNumber()
writerId: number;

@IsNotEmpty()
@IsString()
content: string;
Expand All @@ -17,7 +13,12 @@ export class GetCommentDto {
@IsDate()
updated: Date;

@IsNotEmpty()
// 탈퇴한 회원이 작성한 댓글도 표시 -> null 허용
@IsOptional()
@IsNumber()
writerId: number;

@IsOptional()
@IsString()
name: string;

Expand Down
66 changes: 47 additions & 19 deletions src/rule/rule.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Injectable } from '@nestjs/common';
import {BadRequestException, Injectable, NotFoundException} from '@nestjs/common';
import { CreateRuleDto } from './dto/create-rule.dto';
import { RuleMainEntity } from './domain/rule.main.entity';
import { RuleSubEntity } from './domain/rule.sub.entity';
Expand Down Expand Up @@ -59,7 +59,11 @@ export class RuleService {
const members = await Promise.all(dto.membersId.map(async (memberId): Promise<RuleInvitationEntity> => {
const ruleInvitationEntity = new RuleInvitationEntity();

const userEntity = await UserEntity.findOneOrFail({where: {id: memberId}});
const userEntity = await UserEntity.findOne({
where: {id: memberId }
});
if(!userEntity) throw new NotFoundException('멤버로 초대한 회원을 찾을 수 없습니다');
if(userEntity.isQuit == true) throw new BadRequestException('탈퇴한 회원은 멤버로 초대할 수 없습니다');
ruleInvitationEntity.rule = main;
ruleInvitationEntity.member = userEntity;

Expand Down Expand Up @@ -133,16 +137,27 @@ export class RuleService {
const detailMembers = await Promise.all(invitations.map(async (invitation): Promise<DetailMemberDto> => {
const detailMember = new DetailMemberDto;
const memberEntity = invitation.member;
detailMember.id = memberEntity.id;
detailMember.name = memberEntity.nickname;
console.log('detailMember.id : ', detailMember.id);

// 사용자 프로필 이미지
const image = memberEntity.profileImage;
if (image == null) detailMember.image = null;
if (memberEntity.isQuit == false) {
detailMember.id = memberEntity.id;
detailMember.name = memberEntity.nickname;
console.log('detailMember.id : ', detailMember.id);

// 사용자 프로필 이미지
const image = memberEntity.profileImage;
if (image == null) detailMember.image = null;
else {
const userImageKey = image.imageKey;
detailMember.image = await this.s3Service.getImageUrl(userImageKey);
}
}
// 탈퇴한 회원인데 ruleInvitationEntity 삭제 안된 경우)
else {
const userImageKey = image.imageKey;
detailMember.image = await this.s3Service.getImageUrl(userImageKey);
console.log('탈퇴한 회원의 ruleInvitationEntity 가 삭제되지 않았습니다');
console.log('탈퇴한 회원의 ID : ', memberEntity.id);
console.log('해당 ruleInvitationEntity ID : ', invitation.id);
detailMember.id = null;
detailMember.name = null;
detailMember.image = null;
}

return detailMember;
Expand Down Expand Up @@ -202,17 +217,31 @@ export class RuleService {
const getCommentDto = new GetCommentDto();

getCommentDto.id = comment.id;
getCommentDto.writerId = comment.user.id;
getCommentDto.name = comment.user.nickname;
getCommentDto.content = comment.content;
getCommentDto.updated = comment.updated;

// 사용자 프로필 이미지
const image = comment.user.profileImage;
if (image == null) getCommentDto.image = null;
// 댓글 작성자 정보
// 탈퇴한 사용자가 작성한 댓글도 표시
// -> 댓글 작성자 (user) 존재 여부 확인
const writerEntity = comment.user;
if (writerEntity.isQuit == false) {
getCommentDto.writerId = comment.user.id;
getCommentDto.name = comment.user.nickname;

// 사용자 프로필 이미지
const image = comment.user.profileImage;
if (image == null) getCommentDto.image = null;
else {
const userImageKey = image.imageKey;
getCommentDto.image = await this.s3Service.getImageUrl(userImageKey);
}
}
// 댓글 작성자가 탈퇴한 사용자인 경우
else {
const userImageKey = image.imageKey;
getCommentDto.image = await this.s3Service.getImageUrl(userImageKey);
console.log('탈퇴한 회원이 작성한 댓글 입니다');
getCommentDto.writerId = null;
getCommentDto.name = null;
getCommentDto.image = null;
}

return getCommentDto;
Expand Down Expand Up @@ -242,7 +271,6 @@ export class RuleService {
}

// [4] 여행 규칙 나가기
// -1) 초대 받은 팀원 -> 초대 삭제
async deleteInvitation(ruleId: number, userId: number): Promise<RuleInvitationEntity> {
try {
// 검증1) 사용자가 존재하지 않는 경우
Expand Down
66 changes: 22 additions & 44 deletions src/user/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { RuleInvitationEntity } from '../rule/domain/rule.invitation.entity';
import * as md5 from 'md5';
import { DiaryEntity } from '../diary/models/diary.entity';
import { S3UtilService } from '../utils/S3.service';
import {CommentEntity} from "../comment/domain/comment.entity";

@Injectable()
export class UserService {
Expand Down Expand Up @@ -514,6 +515,27 @@ export class UserService {
user.isQuit = true;
await user.save();

const followings = await UserFollowingEntity.find({
where: [
{user: {id: userId}},
{followUser: {id: userId}}
]
});

for(const following of followings) {
console.log('삭제될 팔로잉 테이블 ID : ', following.id);
await following.softRemove();
}

const ruleInvitations = await RuleInvitationEntity.find({
where: {member: {id: userId}}
});

for(const invitation of ruleInvitations) {
console.log('삭제될 규칙 초대 테이블 ID : ', invitation.id);
await invitation.softRemove();
}

return new ResponseDto(
ResponseCode.DELETE_ACCOUNT_SUCCESS,
true,
Expand Down Expand Up @@ -551,50 +573,6 @@ export class UserService {
}
}

/*
async getSearchResult(userId: number, searchTerm: string) : Promise<UserSearchDto[]> {
// 현재 로그인한 유저 객체
const user = await this.findUserById(userId);
console.log('현재 로그인한 유저 아이디 : ', user.id)
console.log(searchTerm);
// 검색 결과로 보여줄 유저 객체 리스트
const mates = await UserEntity.find({
where: [
{name: Like(`%${searchTerm}%`)},
{nickname: Like(`%${searchTerm}%`)},
],
relations : {
profileImage: true,
following: true,
follower: true,
}
});
console.log(mates);
// dto 리스트 생성
const results : UserSearchDto[] = await Promise.all(mates.map(async (mate) => {
const userSearchDto = new UserSearchDto();
userSearchDto.mateId = mate.id;
userSearchDto.nickName = mate.nickname;
userSearchDto.introduction = mate.introduction;
userSearchDto.followerCnt = mate.follower.length;
userSearchDto.followingCnt = mate.following.length;
userSearchDto.image = mate.profileImage.imageKey;
userSearchDto.isFollowing = await this.checkIfFollowing(user, mate.id);
return userSearchDto;
}));
console.log('검색 결과 : ', results);
return results;
}
*/

async isAlreadyFollowing(userId: number, followingId: number) {
const userEntity = await this.findUserById(userId);
const followingEntity = await this.findUserById(followingId);
Expand Down

0 comments on commit b0b6bd5

Please sign in to comment.