Skip to content

Commit

Permalink
push
Browse files Browse the repository at this point in the history
  • Loading branch information
Kiet1618 committed Nov 22, 2023
1 parent 90adfa7 commit 66e4acf
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 25 deletions.
1 change: 0 additions & 1 deletion src/controllers/oauth.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
91 changes: 77 additions & 14 deletions src/controllers/social.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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);
}
}




Expand Down Expand Up @@ -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;
}
}
9 changes: 0 additions & 9 deletions src/dtos/create-comment.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,3 @@ export class CreateCommentDto {
text: string;
}

export class CreateReplyCommentDto {
@IsString()
@IsNotEmpty()
text: string;

@IsNumber()
@IsNotEmpty()
replyCommentId: number;
}
5 changes: 4 additions & 1 deletion src/services/social-user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,8 @@ export class SocialUserService {
};
}


async findListBookmarkById(id: string): Promise<Array<number>> {
const socialUser = await this.socialUserModel.findOne({ id })
return socialUser.bookmarks;
}
}

0 comments on commit 66e4acf

Please sign in to comment.