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.

Cart Zod schema and Prisma model

Cart Zod schema and Prisma model

All right. So now we're going to start to create the Add to Cart functionality. And in this video, what I want to do is set up our Zod Schemas for validation for both the items in the cart and the cart itself, and then add the types for TypeScript, and then create our Prisma model for the cart, because the user's cart will be saved in the database. So let's start off with the Zod Schemas. So that's going to be in the validator, so lib validators. And let's go under the sign-up schema. And let's just put a comment here. We'll say cart schemas. And this is going to be called cart item schema. So let's say cart item schema. And that's going to be set to z.object. And then we want to pass in our fields. So first is going to be product ID. And product ID is going to be a string. So z.string, let's set a minimum of 1. And for the message, we're just going to say product is required. All right, and then we're going to copy that down. Next one, actually, we'll just copy a few down. So next…

Contents