Skip to content

Commit

Permalink
add feat bookmark
Browse files Browse the repository at this point in the history
  • Loading branch information
Kiet1618 committed Nov 23, 2023
1 parent c3a86fa commit 0c14a50
Showing 1 changed file with 5 additions and 56 deletions.
61 changes: 5 additions & 56 deletions src/controllers/social.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
}

0 comments on commit 0c14a50

Please sign in to comment.