2023-06-05 10:17:35 +02:00
|
|
|
export default defineEventHandler(async (event) => {
|
|
|
|
const userId: string = event.context.params ? event.context.params.id : '@me'
|
|
|
|
|
|
|
|
if (userId === '@me') {
|
|
|
|
return await getCurrentUser(event)
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
const user = await UserModel.findById(userId)
|
|
|
|
|
|
|
|
if (!user) {
|
|
|
|
throw createError({ statusCode: 400, statusMessage: 'No user was found' })
|
|
|
|
}
|
|
|
|
|
|
|
|
return user
|
|
|
|
} catch (e) {
|
|
|
|
console.error('Failed to get user by id', e)
|
|
|
|
|
|
|
|
throw createError({ statusCode: 500, statusMessage: 'Failed to get user' })
|
2023-06-01 22:06:11 +02:00
|
|
|
}
|
|
|
|
})
|