From 0c14a502bf59fc41dd2ce49e02f53c1bed0eec58 Mon Sep 17 00:00:00 2001 From: Kiet1618 Date: Thu, 23 Nov 2023 17:46:09 +0700 Subject: [PATCH] add feat bookmark --- src/controllers/social.controller.ts | 61 +++------------------------- 1 file changed, 5 insertions(+), 56 deletions(-) diff --git a/src/controllers/social.controller.ts b/src/controllers/social.controller.ts index 6795f45..72d870c 100644 --- a/src/controllers/social.controller.ts +++ b/src/controllers/social.controller.ts @@ -407,6 +407,10 @@ export class SocialController { @Put("/post/:id/bookmark-or-unbookmark") async updateBookmark(@Param("id") id: number, @Headers('Authorization') accessToken: string) { try { + if (!accessToken) { + throw new BadRequestException(`You don't have permission`); + } + const user = await verifyAccessToken(accessToken); await this.postService.updateBookmarkOrUnBookmarkAndList(id, user.id); return await this.socialUserService.updateBookmarksOrUnBookmarks(user.id, id); @@ -486,61 +490,6 @@ export class SocialController { 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; + return listPost.map(post => post.id); } } \ No newline at end of file