mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-06 11:30: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
@@ -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