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

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