Kevbot
Kevbot
Explore posts from servers
PPrisma
Created by Kevbot on 7/10/2024 in #help-and-questions
GET request using JSON body
context: prisma,zod,typescript I'm trying to run a GET request and passing in a json body, In order to make this work i need to convert it to using .mutation instead of .query. I was wondering if this is the standard for using prisma as I know posts will still return data. for example: in my postman json:
{
"user_id": 46216
}
{
"user_id": 46216
}
"message": "[\n {\n \"code\": \"invalid_type\",\n \"expected\": \"object\",\n \"received\": \"undefined\",\n \"path\": [],\n \"message\": \"Required\"\n }\n]",

// This will fail as a GET request returning: ^
getFavoriteTruckStops: t.procedure
.input(z.object({user_id: z.number().optional()}))
.query(async ({input}) => {
console.log('findUniqueFuelStop hit with input:', input);
return prisma.truck_stop_favorites.findMany({
where: {user_id: input.user_id}
});
})
"message": "[\n {\n \"code\": \"invalid_type\",\n \"expected\": \"object\",\n \"received\": \"undefined\",\n \"path\": [],\n \"message\": \"Required\"\n }\n]",

// This will fail as a GET request returning: ^
getFavoriteTruckStops: t.procedure
.input(z.object({user_id: z.number().optional()}))
.query(async ({input}) => {
console.log('findUniqueFuelStop hit with input:', input);
return prisma.truck_stop_favorites.findMany({
where: {user_id: input.user_id}
});
})
//This works properly as POST and returns my data.
getFavoriteTruckStops: t.procedure
.input(z.object({user_id: z.number().optional()}))
.mutation(({input}) => {
console.log('findUniqueFuelStop hit with input:', input);
return prisma.truck_stop_favorites.findMany({
where: {user_id: input.user_id}
});
})
//This works properly as POST and returns my data.
getFavoriteTruckStops: t.procedure
.input(z.object({user_id: z.number().optional()}))
.mutation(({input}) => {
console.log('findUniqueFuelStop hit with input:', input);
return prisma.truck_stop_favorites.findMany({
where: {user_id: input.user_id}
});
})
9 replies
TTCTheo's Typesafe Cult
Created by Kevbot on 3/20/2024 in #questions
Permissions issue off fresh TRPC template
No description
2 replies