added getting user and self
All checks were successful
backend-action / build-image (push) Successful in 27s
All checks were successful
backend-action / build-image (push) Successful in 27s
This commit is contained in:
@@ -47,6 +47,12 @@ export const userRoute = router({
|
||||
updateUser: protectedProcedure
|
||||
.input(userUpdateSchema)
|
||||
.mutation(async ({ input, ctx }) => await updateUser(ctx.user.id, input)),
|
||||
getUser: publicProcedure
|
||||
.input(z.object({ userId: z.number() }))
|
||||
.mutation(async ({ input }) => await getUser(input.userId, false)),
|
||||
getSelf: protectedProcedure.mutation(
|
||||
async ({ ctx }) => await getUser(ctx.user.id, true)
|
||||
),
|
||||
login: publicProcedure
|
||||
.input(z.object({ cid: z.string(), phone: z.string() }))
|
||||
.mutation(async ({ input }) => await login(input.cid, input.phone)),
|
||||
@@ -129,6 +135,24 @@ async function getAllUser(
|
||||
}));
|
||||
}
|
||||
|
||||
async function getUser(userId: number, showPhone: boolean) {
|
||||
let user = await db.query.user.findFirst({
|
||||
where: (user, { eq }) => eq(user.id, userId),
|
||||
with: {
|
||||
group: true,
|
||||
opinions: true,
|
||||
zone: true,
|
||||
},
|
||||
});
|
||||
if (user === undefined) {
|
||||
throw new TRPCError({
|
||||
message: "User not found",
|
||||
code: "BAD_REQUEST",
|
||||
});
|
||||
}
|
||||
return { ...user, phone: showPhone ? user.phone : hidePhone(user.phone) };
|
||||
}
|
||||
|
||||
async function createUser(
|
||||
newUser: UserInsertSchema,
|
||||
opinions: OpinionInsertSchema
|
||||
|
||||
Reference in New Issue
Block a user