Skip to content

Commit

Permalink
Fix answer retrieval logic in HomeService
Browse files Browse the repository at this point in the history
  • Loading branch information
overthestream committed Dec 19, 2023
1 parent ef71321 commit a09ab9a
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/home/home.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,23 @@ export class HomeService {
const chats = await this.chattingModel.find();
const startDayTime = new Date(new Date().getTime() - 5 * 60 * 60 * 1000);
startDayTime.setHours(5, 0, 0, 0);
const answers = await this.answerRepository.find({
let answers = await this.answerRepository.find({
where: { postedAt: MoreThan(startDayTime) },
order: {
allLikes: 'DESC',
},
relations: ['user', 'user.userInfo', 'question'],
take: 3,
});
if (answers.length === 0) {
answers = await this.answerRepository.find({
order: {
allLikes: 'DESC',
},
relations: ['user', 'user.userInfo', 'question'],
take: 3,
});
}
const answersDto = await Promise.all(
answers.map(async (answerEntity) => {
const like = await this.likeRepository.findOne({
Expand Down

0 comments on commit a09ab9a

Please sign in to comment.