Type 'ZodObject{ id ZodNumber; first_name ... missing but required in _procedure

So im trying to pass the logic I had on my Nest + Prisma + GraphQL to the ct3 stack and im a beginner with trpc which makes it even more exciting! The objective of my web application is to have a system where users can manage their workout and meal plans and, in case they dont have no idea of what they are doing, give them plan suggestions based on their weight, daily activity, etc. I installed the package zod-prisma so i dont have to write everything by hand. So based on my Prisma model i have
export const UserModel = z.object({
id: z.number().int(),
first_name: z.string().nullish(),
last_name: z.string().nullish(),
gender: z.string(),
email: z.string(),
nickname: z.string(),
password: z.string(),
emailVerified: z.date().nullish(),
createdAt: z.date(),
updatedAt: z.date(),
})
export const UserModel = z.object({
id: z.number().int(),
first_name: z.string().nullish(),
last_name: z.string().nullish(),
gender: z.string(),
email: z.string(),
nickname: z.string(),
password: z.string(),
emailVerified: z.date().nullish(),
createdAt: z.date(),
updatedAt: z.date(),
})
And on my user-login router I tought i could do something like:
import { z } from "zod";
import { UserModel } from '../../../../prisma/zod/user'
import { router, publicProcedure } from "../trpc";

export const userLoginRouter = router({
input: UserModel,
getUsers: publicProcedure.query(({ ctx }) => {
return ctx.prisma.user.findMany({})
}),
getUser: publicProcedure.query(({ ctx }) => {
const { id } = input;
return ctx.prisma.user.findUnique({
where: {
id
}
})
}),
});
import { z } from "zod";
import { UserModel } from '../../../../prisma/zod/user'
import { router, publicProcedure } from "../trpc";

export const userLoginRouter = router({
input: UserModel,
getUsers: publicProcedure.query(({ ctx }) => {
return ctx.prisma.user.findMany({})
}),
getUser: publicProcedure.query(({ ctx }) => {
const { id } = input;
return ctx.prisma.user.findUnique({
where: {
id
}
})
}),
});
Which i see now its not the right way to do. I probably have to read the documentation a bit better but i accept any tips to lead me on the right direction.
3 Replies
Knox
KnoxOP3y ago
getUser: publicProcedure.input(UserModel).query(({ ctx, input }) => {
const { id } = input;
return ctx.prisma.user.findUnique({
where: {
id
}
})
}),
getUser: publicProcedure.input(UserModel).query(({ ctx, input }) => {
const { id } = input;
return ctx.prisma.user.findUnique({
where: {
id
}
})
}),
I guess this is the right way to do it.
Lopen
Lopen3y ago
Is
z.number().int()
z.number().int()
A thing? Thought it was
z.number()
z.number()
Knox
KnoxOP3y ago
It was automatically generated but I still have to try the endpoints
Want results from more Discord servers?
Add your server