Skip to content

Commit

Permalink
ok
Browse files Browse the repository at this point in the history
  • Loading branch information
HUNG-rushb committed Jan 6, 2024
1 parent 6e68818 commit 08d3391
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/Type_Definitions/Post_Post.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ const postDefs = gql`
limit: Int
after: String
): PostPagination!
tagSearchPosts(
data: TagSearchPostInput!
limit: Int
after: String
): PostPagination!
}
type PostPagination {
Expand Down Expand Up @@ -75,6 +80,10 @@ const postDefs = gql`
postId: String!
}
input TagSearchPostInput {
tagName: String!
}
input SearchQueryInput {
userId: ID!
searchString: String!
Expand Down
52 changes: 52 additions & 0 deletions src/resolvers/Query/POST.js
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,58 @@ const postQuery = {
},
};
},
tagSearchPosts: async (parent, args, info) => {
const { after, limit = DEFAULT_LIMIT } = args;
const { tagName } = args.data;
console.log({ tagName });

const [result, count] = await Promise.all([
prisma.post.findMany({
take: limit || DEFAULT_LIMIT,
...(after && {
skip: 1,
}),
where: {
tag: { has: tagName },
image: {
isNot: null,
},
},
include: {
image: true,
},
...(after && {
cursor: {
id: after,
},
}),
}),
prisma.post.count(),
]);

// console.log('Result', result);
// console.log('count', count);

const hasNextPage =
result.length !== 0 && result.length < count && result.length === limit;
// console.log('hasNextPage', hasNextPage);

const nodes = result.map((each) => ({
node: each,
cursor: each.id,
}));

return {
edges: shuffleArrayExceptFirstAndLast(nodes),
pageInfo: {
hasNextPage,
hasPreviousPage: after ? true : false,
// startCursor,
startCursor: nodes.length === 0 ? '' : nodes[0].cursor,
endCursor: nodes.length === 0 ? '' : nodes.slice(-1)[0].cursor,
},
};
},
};

/**
Expand Down

0 comments on commit 08d3391

Please sign in to comment.