feat: migreate get user profile to trpc

This commit is contained in:
Justin Lin committed 2025-04-16 16:40:03 +08:00
1 parent ac92950177
commit 423548804a
11 files changed
+54 -62

No files matched your search

+25
View File
@@ -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,
}
}),
})