feat: added group management UI

This commit is contained in:
2026-05-03 16:41:17 +05:00
parent 4ed6a832d1
commit 622ca04170
4 changed files with 268 additions and 26 deletions
+27 -26
View File
@@ -1,4 +1,4 @@
import { profiles, canvases, follows } from '~/server/utils/db'
import { prisma } from '~/server/utils/prisma'
export default defineEventHandler(async (event) => {
const userId = getRouterParam(event, 'id')
@@ -7,34 +7,35 @@ export default defineEventHandler(async (event) => {
throw createError({ statusCode: 400, message: 'User ID is required' })
}
const profile = profiles.get(userId)
const profile = await prisma.profile.findUnique({
where: { userId },
include: {
user: {
include: {
_count: {
select: {
canvases: true,
followers: true,
following: true
}
}
}
}
}
})
if (!profile) {
// If profile doesn't exist but user might exist in Firebase,
// we could potentially create it here or return 404
throw createError({ statusCode: 404, message: 'Profile not found' })
}
// Count user's canvases
const userCanvases = Array.from(canvases.values()).filter(
canvas => canvas.ownerId === userId
)
// Count followers and following
const followers = Array.from(follows.values()).filter(
follow => follow.followingId === userId
).length
const following = Array.from(follows.values()).filter(
follow => follow.followerId === userId
).length
// Update profile with current stats
const updatedProfile = {
...profile,
canvasCount: userCanvases.length,
followerCount: followers,
followingCount: following
return {
profile: {
...profile,
canvasCount: profile.user._count.canvases,
followerCount: profile.user._count.followers,
followingCount: profile.user._count.following
}
}
profiles.set(userId, updatedProfile)
return { profile: updatedProfile }
})