mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-07 11:10:11 +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,6 +1,7 @@
|
||||
import { router, publicProcedure } from '../trpc.js'
|
||||
import { linkRouter } from './linkRouter.js'
|
||||
import { questRouter } from './questRouter.js'
|
||||
import { userRouter } from './userRouter.js'
|
||||
|
||||
export const appRouter = router({
|
||||
userList: publicProcedure.query(async (opts) => {
|
||||
@@ -9,6 +10,7 @@ export const appRouter = router({
|
||||
}),
|
||||
links: linkRouter,
|
||||
quests: questRouter,
|
||||
users: userRouter,
|
||||
})
|
||||
|
||||
export type AppRouter = typeof appRouter
|
||||
@@ -0,0 +1,25 @@
|
||||
import { UserProfile } from '@linux-odyssey/models'
|
||||
import { TRPCError } from '@trpc/server'
|
||||
import { protectedProcedure, router } from '../trpc.js'
|
||||
|
||||
export const userRouter = router({
|
||||
getMyProfile: protectedProcedure.query(async (opts) => {
|
||||
const { id, username, email } = opts.ctx.user
|
||||
|
||||
const userProfile = await UserProfile.findOne({
|
||||
user: id,
|
||||
})
|
||||
if (!userProfile) {
|
||||
throw new TRPCError({
|
||||
code: 'NOT_FOUND',
|
||||
message: `UserProfile not found for user ${username} ${id}!`,
|
||||
})
|
||||
}
|
||||
const { progress } = userProfile
|
||||
return {
|
||||
username,
|
||||
email,
|
||||
progress,
|
||||
}
|
||||
}),
|
||||
})
|
||||
Reference in new issue
Block a user