is trpc + prisma right for my problem

Hello, let's say I want functionality add to favorites in my webapp. I have user session from next auth. Currently I am storing items inside User model in my database and then mutating and displaying items with help of trpc on frontend. But the problem is that all users see the same list of items. I have tried to filter it by user id but the issue is that now if one user adds Item to favorites, the other can not because its already there but filtered. Now I think that maybe I am overcomplicating it and should just use state management like zustand with local storage?
4 Replies
Lopen
Lopen2y ago
Yes trpc is the right way to go and Restructure your database table
noctate
noctate2y ago
Ahh I think I have tried that but don't know from where to get userId inside query (if that makes sense) code for displaying items:
getAll: publicProcedure.query(async ({ ctx }) => {
try {
return await ctx.prisma.coin.findMany({
select: {
name: true,
rank: true,
userId: true,
},
});
} catch (error) {
console.log("error", error);
} }),
getAll: publicProcedure.query(async ({ ctx }) => {
try {
return await ctx.prisma.coin.findMany({
select: {
name: true,
rank: true,
userId: true,
},
});
} catch (error) {
console.log("error", error);
} }),
Lopen
Lopen2y ago
Add where
getAll: publicProcedure.query(async ({ ctx }) => {
try {
return await ctx.prisma.coin.findMany({
where: {id: userId},
select: {
name: true,
rank: true,
userId: true,
},
});
} catch (error) {
console.log("error", error);
} }),
getAll: publicProcedure.query(async ({ ctx }) => {
try {
return await ctx.prisma.coin.findMany({
where: {id: userId},
select: {
name: true,
rank: true,
userId: true,
},
});
} catch (error) {
console.log("error", error);
} }),
Also no need of the try catch since your already await Can do
getAll: publicProcedure.query(async ({ ctx }) => {

return await ctx.prisma.coin.findMany({
where: {id: userId},
select: {
name: true,
rank: true,
userId: true,
},
}).catch((err) =>{console.log(err));

getAll: publicProcedure.query(async ({ ctx }) => {

return await ctx.prisma.coin.findMany({
where: {id: userId},
select: {
name: true,
rank: true,
userId: true,
},
}).catch((err) =>{console.log(err));

noctate
noctate2y ago
Thx!
Want results from more Discord servers?
Add your server