Skip to content

Commit faef281

Browse files
committed
feat: implement group detail view and editing functionality with backend integration
1 parent b01c419 commit faef281

5 files changed

Lines changed: 440 additions & 6 deletions

File tree

apps/api/src/modules/group/group.router.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,10 @@ export const groupRouter = router({
3636
.mutation(({ ctx, input }) =>
3737
GroupService.createGroup(ctx.prisma, ctx.session.user.id, input)
3838
),
39+
40+
updateGroup: protectedProcedure
41+
.input(GroupSchema.updateGroupSchema)
42+
.mutation(({ ctx, input }) =>
43+
GroupService.updateGroup(ctx.prisma, ctx.session.user.id, input.groupId, input)
44+
),
3945
});

apps/api/src/modules/group/group.schema.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,13 @@ export const createGroupSchema = z.object({
1212
privacy: z.enum(["PUBLIC", "PRIVATE"]),
1313
image: z.string().optional(),
1414
});
15+
16+
// updateGroup
17+
export const updateGroupSchema = z.object({
18+
groupId: z.string(),
19+
name: z.string().min(3).max(50).optional(),
20+
description: z.string().max(200).optional(),
21+
privacy: z.enum(["PUBLIC", "PRIVATE"]).optional(),
22+
image: z.string().optional(),
23+
guidelines: z.string().max(1000).optional(),
24+
});

apps/api/src/modules/group/group.service.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)