From the course: Master Next.js by Building Scalable Apps with Routing, Databases, and Performance

Unlock this course with a free trial

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

Completing add product functionality

Completing add product functionality

In the previous lecture, we have implemented image storing functionality. So we have an image path ready to store it into the database. Into the product table, we need to store current stock as well. To achieve that, we need to do summation of small size, medium size and large size. But here we get all the values in the string format. So first of all, we have to convert into the integer format using the parseInt method and store it into the variable by saying const totalStock is equal to parseInt data.smallSize plus parseInt data.mediumSize plus parseInt data.largeSize. Now I will call the db.create method. We will say await db.product.create curly brackets, then passing the data name data.name, description with data.description. As you already know, here we get sell price and MRP as a string, so I will convert them into float by saying sellPrice, parseFloat, data.sellPrice and MRP, parseFloat, data.MRP. Similarly I will enter the data for image, current stock, product type id and…

Contents