Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Folder list에 postCount 0으로 나오는 것 수정, '나중에 읽을 링크' postCount 누락 수정 #59

Merged
merged 2 commits into from
Jul 17, 2024
Merged
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
22 changes: 16 additions & 6 deletions src/modules/folders/folders.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export class FoldersService {
const groupedFolders =
await this.postRepository.getPostCountByFolderIds(folderIds);

const allPostCount = sum(groupedFolders, (folder) => folder.count);
const allPostCount = sum(groupedFolders, (folder) => folder.postCount);
const favoritePostCount =
await this.postRepository.findFavoritePostCount(userId);

Expand All @@ -41,15 +41,18 @@ export class FoldersService {
const customFolders = folders
.filter((folder) => folder.type === FolderType.CUSTOM)
.map((folder) => {
const post = groupedFolders.find((folder) =>
folder._id.equals(folder._id),
const post = groupedFolders.find((groupedFolder) =>
groupedFolder._id.equals(folder._id),
);
return {
...folder.toJSON(),
postCount: post?.count ?? 0,
postCount: post?.postCount ?? 0,
};
});

const customFoldersPostCount = sum(
customFolders,
(folder) => folder.postCount,
);
const all = {
id: null,
name: '모든 링크',
Expand All @@ -64,8 +67,15 @@ export class FoldersService {
userId: new MongooseSchema.Types.ObjectId(userId),
postCount: favoritePostCount,
};
const defaultFolderTmp = {
id: defaultFolder.id,
name: defaultFolder.name,
type: FolderType.DEFAULT,
userId: new MongooseSchema.Types.ObjectId(userId),
postCount: allPostCount - customFoldersPostCount,
};

const defaultFolders = [all, favorite, defaultFolder].filter(
const defaultFolders = [all, favorite, defaultFolderTmp].filter(
(folder) => !!folder,
);
return { defaultFolders, customFolders };
Expand Down
2 changes: 1 addition & 1 deletion src/modules/posts/posts.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export class PostsRepository {
async getPostCountByFolderIds(folderIds: Types.ObjectId[]) {
const folders = await this.postModel.aggregate<{
_id: Types.ObjectId;
count: number;
postCount: number;
}>([
{
$match: {
Expand Down