diff --git a/src/controllers/oauth.controller.ts b/src/controllers/oauth.controller.ts index 5129cb3..b8c448e 100644 --- a/src/controllers/oauth.controller.ts +++ b/src/controllers/oauth.controller.ts @@ -38,7 +38,6 @@ export class OauthController { const { access_token } = tokens; const user: User = await verifyAccessToken(`Bearer ${access_token}`); const existedUser = await this.userService.findUserById(user.id); - // owner: string; // const wallet: any = await gaxios({ // url: "http://localhost:3001/proxy", // method: 'POST', diff --git a/src/controllers/social.controller.ts b/src/controllers/social.controller.ts index 8e924de..e69cfd0 100644 --- a/src/controllers/social.controller.ts +++ b/src/controllers/social.controller.ts @@ -62,6 +62,20 @@ export class SocialController { throw new BadRequestException(err.message); } } + @Post("/post/:id/comment") + async createComment(@Param("id") id: number, @Body() createComment: CreateCommentDto, @Headers('Authorization') accessToken: string) { + try { + const user = await verifyAccessToken(accessToken); + // update number of comment + const post = await this.postService.findPostById(id); + const numberOfComments = post.numberOfComments + 1; + await this.postService.updateNumberOfComments(id, numberOfComments); + return await this.commentService.createComment(user.id, id, createComment.text); + } + catch (err) { + throw new BadRequestException(err.message); + } + } @Get("/post/owner") @@ -237,20 +251,7 @@ export class SocialController { } - @Post("/post/:id/comment") - async createComment(@Param("id") id: number, @Body() createComment: CreateCommentDto, @Headers('Authorization') accessToken: string) { - try { - const user = await verifyAccessToken(accessToken); - // update number of comment - const post = await this.postService.findPostById(id); - const numberOfComments = post.numberOfComments + 1; - await this.postService.updateNumberOfComments(id, numberOfComments); - return await this.commentService.createComment(user.id, id, createComment.text); - } - catch (err) { - throw new BadRequestException(err.message); - } - } + @@ -479,4 +480,66 @@ export class SocialController { } } } + // get all post in bookmark user + @Get("/post/bookmark/:id") + async getPostByBookmark(@Param("id") id: string) { + const listPostId = await this.socialUserService.findListBookmarkById(id); + const listPost = await this.postService.findPostByListId(listPostId); + const mapPost = await Promise.all(listPost.map(async (post) => { + const comment = await this.commentService.findCommentByPostId(post.id); + const nft = await this.nftService.findNftById(post.nftId); + const ownerPost = await this.userService.findUserById(post.ownerId); + const listOwnerComment = await Promise.all(comment.map(async (comment) => { + const ownerComment = await this.userService.findUserById(comment.ownerId); + const replyComment = await this.commentService.findReplyCommentByCommentId(comment.id); + const mapReplyCmt = await Promise.all(replyComment.map(async (replyComment) => { + const ownerReplyComment = await this.userService.findUserById(replyComment.ownerId); + return { + id: replyComment.id, + text: replyComment.text, + timestamp: replyComment.timestamp, + likes: replyComment.likes, + ownerComment: { + id: ownerReplyComment.id, + name: ownerReplyComment.name, + email: ownerReplyComment.email, + picture: ownerReplyComment.picture, + }, + } + })); + return { + id: comment.id, + text: comment.text, + timestamp: comment.timestamp, + likes: comment.likes, + listReplyComment: mapReplyCmt, + ownerComment: { + id: ownerComment.id, + name: ownerComment.name, + email: ownerComment.email, + picture: ownerComment.picture, + } + } + })); + return { + postId: post.id, + text: post.text, + header: post.header, + description: post.description, + bookmark: post.bookmark, + likes: post.likes, + listComment: listOwnerComment, + timestamp: post.timestamp, + tags: post.tags, + nft: nft, + postOwner: { + id: ownerPost.id, + name: ownerPost.name, + email: ownerPost.email, + picture: ownerPost.picture, + } + } + })); + return mapPost; + } } \ No newline at end of file diff --git a/src/dtos/create-comment.dto.ts b/src/dtos/create-comment.dto.ts index 63da39d..6188d7d 100644 --- a/src/dtos/create-comment.dto.ts +++ b/src/dtos/create-comment.dto.ts @@ -6,12 +6,3 @@ export class CreateCommentDto { text: string; } -export class CreateReplyCommentDto { - @IsString() - @IsNotEmpty() - text: string; - - @IsNumber() - @IsNotEmpty() - replyCommentId: number; -} \ No newline at end of file diff --git a/src/services/social-user.service.ts b/src/services/social-user.service.ts index 1db9437..7cc0118 100644 --- a/src/services/social-user.service.ts +++ b/src/services/social-user.service.ts @@ -85,5 +85,8 @@ export class SocialUserService { }; } - + async findListBookmarkById(id: string): Promise> { + const socialUser = await this.socialUserModel.findOne({ id }) + return socialUser.bookmarks; + } } \ No newline at end of file