From 9a07e9b76b6025a395adcc674029e123a94b1338 Mon Sep 17 00:00:00 2001 From: andrewquang512 Date: Sun, 5 Nov 2023 17:18:14 +0700 Subject: [PATCH] Add categoryIds input to getNewFeed --- src/Type_Definitions/Post_Post.js | 7 ++++++- src/resolvers/Query/POST.js | 29 +++++++++++++++++++++++++---- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/src/Type_Definitions/Post_Post.js b/src/Type_Definitions/Post_Post.js index 2ee25a9..e576dec 100644 --- a/src/Type_Definitions/Post_Post.js +++ b/src/Type_Definitions/Post_Post.js @@ -8,7 +8,7 @@ const postDefs = gql` allPosts: [Post]! postInfo(data: PostInfoInput!): Post! - getNewFeed(userId: String, after: String, timeCall: Int): PostConnection! + getNewFeed(data: getNewFeedInput, after: String, timeCall: Int): PostConnection! getAllUserPosts( userId: String currentUserId: String @@ -20,6 +20,11 @@ const postDefs = gql` similarImages(data: SimilarImagesInput!): [Image]! } + input getNewFeedInput { + categoryIds: [String] + userId: String + } + type SearchReturnType { tags: [Tag]! users: [User]! diff --git a/src/resolvers/Query/POST.js b/src/resolvers/Query/POST.js index d65e5a9..65b41c2 100644 --- a/src/resolvers/Query/POST.js +++ b/src/resolvers/Query/POST.js @@ -13,7 +13,16 @@ const postQuery = { }, }); }, + + /** + * + * @param {*} parent + * @param {{data: {userId: string, categoryIds: String[]}, timeCall: number, after: string}} args + * @param {*} info + * @returns + */ getNewFeed: async (parent, args, info) => { + const { userId, categoryIds } = args.data console.log(args); let a, @@ -27,7 +36,10 @@ const postQuery = { a = await prisma.post.findMany({ where: { - userId: args.userId, + userId: userId, + categoryId: { + hasEvery: categoryIds + }, OR: [ { postViewStatus: 'PUBLIC' }, { postViewStatus: 'ONLY_FOLLOWERS' }, @@ -47,7 +59,7 @@ const postQuery = { } else { const b = await prisma.following.findUnique({ where: { - userId: args.userId, + userId: userId, }, }); console.log({ b }); @@ -69,6 +81,9 @@ const postQuery = { a = await prisma.post.findMany({ where: { userId: { in: b.userFollowing }, + categoryId: { + hasEvery: categoryIds + }, OR: [ { postViewStatus: 'PUBLIC' }, { postViewStatus: 'ONLY_FOLLOWERS' }, @@ -107,10 +122,13 @@ const postQuery = { where: { AND: [ { userId: { notIn: b.userFollowing } }, - { userId: { not: args.userId } }, + { userId: { not: userId } }, ], userId: { notIn: b.userFollowing }, postViewStatus: 'PUBLIC', + categoryId: { + hasEvery: categoryIds + }, }, orderBy: [ { @@ -127,10 +145,13 @@ const postQuery = { where: { AND: [ { userId: { notIn: b.userFollowing } }, - { userId: { not: args.userId } }, + { userId: { not: userId } }, ], userId: { notIn: b.userFollowing }, postViewStatus: 'PUBLIC', + categoryId: { + hasEvery: categoryIds + }, }, orderBy: [ {