File tree Expand file tree Collapse file tree 1 file changed +32
-1
lines changed
Expand file tree Collapse file tree 1 file changed +32
-1
lines changed Original file line number Diff line number Diff line change @@ -47,6 +47,35 @@ const getHistory = async ({ id }: { id: string | undefined }) => {
4747
4848 return { history : JSON . parse ( JSON . stringify ( history ) ) } ;
4949}
50+ const getHistoryAuthorPost = async ( { id } : { id : string | undefined } ) => {
51+ const historyAuthor = await postgres . readingHistory . findMany ( {
52+ where : { userId : id } ,
53+ select : {
54+ post : {
55+ select : {
56+ authorId : true ,
57+ }
58+ } ,
59+ } ,
60+ orderBy : {
61+ createdAt : "desc" ,
62+ } ,
63+ take : 10 ,
64+ } ) ;
65+
66+ const history = await postgres . post . findMany ( {
67+ where : { authorId : { in : historyAuthor . map ( ( history ) => history . post . authorId ) } } ,
68+ select : {
69+ id : true ,
70+ } ,
71+ orderBy : {
72+ createdAt : "desc" ,
73+ } ,
74+ take : 10 ,
75+ } ) ;
76+
77+ return { history : JSON . parse ( JSON . stringify ( history ) ) } ;
78+ }
5079const getFollowingsUsers = async ( { id } : { id : string | undefined } ) => {
5180 const { followings : sessionFollowingsArray } = await getFollowings ( { id } ) ;
5281 console . log ( sessionFollowingsArray ) ;
@@ -197,8 +226,10 @@ const sortedTagIds = Object.entries(tagCounts)
197226 . sort ( ( a , b ) => b [ 1 ] - a [ 1 ] )
198227 . map ( ( [ tagId ] ) => tagId )
199228
229+ const { history : historyAuthor } = await getHistoryAuthorPost ( { id} ) ;
230+
200231 const posts = await postgres . post . findMany ( {
201- where : { tags : { some : { tagId : { in : sortedTagIds } } } } ,
232+ where : { tags : { some : { tagId : { in : sortedTagIds } } } , id : { in : historyAuthor . map ( ( post : any ) => post . id ) } } ,
202233 select : { id : true } ,
203234 } ) ;
204235
You can’t perform that action at this time.
0 commit comments