feat: added group management UI
This commit is contained in:
@@ -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 }
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user