mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-06 03:20:13 +08:00
26 lines
638 B
TypeScript
26 lines
638 B
TypeScript
import { TRPCError } from '@trpc/server'
|
|
import { UserProfile } from '@odyssey/models'
|
|
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,
|
|
}
|
|
}),
|
|
})
|