@@ -100,6 +100,7 @@ export async function getGroupById(
100100 guidelines : group . guidelines ,
101101 memberCount : group . _count . members ,
102102 isMember : group . members . length > 0 ,
103+ isAdmin : group . members [ 0 ] ?. role === "ADMIN" ,
103104 } ;
104105}
105106
@@ -249,3 +250,38 @@ export async function createGroup(
249250 } ,
250251 } ) ;
251252}
253+
254+ // ──────────────────────────────────────────────
255+ // UPDATE GROUP
256+ // ──────────────────────────────────────────────
257+ export async function updateGroup (
258+ prisma : PrismaClient ,
259+ userId : string ,
260+ groupId : string ,
261+ input : { name ?: string ; description ?: string ; privacy ?: "PUBLIC" | "PRIVATE" ; image ?: string ; guidelines ?: string }
262+ ) {
263+ // Check if the user is an admin
264+ const member = await prisma . groupMember . findUnique ( {
265+ where : {
266+ userId_groupId : { userId, groupId } ,
267+ } ,
268+ } ) ;
269+
270+ if ( ! member || member . role !== "ADMIN" ) {
271+ throw new TRPCError ( {
272+ code : "UNAUTHORIZED" ,
273+ message : "You must be an admin to update this group" ,
274+ } ) ;
275+ }
276+
277+ return prisma . group . update ( {
278+ where : { id : groupId } ,
279+ data : {
280+ ...( input . name && { name : input . name } ) ,
281+ ...( input . description !== undefined && { description : input . description } ) ,
282+ ...( input . privacy && { privacy : input . privacy } ) ,
283+ ...( input . image !== undefined && { image : input . image } ) ,
284+ ...( input . guidelines !== undefined && { guidelines : input . guidelines } ) ,
285+ } ,
286+ } ) ;
287+ }
0 commit comments