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

Commit

Permalink
fix : where 조건 수정 (#183)
Browse files Browse the repository at this point in the history
  • Loading branch information
yewonahn authored Feb 12, 2024
2 parents f82d9de + 2fb56ed commit 56f0bd7
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 17 deletions.
28 changes: 22 additions & 6 deletions src/follow/follow.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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();

Expand All @@ -66,7 +82,7 @@ export class FollowService {
return followSearchDto;
}));

// (2) 페이징 및 정렬 기준 설정
// (3) 페이징 및 정렬 기준 설정
let hasNextData = true;
let cursor: number;

Expand Down
26 changes: 15 additions & 11 deletions src/rule/rule.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export class RuleService {
// [3] 여행 규칙 상세 페이지 조회 (댓글) - 페이지네이션
async getComment(cursorPageOptionsDto: CursorPageOptionsDto, ruleId: number): Promise<CursorPageDto<GetCommentDto>> {

let cursorId: number = 0;
const cursorId: number = cursorPageOptionsDto.cursorId;

// (1) 데이터 조회
const [comments, total] = await CommentEntity.findAndCount({
Expand Down Expand Up @@ -323,6 +323,7 @@ export class RuleService {
async getSearchMemberAtCreate(cursorPageOptionsDto: CursorPageOptionsDto, userId: number, searchTerm: string): Promise<CursorPageDto<GetSearchMemberAtCreateDto>> {
let cursorId: number = 0;

console.log('cursorId : ', cursorPageOptionsDto);
// (1) 처음 요청인 경우 cursorId 설정
if(cursorPageOptionsDto.cursorId == 0){
const newUser = await UserEntity.find({
Expand All @@ -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: {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand All @@ -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: {
Expand Down

0 comments on commit 56f0bd7

Please sign in to comment.