Skip to content

Commit

Permalink
🔨 fix(questions) : 질문 리스트 총갯수 반환
Browse files Browse the repository at this point in the history
  • Loading branch information
ImNM committed Jun 18, 2022
1 parent 949a98f commit f0737ff
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/apis/alarm/pushAlarm.processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export class PushAlarmProcessor {
console.log('processor ALARM Comment ', job.data);

const chatAlarmSubDto = plainToInstance(ChatAlarmSubDto, job.data);

const room = await this.roomRepository.getUserAlarmInfoInRoom(
new RoomIdDto(chatAlarmSubDto.roomId),
);
Expand Down
27 changes: 27 additions & 0 deletions src/apis/questions/dto/QuestionListTotal.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { ApiProperty } from '@nestjs/swagger';
import { Exclude, Expose, Type } from 'class-transformer';
import { QuestionListShowDto } from './QuestionList.res.dto';
export class QuestionListTotalDto {
constructor(list: QuestionListShowDto[], realTotalCount?: number) {
this.list = list;
if (realTotalCount) this.realTotalCount = realTotalCount;
}

@Exclude({ toPlainOnly: true })
@Expose({ toClassOnly: true })
realTotalCount: number;

@ApiProperty({
description: '리스트 총 길이',
type: Number,
})
@Expose()
get totalCount(): number {
return this.realTotalCount ? this.realTotalCount : this.list.length;
}

@ApiProperty({ type: QuestionListShowDto })
@Type(() => QuestionListShowDto)
@Expose()
list: QuestionListShowDto[];
}
3 changes: 2 additions & 1 deletion src/apis/questions/questions.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import { CommentStringDto } from './dto/CommentString.dto';
import { IlikeResDto } from './dto/Ilike.res.dto';
import { QuestionShowDto } from './dto/Question.res.dto';
import { QuestionListShowDto } from './dto/QuestionList.res.dto';
import { QuestionListTotalDto } from './dto/QuestionListTotal.dto';
import { QuestionFindRequestDto } from './dto/QuestionsList.req.dto';
import { QuestionsService } from './questions.service';

Expand All @@ -50,7 +51,7 @@ export class QuestionsController {
status: 200,
description:
'요청 성공시 , 코멘트 갯수만 반환합니다 밑에 QuestionShow는 디테일 인포 용입니당!',
type: [QuestionListShowDto],
type: QuestionListTotalDto,
})
@Get()
findQuestions(
Expand Down
27 changes: 19 additions & 8 deletions src/apis/questions/questions.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { CommentStringDto } from './dto/CommentString.dto';
import { IlikeResDto } from './dto/Ilike.res.dto';
import { QuestionShowDto } from './dto/Question.res.dto';
import { QuestionListShowDto } from './dto/QuestionList.res.dto';
import { QuestionListTotalDto } from './dto/QuestionListTotal.dto';
import { QuestionFindRequestDto } from './dto/QuestionsList.req.dto';

@Injectable()
Expand Down Expand Up @@ -52,15 +53,17 @@ export class QuestionsService {
return new RoomIdDto(user.myRoom._id);
}

@returnValueToDto(QuestionListShowDto)
@returnValueToDto(QuestionListTotalDto)
async findQuestions(
userIdDto: UserIdDto,
questionFindRequestDto: QuestionFindRequestDto,
blockUserListDto: BlockedUserDto,
): Promise<QuestionListShowDto[]> {
) {
// 내 아이디 정보를 넣어서 비교로직 추가가 필요함.
const myRoomIdDto = await this.checkMyRoom(userIdDto);
let result: Question[];
let countDocuments = 0;

switch (questionFindRequestDto.filter) {
case QUESTION_FIND_FILTER_TYPE.NOTANSWERED:
result = await this.questionRepository.getQuestionsByRoomIdNotAnswerd(
Expand All @@ -82,11 +85,16 @@ export class QuestionsService {

break;
case QUESTION_FIND_FILTER_TYPE.RECENT:
result = await this.questionRepository.getRecent2Questions(
myRoomIdDto,
blockUserListDto,
);

[result, countDocuments] = await Promise.all([
this.questionRepository.getRecent2Questions(
myRoomIdDto,
blockUserListDto,
),
this.questionRepository.getQuestionsCountsByRoomId(
myRoomIdDto,
blockUserListDto,
),
]);
break;
}

Expand All @@ -105,7 +113,10 @@ export class QuestionsService {
},
);

return filterBlockedUserCommentFromCommentList as unknown as QuestionListShowDto[];
return new QuestionListTotalDto(
filterBlockedUserCommentFromCommentList as unknown as QuestionListShowDto[],
countDocuments === 0 ? undefined : countDocuments,
);
}

@returnValueToDto(QuestionShowDto)
Expand Down
10 changes: 10 additions & 0 deletions src/repositories/question.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ export class QuestionRepository {
.lean<Question[]>({ defaults: true });
}

async getQuestionsCountsByRoomId(
roomIdDto: RoomIdDto,
blockUserListDto: BlockedUserDto,
): Promise<number> {
return await this.questionModel.countDocuments({
room: roomIdDto.roomId,
user: { $nin: blockUserListDto.blockedUsers },
});
}

async getQuestionsByRoomIdNewOrder(
roomIdDto: RoomIdDto,
blockUserListDto: BlockedUserDto,
Expand Down

0 comments on commit f0737ff

Please sign in to comment.