42 lines
988 B
TypeScript
42 lines
988 B
TypeScript
import { prisma } from '~/server/utils/prisma'
|
|
|
|
export default defineEventHandler(async (event) => {
|
|
const userId = getRouterParam(event, 'id')
|
|
|
|
if (!userId) {
|
|
throw createError({ statusCode: 400, message: 'User ID is required' })
|
|
}
|
|
|
|
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' })
|
|
}
|
|
|
|
return {
|
|
profile: {
|
|
...profile,
|
|
canvasCount: profile.user._count.canvases,
|
|
followerCount: profile.user._count.followers,
|
|
followingCount: profile.user._count.following
|
|
}
|
|
}
|
|
})
|