@@ -133,6 +133,41 @@ export async function createRepo(_, { id, name, isPublic }, { userId }) {
133133 return repo ;
134134}
135135
136+ export async function getVisibility ( _ , { repoId } , { userId } ) {
137+ if ( ! userId ) throw Error ( "Unauthenticated" ) ;
138+ const repo = await prisma . repo . findFirst ( {
139+ where : {
140+ id : repoId ,
141+ owner : { id : userId || "undefined" }
142+ } ,
143+ include : {
144+ collaborators : true ,
145+ } ,
146+ } ) ;
147+ if ( ! repo ) throw Error ( "Repo not found" ) ;
148+ return { collaborators : repo . collaborators , isPublic : repo . public } ;
149+ }
150+
151+ export async function updateVisibility ( _ , { repoId, isPublic } , { userId } ) {
152+ if ( ! userId ) throw Error ( "Unauthenticated" ) ;
153+ const repo = await prisma . repo . findFirst ( {
154+ where : {
155+ id : repoId ,
156+ owner : { id : userId || "undefined" }
157+ } ,
158+ } ) ;
159+ if ( ! repo ) throw Error ( "Repo not found" ) ;
160+ await prisma . repo . update ( {
161+ where : {
162+ id : repoId ,
163+ } ,
164+ data : {
165+ public : isPublic ,
166+ } ,
167+ } ) ;
168+ return true ;
169+ }
170+
136171export async function updateRepo ( _ , { id, name } , { userId } ) {
137172 if ( ! userId ) throw Error ( "Unauthenticated" ) ;
138173 const repo = await prisma . repo . findFirst ( {
@@ -223,6 +258,28 @@ export async function addCollaborator(_, { repoId, email }, { userId }) {
223258 return true ;
224259}
225260
261+ export async function deleteCollaborator ( _ , { repoId, collaboratorId } , { userId } ) {
262+ if ( ! userId ) throw new Error ( "Not authenticated." )
263+ // 1. find the repo
264+ const repo = await prisma . repo . findFirst ( {
265+ where : {
266+ id : repoId ,
267+ owner : { id : userId } ,
268+ } ,
269+ } ) ;
270+ // 2. delete the user from the repo
271+ if ( ! repo ) throw new Error ( "Repo not found or you are not the owner." ) ;
272+ const res = await prisma . repo . update ( {
273+ where : {
274+ id : repoId ,
275+ } ,
276+ data : {
277+ collaborators : { disconnect : { id : collaboratorId } } ,
278+ }
279+ } )
280+ return true ;
281+ }
282+
226283export async function addPod ( _ , { repoId, parent, index, input } , { userId } ) {
227284 // make sure the repo is writable by this user
228285 if ( ! userId ) throw new Error ( "Not authenticated." ) ;
0 commit comments