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.

Preparing customers and buyers report

Preparing customers and buyers report

Let's begin with a very simple report for customers and buyers, where we will display the number of customers who are logged into the client section, and the number of customers who purchased a product, so they become buyers. For that, we will fetch the data from the buyer master table, where all the data is represented as customers and the customer who has value in the sales master column will be considered as a buyer. So we will create server action to fetch the dashboard data. For that, I will create a dashboard actions.js file inside the actions folder and will create an asynchronous function getDashboardData. Now inside we will fetch all the data in the ascending order from the buyer master table using the db.findMany method. We also need the sales data. So I will include the sales master attribute. Alright we get the customer data. Now I will filter out the buyers who have the sales data that is the ones that have purchased something. So I will write const totalBuyers is equal…

Contents