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.

Create and update actions

Create and update actions

OK, so we're going to be creating our actions to create and update a product. But a couple of other things I want to do, I want to add a Zod schema for the update. We already have, if we look in the lib and then validators, we already have an insert product schema, which covers all the fields to create a product. So we'll use that later on. And for updating, it's going to be the same thing, except we also need to provide the ID, right? So what we can do with Zod is we can extend this schema and then just add an additional ID field. So I'm going to come down. Actually, we'll put it under the insert. I think that that makes sense to put it here. So let's say schema for updating products. So we'll say export const. And we'll call this update product schema. And we're going to set that to, and this is where we can extend by saying insert product schema, and then dot extend. And what we'll pass in extend is an object and then any additional fields that we want. So update product schema now…

Contents