mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-06 03:20:13 +08:00
feat: migreate get user profile to trpc
This commit is contained in:
1 parent
ac92950177
commit
423548804a
11 files changed
+54
-62
No files matched your search
@@ -1,20 +0,0 @@
|
||||
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: Request, res: Response) => {
|
||||
const { id, username, email } = req.user as Express.ExistingUser
|
||||
|
||||
const userProfile = await UserProfile.findOne({
|
||||
user: id,
|
||||
})
|
||||
if (!userProfile) {
|
||||
throw new Error(`UserProfile not found for user ${username} ${id}!`)
|
||||
}
|
||||
const { progress } = userProfile
|
||||
res.json({
|
||||
username,
|
||||
email,
|
||||
progress,
|
||||
})
|
||||
})
|
||||
@@ -4,7 +4,6 @@ import sessions from './sessionRouter.js'
|
||||
import commands from './commandRouter.js'
|
||||
import authRouter from './authRouter.js'
|
||||
import authRequired from '../../middleware/authRequired.js'
|
||||
import userRouter from './userRouter.js'
|
||||
import config from '../../config.js'
|
||||
import leaderboardController from '../controllers/leaderboardController.js'
|
||||
|
||||
@@ -28,24 +27,6 @@ router.use(
|
||||
router.use('/auth', authRouter)
|
||||
router.use('/sessions', authRequired, sessions)
|
||||
|
||||
router.use('/users', userRouter)
|
||||
|
||||
router.get('/survey', (req, res) => {
|
||||
if (!config.surveyUrl) {
|
||||
res.status(404).send('Survey not configured')
|
||||
return
|
||||
}
|
||||
res.redirect(config.surveyUrl)
|
||||
})
|
||||
|
||||
router.get('/bug-report', (req, res) => {
|
||||
if (!config.bugReportUrl) {
|
||||
res.status(404).send('Bug report not configured')
|
||||
return
|
||||
}
|
||||
res.redirect(config.bugReportUrl)
|
||||
})
|
||||
|
||||
router.get('/leaderboard', leaderboardController)
|
||||
|
||||
export default router
|
||||
@@ -1,9 +0,0 @@
|
||||
import express from 'express'
|
||||
import { me } from '../controllers/userController.js'
|
||||
import authRequired from '../../middleware/authRequired.js'
|
||||
|
||||
const router = express.Router()
|
||||
|
||||
router.get('/me', authRequired, me)
|
||||
|
||||
export default router
|
||||
@@ -0,0 +1,7 @@
|
||||
import { check } from 'express-validator'
|
||||
import { noError } from '../../middleware/validator.js'
|
||||
|
||||
export const checkQuestId = () =>
|
||||
check('questId').notEmpty().isString().isLowercase().isLength({ max: 64 })
|
||||
|
||||
export const questIdValidator = [checkQuestId(), noError]
|
||||
@@ -1,4 +1,5 @@
|
||||
import { check } from 'express-validator'
|
||||
import { checkQuestId } from './questValidator.js'
|
||||
import { noError } from '../../middleware/validator.js'
|
||||
|
||||
const checkSessionStatus = () =>
|
||||
@@ -7,7 +8,7 @@ const checkSessionStatus = () =>
|
||||
export const checkSessionId = () =>
|
||||
check('sessionId').notEmpty().isString().isMongoId()
|
||||
|
||||
export const sessionListValidator = [checkSessionStatus()]
|
||||
export const sessionListValidator = [checkQuestId(), checkSessionStatus()]
|
||||
export const sessionDetailValidator = [checkSessionId()]
|
||||
export const createSessionValidator = [noError]
|
||||
export const activeSessionValidator = [noError]
|
||||
export const createSessionValidator = [checkQuestId(), noError]
|
||||
export const activeSessionValidator = [checkQuestId(), noError]
|
||||
Reference in new issue
Block a user