How to return multiple prisma calls with trpc

how do i return two prisma calls
follow: protectedProcedure.input(z.object({ userid: z.string(), pageid: z.string() })).mutation(async ({ input, ctx }) => {
ctx.prisma.user.update({
where: {
id: input.userid,
},
data: {
following: {
set: {
id: input.pageid,
},
},
},
}),
ctx.prisma.user.update({
where: {
id: input.pageid,
},
data: {
followers: {
set: {
id: input.userid,
},
},
},
});
}),
follow: protectedProcedure.input(z.object({ userid: z.string(), pageid: z.string() })).mutation(async ({ input, ctx }) => {
ctx.prisma.user.update({
where: {
id: input.userid,
},
data: {
following: {
set: {
id: input.pageid,
},
},
},
}),
ctx.prisma.user.update({
where: {
id: input.pageid,
},
data: {
followers: {
set: {
id: input.userid,
},
},
},
});
}),
i tried this but did not work either
follow: protectedProcedure.input(z.object({ userid: z.string(), pageid: z.string() })).mutation(async ({ input, ctx }) => {
return () => {
ctx.prisma.user.update({
where: {
id: input.userid,
},
data: {
following: {
set: {
id: input.pageid,
},
},
},
}),
ctx.prisma.user.update({
where: {
id: input.pageid,
},
data: {
followers: {
set: {
id: input.userid,
},
},
},
});
}
}),
follow: protectedProcedure.input(z.object({ userid: z.string(), pageid: z.string() })).mutation(async ({ input, ctx }) => {
return () => {
ctx.prisma.user.update({
where: {
id: input.userid,
},
data: {
following: {
set: {
id: input.pageid,
},
},
},
}),
ctx.prisma.user.update({
where: {
id: input.pageid,
},
data: {
followers: {
set: {
id: input.userid,
},
},
},
});
}
}),
2 Replies
cje
cje2y ago
const q1 = await prisma.whatever
const q2 = await prisma.otherThing
return { q1, q2 }
const q1 = await prisma.whatever
const q2 = await prisma.otherThing
return { q1, q2 }
or if you're feeling fancy you could use promise.all
shu
shuOP2y ago
thanks!! it worked now i feel stupid xD
Want results from more Discord servers?
Add your server