From the course: Next.js Ecommerce: Build a Shopping Platform from Scratch

Unlock this course with a free trial

Join today to access over 25,200 courses taught by industry experts.

Get reviews action

Get reviews action

All right, so there's two actions I want to create in this video. And they're pretty simple, so this will be pretty quick. So go into your review.actions.ts file. You want to go down to the bottom. And the first function or action that we're going to create is to get all reviews. So we want to get all reviews for a product. So let's export a sync function. And let's just call this get reviews. And it's going to take in an object with the product ID. It should be lowercase d. And then for the type, we'll have an object with product ID. And that's going to be a string. All right, now in the function, let's create a variable called data. And let's await prisma.review. And then we want to find many. It's a single product, but we want to find many reviews. And we want to say where the product ID is equal to the product ID that's passed in. And then we're also going to include the user name. So for that, we need to include from the user table, we want to select the name field. So set name…

Contents