mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-06 03:20:13 +08:00
fix: wrap all async controller with error handler
* add validations to newCommand
This commit is contained in:
1 parent
1af85651b8
commit
c2dac8d385
13 files changed
+120
-120
No files matched your search
@@ -1,20 +1,20 @@
|
||||
import { UserProfile } from '@linux-odyssey/models'
|
||||
import { asyncHandler } from '../../middleware/error.js'
|
||||
|
||||
export async function me(req, res) {
|
||||
export const me = asyncHandler(async (req, res) => {
|
||||
const userProfile = await UserProfile.findOne({
|
||||
user: req.user._id,
|
||||
}).populate('user')
|
||||
})
|
||||
if (!userProfile) {
|
||||
res.status(404).json({ message: 'User not found' })
|
||||
return
|
||||
throw new Error(
|
||||
`UserProfile not found for user ${req.user.username} ${req.user._id}!`
|
||||
)
|
||||
}
|
||||
const {
|
||||
user: { username, email },
|
||||
progress,
|
||||
} = userProfile
|
||||
const { username, email } = req.user
|
||||
const { progress } = userProfile
|
||||
res.json({
|
||||
username,
|
||||
email,
|
||||
progress,
|
||||
})
|
||||
}
|
||||
})
|
||||
Reference in new issue
Block a user