@@ -41,13 +41,22 @@ async function ensurePodEditAccess({ id, userId }) {
41
41
}
42
42
}
43
43
44
- async function myRepos ( _ , __ , { userId } ) {
44
+ async function getDashboardRepos ( _ , __ , { userId } ) {
45
45
if ( ! userId ) throw Error ( "Unauthenticated" ) ;
46
46
const repos = await prisma . repo . findMany ( {
47
47
where : {
48
- owner : {
49
- id : userId ,
50
- } ,
48
+ OR : [
49
+ {
50
+ owner : {
51
+ id : userId ,
52
+ } ,
53
+ } ,
54
+ {
55
+ collaborators : {
56
+ some : { id : userId } ,
57
+ } ,
58
+ } ,
59
+ ] ,
51
60
} ,
52
61
include : {
53
62
UserRepoData : {
@@ -58,46 +67,17 @@ async function myRepos(_, __, { userId }) {
58
67
stargazers : true ,
59
68
} ,
60
69
} ) ;
61
- // Sort by last access time.
62
- repos . sort ( ( a , b ) => {
63
- if ( a . UserRepoData . length > 0 ) {
64
- if ( b . UserRepoData . length > 0 ) {
65
- return (
66
- b . UserRepoData [ 0 ] . accessedAt . valueOf ( ) -
67
- a . UserRepoData [ 0 ] . accessedAt . valueOf ( )
68
- ) ;
69
- }
70
- return - 1 ;
71
- }
72
- return a . updatedAt . valueOf ( ) - b . updatedAt . valueOf ( ) ;
73
- } ) ;
74
- // Re-use updatedAt field (this is actually the lastviewed field).
75
70
return repos . map ( ( repo ) => {
76
71
return {
77
72
...repo ,
78
- updatedAt :
73
+ accessedAt :
79
74
repo . UserRepoData . length > 0
80
75
? repo . UserRepoData [ 0 ] . accessedAt
81
76
: repo . updatedAt ,
82
77
} ;
83
78
} ) ;
84
79
}
85
80
86
- async function myCollabRepos ( _ , __ , { userId } ) {
87
- if ( ! userId ) throw Error ( "Unauthenticated" ) ;
88
- const repos = await prisma . repo . findMany ( {
89
- where : {
90
- collaborators : {
91
- some : { id : userId } ,
92
- } ,
93
- } ,
94
- include : {
95
- stargazers : true ,
96
- } ,
97
- } ) ;
98
- return repos ;
99
- }
100
-
101
81
async function updateUserRepoData ( { userId, repoId } ) {
102
82
// FIXME I should probably rename this from query to mutation?
103
83
//
@@ -609,9 +589,8 @@ async function copyRepo(_, { repoId }, { userId }) {
609
589
610
590
export default {
611
591
Query : {
612
- myRepos,
613
592
repo,
614
- myCollabRepos ,
593
+ getDashboardRepos ,
615
594
getVisibility,
616
595
} ,
617
596
Mutation : {
0 commit comments