Skip to content

Commit

Permalink
Add function to retrieve
Browse files Browse the repository at this point in the history
history of posts by author
  • Loading branch information
thebkht committed Nov 29, 2023
1 parent 24c2ddb commit fe1b762
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion lib/prisma/feed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,35 @@ const getHistory = async ({ id }: { id: string | undefined }) => {

return { history: JSON.parse(JSON.stringify(history)) };
}
const getHistoryAuthorPost = async ({ id }: { id: string | undefined }) => {
const historyAuthor = await postgres.readingHistory.findMany({
where: { userId: id },
select: {
post: {
select: {
authorId: true,
}
},
},
orderBy: {
createdAt: "desc",
},
take: 10,
});

const history = await postgres.post.findMany({
where: { authorId: { in: historyAuthor.map((history) => history.post.authorId) } },
select: {
id: true,
},
orderBy: {
createdAt: "desc",
},
take: 10,
});

return { history: JSON.parse(JSON.stringify(history)) };
}
const getFollowingsUsers = async ({ id }: { id: string | undefined }) => {
const { followings: sessionFollowingsArray } = await getFollowings({ id });
console.log(sessionFollowingsArray);
Expand Down Expand Up @@ -197,8 +226,10 @@ const sortedTagIds = Object.entries(tagCounts)
.sort((a, b) => b[1] - a[1])
.map(([tagId]) => tagId)

const { history: historyAuthor } = await getHistoryAuthorPost({id});

const posts = await postgres.post.findMany({
where: { tags: { some: { tagId: { in: sortedTagIds } } } },
where: { tags: { some: { tagId: { in: sortedTagIds } } }, id: { in: historyAuthor.map((post: any) => post.id) } },
select: { id: true },
});

Expand Down

0 comments on commit fe1b762

Please sign in to comment.