feat: stabilize admin dashboard, refactor group management, implement PWA, and fix routing
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
import { requireAuth } from '~/server/utils/auth'
|
||||
import { prisma } from '~/server/utils/prisma'
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const currentUser = requireAuth(event)
|
||||
const targetIdOrUsername = getRouterParam(event, 'id')
|
||||
|
||||
const targetUser = await prisma.user.findFirst({
|
||||
where: {
|
||||
OR: [
|
||||
{ id: targetIdOrUsername },
|
||||
{ username: targetIdOrUsername }
|
||||
]
|
||||
}
|
||||
})
|
||||
|
||||
if (!targetUser) {
|
||||
throw createError({ statusCode: 404, message: 'User not found' })
|
||||
}
|
||||
|
||||
if (targetUser.id === currentUser.id) {
|
||||
throw createError({ statusCode: 400, message: 'You cannot follow yourself' })
|
||||
}
|
||||
|
||||
await prisma.follows.upsert({
|
||||
where: {
|
||||
followerId_followingId: {
|
||||
followerId: currentUser.id,
|
||||
followingId: targetUser.id
|
||||
}
|
||||
},
|
||||
update: {},
|
||||
create: {
|
||||
followerId: currentUser.id,
|
||||
followingId: targetUser.id
|
||||
}
|
||||
})
|
||||
|
||||
return { success: true }
|
||||
})
|
||||
Reference in New Issue
Block a user