Skip to content

Commit

Permalink
Add categoryIds input to getNewFeed
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewquang512 committed Nov 5, 2023
1 parent 2bbff08 commit 9a07e9b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
7 changes: 6 additions & 1 deletion src/Type_Definitions/Post_Post.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -20,6 +20,11 @@ const postDefs = gql`
similarImages(data: SimilarImagesInput!): [Image]!
}
input getNewFeedInput {
categoryIds: [String]
userId: String
}
type SearchReturnType {
tags: [Tag]!
users: [User]!
Expand Down
29 changes: 25 additions & 4 deletions src/resolvers/Query/POST.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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' },
Expand All @@ -47,7 +59,7 @@ const postQuery = {
} else {
const b = await prisma.following.findUnique({
where: {
userId: args.userId,
userId: userId,
},
});
console.log({ b });
Expand All @@ -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' },
Expand Down Expand Up @@ -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: [
{
Expand All @@ -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: [
{
Expand Down

0 comments on commit 9a07e9b

Please sign in to comment.