Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions src/modules/folders/folders.v2.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
Injectable,
NotFoundException,
} from '@nestjs/common';
import { Types } from 'mongoose';
import { sum } from '@src/common';
import { FolderType } from '@src/infrastructure/database/types/folder-type.enum';
import { PostsPGRepository } from '../posts/posts.pg.repository';
Expand Down Expand Up @@ -71,21 +70,21 @@ export class FoldersV2Service {
id: null,
name: '전체',
type: FolderType.ALL,
userId: new Types.ObjectId(userId),
userId,
postCount: allPostCount,
};
const favorite = {
id: null,
name: '즐겨찾기',
type: FolderType.FAVORITE,
userId: new Types.ObjectId(userId),
userId,
postCount: favoritePostCount,
};
const readLater = {
id: defaultFolder.id,
name: defaultFolder.name,
type: FolderType.DEFAULT,
userId: new Types.ObjectId(userId),
userId,
postCount: allPostCount - customFoldersPostCount,
};

Expand Down
7 changes: 4 additions & 3 deletions src/modules/posts/posts.pg.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,12 @@ export class PostsPGRepository extends Repository<Post> {

async getPostCountByFolderIds(folderIds: string[]) {
const posts = await this.createQueryBuilder('post')
.select('folderId')
.addSelect('COUNT(id)', 'count')
.where('folderId IN (:...folderIds)', {
.select('post.folderId', 'folderId')
.addSelect('COUNT(post.id)', 'count')
.where('post.folderId IN (:...folderIds)', {
folderIds,
})
.groupBy('post.folderId')
.getRawMany<{ folderId: string; postCount: string }>();

const result = posts.map((folder) => ({
Expand Down