Skip to content

Commit

Permalink
Fix: Fix folder post response type
Browse files Browse the repository at this point in the history
  • Loading branch information
J-Hoplin committed Jul 20, 2024
1 parent 1a13414 commit 22f4240
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 19 deletions.
4 changes: 2 additions & 2 deletions src/modules/folders/docs/folder-api.docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import {
} from '@nestjs/swagger';
import {
FolderListResponse,
FolderPostResponse,
FolderResponse,
PostListInFolderResponse,
} from '../responses';

export const CreateFolderDocs = applyDecorators(
Expand Down Expand Up @@ -50,7 +50,7 @@ export const FindLinksInFolderDocs = applyDecorators(
description: '',
}),
ApiResponse({
type: PostListInFolderResponse,
type: FolderPostResponse,
}),
);

Expand Down
10 changes: 6 additions & 4 deletions src/modules/folders/folders.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
Query,
UseGuards,
} from '@nestjs/common';
import { GetUser } from '@src/common';
import { GetUser, PaginationMetadata } from '@src/common';
import { GetPostQueryDto } from '../posts/dto/find-in-folder.dto';
import { PostsService } from '../posts/posts.service';
import { JwtGuard } from '../users/guards';
Expand All @@ -26,10 +26,11 @@ import { CreateFolderDto, UpdateFolderDto } from './dto';
import { FoldersService } from './folders.service';
import {
FolderListResponse,
FolderPostResponse,
FolderResponse,
FolderSummaryResponse,
PostListInFolderResponse,
} from './responses';
import { PostResponse } from './responses/post.response';

@FolderControllerDocs
@UseGuards(JwtGuard)
Expand Down Expand Up @@ -88,12 +89,13 @@ export class FoldersController {
query,
);

return new PostListInFolderResponse(
const metadata = new PaginationMetadata(
query.page,
query.limit,
result.count,
result.posts,
);
const posts = result.posts.map((post) => new PostResponse(post));
return new FolderPostResponse(metadata, posts);
}

@UpdateFolderDocs
Expand Down
23 changes: 10 additions & 13 deletions src/modules/folders/responses/post-list-in-folder.response.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
import { ApiProperty } from '@nestjs/swagger';
import { FolderResponse } from './folder.response';
import { PostResponse } from './post.response';
import { PostDocument } from '@src/infrastructure';
import { PaginationMetadata } from '@src/common';
import { PostResponse } from './post.response';

export class FolderPostResponse {
@ApiProperty({
type: PaginationMetadata,
})
meatadata: PaginationMetadata;

export class PostListInFolderResponse extends PaginationMetadata {
@ApiProperty({ type: PostResponse, isArray: true })
list: PostResponse[];

constructor(
page: number,
limit: number,
total: number,
list: PostDocument[],
) {
super(page, limit, total);

this.list = list.map((post) => new PostResponse(post));
constructor(metadata: PaginationMetadata, posts: PostResponse[]) {
this.meatadata = metadata;
this.list = posts;
}
}

0 comments on commit 22f4240

Please sign in to comment.