From 2fb56ed7bd0eb05aed88f62c0645f048368d001a Mon Sep 17 00:00:00 2001 From: yewonahn Date: Tue, 13 Feb 2024 01:52:32 +0900 Subject: [PATCH] =?UTF-8?q?fix=20:=20where=20=EC=A1=B0=EA=B1=B4=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/follow/follow.service.ts | 28 ++++++++++++++++++++++------ src/rule/rule.service.ts | 26 +++++++++++++++----------- 2 files changed, 37 insertions(+), 17 deletions(-) diff --git a/src/follow/follow.service.ts b/src/follow/follow.service.ts index e1dcead..7b6101c 100644 --- a/src/follow/follow.service.ts +++ b/src/follow/follow.service.ts @@ -21,17 +21,34 @@ export class FollowService { // [1] 메이트 검색 async getSearchResult(cursorPageOptionsDto: CursorPageOptionsDto, userId: number, searchTerm: string) { + let cursorId: number = 0; - // (1) 데이터 조회 + // (1) 처음 요청인 경우 cursorId 설정 + if(cursorPageOptionsDto.cursorId == 0){ + const newUser = await UserEntity.find({ + order: { + id: 'DESC' // 가장 최근에 가입한 유저 + }, + take: 1 + }); + const cursorId = newUser[0].id + 1; + + console.log('random cursor: ', cursorId); + } + else { + cursorId = cursorPageOptionsDto.cursorId; + } + + // (2) 데이터 조회 // 검색 결과에 해당하는 값 찾기 // 해당 결과값을 name 혹은 nickName 에 포함하고 있는 사용자 찾기 + console.log('검색 값: ', searchTerm); const [resultUsers, total] = await UserEntity.findAndCount({ take: cursorPageOptionsDto.take, where: [ - {id: cursorPageOptionsDto.cursorId ? LessThan(cursorPageOptionsDto.cursorId) : null}, - {name: Like(`%${searchTerm}%`)}, - {nickname: Like(`%${searchTerm}%`)} + {id: cursorId ? LessThan(cursorId) : null, name: Like(`%${searchTerm}%`)}, + {id: cursorId ? LessThan(cursorId) : null, name: Like(`%${searchTerm}%`)}, ], relations: {profileImage : true, follower : true, following : true}, order: { @@ -41,7 +58,6 @@ export class FollowService { const userEntity = await UserEntity.findExistUser(userId); - const searchResult = await Promise.all(resultUsers.map(async (user) => { const followSearchDto = new FollowSearchDto(); @@ -66,7 +82,7 @@ export class FollowService { return followSearchDto; })); - // (2) 페이징 및 정렬 기준 설정 + // (3) 페이징 및 정렬 기준 설정 let hasNextData = true; let cursor: number; diff --git a/src/rule/rule.service.ts b/src/rule/rule.service.ts index baa48e7..78b2d33 100644 --- a/src/rule/rule.service.ts +++ b/src/rule/rule.service.ts @@ -134,7 +134,7 @@ export class RuleService { // [3] 여행 규칙 상세 페이지 조회 (댓글) - 페이지네이션 async getComment(cursorPageOptionsDto: CursorPageOptionsDto, ruleId: number): Promise> { - let cursorId: number = 0; + const cursorId: number = cursorPageOptionsDto.cursorId; // (1) 데이터 조회 const [comments, total] = await CommentEntity.findAndCount({ @@ -323,6 +323,7 @@ export class RuleService { async getSearchMemberAtCreate(cursorPageOptionsDto: CursorPageOptionsDto, userId: number, searchTerm: string): Promise> { let cursorId: number = 0; + console.log('cursorId : ', cursorPageOptionsDto); // (1) 처음 요청인 경우 cursorId 설정 if(cursorPageOptionsDto.cursorId == 0){ const newUser = await UserEntity.find({ @@ -333,23 +334,25 @@ export class RuleService { }); const cursorId = newUser[0].id + 1; - console.log('random cursor: ', cursorId); + console.log('cursorPageOptionsDto.cursorId == 0 로 인식'); + console.log('cursor: ', cursorId); } else { cursorId = cursorPageOptionsDto.cursorId; + console.log('cursorPageOptionsDto.cursorId != 0 로 인식') } + console.log('cursor: ', cursorId); // (2) 데이터 조회 // 검색 결과에 해당하는 값 찾기 // 해당 결과값을 name 혹은 nickName 에 포함하고 있는 사용자 찾기 + // { id: Not(Equal(userId))} // 사용자 본인은 검색결과에 뜨지 않도록 console.log('검색 값: ', searchTerm); const [resultUsers, total] = await UserEntity.findAndCount({ take: cursorPageOptionsDto.take, where: [ - {id: cursorId ? LessThan(cursorId) : null}, - { name: Like(`%${searchTerm}%`) }, - { nickname: Like(`%${searchTerm}%`)}, - { id: Not(Equal(userId))} // 사용자 본인은 검색결과에 뜨지 않도록 + { id: cursorId ? LessThan(cursorId) : null, name: Like(`%${searchTerm}%`) }, + { id: cursorId ? LessThan(cursorId) : null, nickname: Like(`%${searchTerm}%`)}, ], relations: {profileImage : true, ruleParticipate: {rule: true}}, order: { @@ -382,7 +385,10 @@ export class RuleService { let cursor: number; const takePerScroll = cursorPageOptionsDto.take; + console.log('takePerScroll : ',takePerScroll); const isLastScroll = total <= takePerScroll; + console.log('isLastScroll : ', isLastScroll); + console.log('total : ', total) const lastDataPerScroll = resultUsers[resultUsers.length - 1]; if (isLastScroll) { @@ -411,7 +417,7 @@ export class RuleService { }); const cursorId = newUser[0].id + 1; - console.log('random cursor: ', cursorId); + console.log('cursor: ', cursorId); } else { cursorId = cursorPageOptionsDto.cursorId; @@ -424,10 +430,8 @@ export class RuleService { const [resultUsers, total] = await UserEntity.findAndCount({ take: cursorPageOptionsDto.take, where: [ - {id: cursorId ? LessThan(cursorId) : null}, - { name: Like(`%${searchTerm}%`) }, - { nickname: Like(`%${searchTerm}%`)}, - { id: Not(Equal(userId))} // 사용자 본인은 검색결과에 뜨지 않도록 + { id: cursorId ? LessThan(cursorId) : null, name: Like(`%${searchTerm}%`) }, + { id: cursorId ? LessThan(cursorId) : null, nickname: Like(`%${searchTerm}%`)}, ], relations: {profileImage : true, ruleParticipate: {rule: true}}, order: {