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 - Next.js Tutorial
From the course: Next.js Ecommerce: Build a Shopping Platform from Scratch
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
-
-
-
-
-
-
(Locked)
Section intro1m 11s
-
(Locked)
Get products for admin page8m 24s
-
(Locked)
Display products7m 55s
-
(Locked)
Delete products4m 16s
-
(Locked)
Create and update actions8m 30s
-
(Locked)
Create product page and form9m 35s
-
(Locked)
Form fields and slugify13m 27s
-
(Locked)
Create product form submission6m 23s
-
(Locked)
Uploadthing configuration8m 9s
-
(Locked)
Add image upload12m 56s
-
(Locked)
Product cleanup7m 57s
-
(Locked)
Is featured banner8m 55s
-
(Locked)
Product update form9m 57s
-
(Locked)
-
-
-
-
-
-