Skip to content

Commit

Permalink
Merge pull request #59 from mash-up-kr/fix/postCount
Browse files Browse the repository at this point in the history
Folder list에  postCount 0으둜 λ‚˜μ˜€λŠ” 것 μˆ˜μ •, 'λ‚˜μ€‘μ— 읽을 링크' postCount λˆ„λ½ μˆ˜μ •
  • Loading branch information
hye-on authored Jul 17, 2024
2 parents 9dbb55b + ea76097 commit f170d2c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
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

0 comments on commit f170d2c

Please sign in to comment.