mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-06 03:20:13 +08:00
refactor: userController and add req user type
This commit is contained in:
1 parent
4c421b4cb3
commit
c912319967
8 files changed
+49
-23
No files matched your search
+6
-6
@@ -1,16 +1,16 @@
|
||||
import type { Express, Request, Response } from 'express'
|
||||
import { UserProfile } from '@linux-odyssey/models'
|
||||
import { asyncHandler } from '../../middleware/error.js'
|
||||
|
||||
export const me = asyncHandler(async (req, res) => {
|
||||
export const me = asyncHandler(async (req: Request, res: Response) => {
|
||||
const { id, username, email } = req.user as Express.ExistingUser
|
||||
|
||||
const userProfile = await UserProfile.findOne({
|
||||
user: req.user._id,
|
||||
user: id,
|
||||
})
|
||||
if (!userProfile) {
|
||||
throw new Error(
|
||||
`UserProfile not found for user ${req.user.username} ${req.user._id}!`
|
||||
)
|
||||
throw new Error(`UserProfile not found for user ${username} ${id}!`)
|
||||
}
|
||||
const { username, email } = req.user
|
||||
const { progress } = userProfile
|
||||
res.json({
|
||||
username,
|
||||
Reference in new issue
Block a user