Node.js Food Order System Tutorial (EASY & FAST)

Code with Jay
29 Dec 202024:53

Summary

TLDRIn this video, the host guides viewers through deploying a Node.js project on Heroku, explaining the transition to microservices architecture. The tutorial covers project preparation for production, including compiling TypeScript and setting up PM2 for process monitoring. It also introduces DevOps practices, such as Dockerization, Docker Compose, and CI/CD pipelines. The host demonstrates deploying to Heroku, configuring databases, and updating the application with new features, like order handling, ensuring a smooth viewer experience into the next episode focusing on microservices.

Takeaways

  • 🚀 The video discusses deploying a Node.js project on Heroku and transitioning to a microservices architecture in subsequent episodes.
  • 🛠️ The project needs to be built compatible with ES5 or ES6, especially when using TypeScript, to ensure it runs smoothly on the production server.
  • 📦 The script covers the importance of Dockerizing the project and its dependencies for independent operations and ease of management.
  • 🔄 The video introduces the use of Docker Compose for running containers easily and setting up a Docker network for service communication.
  • 🔧 The script explains the setup of a CI/CD pipeline for integration testing and deployment automation to the cloud.
  • 🌐 The video mentions using a reverse proxy like NGINX for exposing the application to the audience and load balancing with Kubernetes.
  • 📝 The importance of configuring the `package.json` file for deployment is highlighted, including setting up scripts for build and start processes.
  • 🔄 The script details modifying the Node.js application to work with environment variables, especially for database connections and port configurations.
  • 🔑 The video shows the process of creating and configuring a Heroku app, including pushing code and handling build processes on the platform.
  • 🔍 Debugging tips are provided, such as using Heroku logs to monitor the application's behavior and troubleshoot issues.
  • 📈 The script outlines steps for creating order functionalities in the application, including handling order creation and retrieval of order details.

Q & A

  • What is the main topic discussed in the video script?

    -The main topic discussed in the video script is the deployment of a Node.js project on Heroku and the subsequent development of an order section within the project.

  • Why is the project being deployed on Heroku before the order section is completed?

    -The project is being deployed on Heroku early because the tutorial is transitioning to a microservices architecture from the next episode onward, and this allows viewers who are not interested in microservices to continue with the monolithic architecture.

  • What is the significance of compiling the project's TypeScript to ES5 or ES6 before deployment?

    -Compiling TypeScript to ES5 or ES6 is important because running the project directly with TypeScript and development dependencies on a production server is not advisable.

  • What are the key considerations when deploying a Node.js project on a server?

    -Key considerations include ensuring Node.js is installed, configuring any project-related services such as databases, caches, or mail servers, and using tools like PM2 to monitor the project in the production environment.

  • What is the role of Docker in the deployment process described in the script?

    -Docker is used to containerize the project and its dependencies, allowing them to run independently and making it easier to manage starting operations and network configurations for the containers.

  • What is the purpose of setting up a CI/CD server configuration in the DevOps approach?

    -The purpose of setting up a CI/CD server configuration is to automate the process of running integration tests and test coverages before deploying the artifacts to the cloud, ensuring a smooth and error-free deployment.

  • How does the script suggest handling the database configuration for deployment?

    -The script suggests using a cloud MongoDB URL instead of a local database for deployment, which requires configuring the database connection in the project.

  • What is the significance of setting the port dynamically in the project configuration?

    -Setting the port dynamically allows the application to run on the port specified by the environment variable if available, otherwise it defaults to port 8000, providing flexibility for different deployment environments.

  • What changes are made to the package.json file in preparation for deployment?

    -Changes to the package.json file include updating the scripts for building and running the project, specifying the Node.js engine version, and removing unnecessary dependencies and devDependencies.

  • How does the script handle the creation of orders in the application?

    -The script handles the creation of orders by first grabbing the login customer, creating an order ID, grabbing order items from the request, calculating the order amount based on the database information, creating an order with item descriptions, and updating the order in the user account.

  • What is the next step in the tutorial series after deploying the project on Heroku?

    -The next step in the tutorial series is to work on the order section and then transition to a microservices architecture for more advanced development.

Outlines

00:00

🚀 Introduction to Node.js Deployment and DevOps

The speaker begins by welcoming viewers to the channel and announces the continuation of a series on Node.js. They plan to deploy the current progress of their project on Heroku, despite it not being the ideal time, as future episodes will shift towards a microservices architecture. The speaker emphasizes the importance of understanding how Node.js operates in a production environment, highlighting the need for compatibility with ES5 or ES6. They discuss the deployment process, which includes ensuring Node.js is installed on the server, configuring project-related settings, and using tools like PM2 for monitoring. The speaker contrasts the traditional deployment workflow with the DevOps approach, which involves collaboration between development, operations, and quality assurance teams. They touch on Dockerization, Docker Compose for container management, and the use of CI/CD pipelines for automated testing and deployment. The speaker concludes by outlining the steps for deploying on Heroku, including updating the TypeScript configuration and package.json file.

05:01

🛠️ Preparing the Project for Heroku Deployment

The speaker continues by detailing the modifications needed for the project to be deployable on Heroku. They start by updating the 'package.json' file to include necessary scripts and dependencies. The speaker removes deprecated packages and adds engines to specify the compatible Node.js version. They also discuss the importance of handling MongoDB errors and making the project compatible with ES6. The speaker demonstrates how to install dependencies and troubleshoot common issues, such as those related to MongoDB. They show how to configure the database connection to use a cloud MongoDB URL and modify the 'index.ts' file to dynamically assign the server port. The speaker concludes this section by committing the changes and demonstrating the creation of an app on Heroku, followed by a successful build and deployment.

10:01

🌐 Deploying and Testing the Application on Heroku

After successfully deploying the application on Heroku, the speaker checks if the app is running correctly by accessing it through a provided URL. They demonstrate how to use Postman to test the application's endpoints, such as creating a vendor and logging in as a banner. The speaker shows how to access logs from the Heroku server to monitor the application's performance. They also discuss the process of making changes to the application and redeploying it on Heroku, emphasizing the ease of updates and the automatic build process. The speaker then shifts focus to the next steps, which include working on the order section of the application and setting up the necessary routes and controllers.

15:01

📝 Developing the Order Section and Database Interaction

The speaker delves into the development of the order section, starting with the creation of order-related routes and controllers. They discuss the process of handling order creation, including fetching the logged-in customer, generating an order ID, and calculating the order amount based on item details from the request. The speaker emphasizes the importance of using accurate price information from the database to ensure correct order calculations. They demonstrate how to create a data model for orders and modify the customer model to include an orders array. The speaker also shows how to handle the creation of orders, including updating the user's order information and returning the current order details upon successful creation.

20:04

🔍 Implementing Get Orders and Order by ID Functionality

The speaker continues the development of the order section by implementing the functionality to retrieve orders and view a specific order by its ID. They show how to fetch the current customer's orders and use the 'get' method to access the orders array. The speaker also demonstrates how to populate the food details for each order item. They discuss the process of retrieving a specific order by its ID, including populating the food information for that order. The speaker tests these functionalities using a tool like Postman, showcasing the successful retrieval of order details. They conclude by summarizing the progress made in the episode and teasing the upcoming focus on microservices architecture in future episodes.

Mindmap

Keywords

💡Heroku

Heroku is a cloud platform that lets companies build, deliver, monitor, and scale apps. In the video, Heroku is used as the platform for deploying the Node project, demonstrating the process of pushing changes to the Heroku server and making the application available online.

💡Microservices Architecture

Microservices Architecture is a style of software architecture where large applications are broken down into smaller, independent services that communicate with each other. The video mentions a transition to this architecture from the next episode, indicating a shift towards a more scalable and maintainable system design.

💡DevOps

DevOps is a set of practices that combines software development (Dev) and IT operations (Ops) to shorten the systems development life cycle and provide continuous delivery of value to end users. The script discusses the DevOps culture and its role in the deployment process, emphasizing the collaboration between development, operations, and quality assurance.

💡Dockerization

Dockerization refers to the process of containerizing applications into Docker containers. In the context of the video, the project is dockerized to ensure it can run independently and be easily managed, which is a key step in the DevOps workflow described.

💡Docker Compose

Docker Compose is a tool for defining and running multi-container Docker applications. The script mentions configuring a Docker Compose file to simplify the process of running containers and ensuring they can communicate within the same Docker network.

💡CI/CD

CI/CD stands for Continuous Integration/Continuous Deployment, which are practices in software development that aim to improve the process of integrating changes from multiple contributors and deploying them to a live environment. The video script refers to setting up a CI/CD server for running integration tests and deploying artifacts to the cloud.

💡TypeScript

TypeScript is a superset of JavaScript that adds optional static typing, classes, and interfaces. In the video, the project is written in TypeScript, and there is a discussion about compiling TypeScript code to be compatible with the production environment.

💡ES5/ES6

ES5 and ES6 refer to different versions of the ECMAScript standard for JavaScript. ES6, also known as ECMAScript 2015, introduced many new features to the language. The script mentions building the Node project to be compatible with ES5 or ES6, indicating the need for transpilation for compatibility with different JavaScript engines.

💡PM2

PM2 is a process manager for Node.js applications with a built-in load balancer. It is used to ensure that applications run continuously and to manage application deployment and monitoring. The video script suggests using PM2 to monitor the Node project in the production environment.

💡MongoDB

MongoDB is a NoSQL database that stores data in a flexible, JSON-like format. In the video, MongoDB is used as the database for the Node project, and there is a discussion about switching from a local MongoDB instance to a cloud-based MongoDB URL for deployment.

💡Order Management

Order Management refers to the process of handling customer orders in a business system. The script describes creating routes for order management, including creating orders and retrieving orders, which is a crucial part of the application's functionality being developed in the video.

Highlights

Introduction to the deployment process of a Node.js project on Heroku, transitioning from a monolithic architecture to microservices.

Explanation of the importance of compiling a Node.js project to ES5 or ES6 before deployment, especially when using TypeScript.

Overview of the DevOps approach, emphasizing the automation of development, operations, and quality assurance processes.

Discussion on the necessity of Dockerizing projects and dependencies for efficient deployment and management.

Step-by-step guide on setting up Docker Compose for managing containers and services within a Docker network.

Details on configuring Nginx as a reverse proxy and load balancer for Docker containers.

Instructions on setting up CI/CD server configurations for automatic deployment, testing, and integration.

Demonstration of deploying a Node.js project on Heroku and the importance of post-install scripts for smooth deployment.

Modifications to the TypeScript configuration file, including setting up source and distribution directories.

Instructions for configuring a database connection, transitioning from a local database to a cloud MongoDB instance.

Detailed steps for handling environment variables and setting up dynamic port configurations for deployment.

Explanation of setting up and modifying the package.json file, including managing dependencies and scripts.

Guidelines on creating and managing orders within the application, including creating routes and controllers for order processing.

Instructions on creating a Data Transfer Object (DTO) for order inputs and managing cart items during order creation.

Final demonstration of deploying changes to Heroku, validating successful deployment, and verifying the application’s functionality using Postman.

Transcripts

play00:00

hey there welcome to my channel let's

play00:02

continue with our series today we will

play00:03

work on the order section

play00:05

but right before moving forward we will

play00:06

deploy our current progress on heroku

play00:09

i know this is not right time to deploy

play00:11

our project but

play00:12

from the next episode onward we will

play00:14

completely move to microservices

play00:16

architecture

play00:16

if people not willing to follow that

play00:18

architecture so at least

play00:19

they can continue with the current flow

play00:21

to publish the final project on

play00:23

monolithic way

play00:24

let's understand how the node project is

play00:26

working on the production environment

play00:28

first of all we need to build our node

play00:29

project compatible to es5 or es6

play00:32

if we're writing on the typescript then

play00:34

only we will move to the compile output

play00:36

to the production server

play00:37

because it is not a good idea to run the

play00:39

project on the production server

play00:40

with the typescript directly with the

play00:42

development dependency right

play00:44

there are many ways you can deploy your

play00:45

artifacts on the cloud it depends on

play00:47

your working style and what kind of

play00:49

process you are following

play00:50

in my case i am following devops culture

play00:52

and i will try to give an overview

play00:54

then how the things are working in the

play00:56

devops and the normal flow

play00:58

in the normal flow usually we are

play00:59

deploying our project on any web server

play01:01

or where a couple of things we need to

play01:03

take care of number one make sure you

play01:05

have installed node.js in your server

play01:07

make sure all the pdp sets configured on

play01:09

your server related to project

play01:11

example db a cache or mail server etc

play01:15

and finally we need to install uh pm2 or

play01:17

similar tools to monitor our projects on

play01:19

the production environment

play01:21

if it crashed on runtime so or something

play01:23

happen

play01:24

unwanted then it will restart your

play01:26

project immediately and next upload your

play01:28

project and start on the specified port

play01:30

and finally we need to set up a reverse

play01:32

proxy to bind our expose port

play01:33

to reach to the audience so that this is

play01:36

the normal workflow

play01:37

in the devops way it's a combination of

play01:38

development operation and the quality

play01:40

students working together on

play01:42

sync to sip the final product to the

play01:44

audience i will not go deeper to make

play01:45

you understand what devops it is

play01:47

uh so there are tons of resources

play01:48

available on the web which can help you

play01:50

to understand

play01:51

in this way first we need to dockerize

play01:52

our project and dependency images

play01:54

example if you are using mongodb or

play01:56

mysql

play01:57

or redis or revit mq for messaging queue

play02:00

um

play02:00

so all those things you need to

play02:02

dockerize first so it can run

play02:03

independently to perform

play02:04

starting operations next configure

play02:06

docker compose file to run the

play02:08

containers easily through a command

play02:10

or where the containers reach to the

play02:12

services together in the same docker

play02:13

network

play02:14

next we need to add the engine x to

play02:15

handle the reverse proxy

play02:17

for reaching out the exposed port

play02:19

finally we need to set up the ci cd

play02:21

server configuration to run our

play02:22

integration and test coverages

play02:24

right before deploying our artifacts on

play02:26

the cloud for example elastic bin stock

play02:28

or aws instance or maybe google cloud or

play02:30

digital

play02:31

etc additionally we can manage our

play02:32

containers by adding kubernetes and

play02:34

ingress

play02:35

engine x is gonna be work as a proxy and

play02:36

a loop balancer for our containers

play02:38

so these are some of the advanced topic

play02:40

definitely we will cover in sunday

play02:42

so in the in the devops way all the

play02:43

process are running automatically

play02:45

when we push a new changes to the master

play02:47

repository now i hope you got an idea

play02:49

how we can proceed with the deployment

play02:50

stage of the node project now let's

play02:52

deploy this thing in heroku first

play02:54

and after that we will work on the order

play02:56

section so here is our project

play02:58

so far we have covered pretty much good

play03:00

amount of functionality we will work a

play03:01

bit on our ts config file here

play03:05

i am going to wipe it out first all

play03:07

those things like

play03:08

here okay

play03:34

these are the things at least we should

play03:35

have to be present in our ts config file

play03:38

so here root directory we are just

play03:39

pointing to a directory which is going

play03:41

to be like in a source directory which

play03:42

is we have not created at all

play03:44

so let's create that directory um src

play03:48

and secondly uh the distribution

play03:51

directory we don't need to create at all

play03:53

so it will be created automatically

play03:54

by by typescript when we compile our

play03:57

source code

play03:58

i'm going to delete this node module

play04:00

here okay and

play04:02

now now let's let's move all those

play04:04

things to inside the source directory

play04:12

now now all the files are inside the

play04:13

source directory good

play04:15

package log session file we are going to

play04:17

delete this one

play04:18

and now we need to do a little bit work

play04:20

on the package.json file

play04:30

okay so uh with the help of the tsc

play04:33

that's p

play04:33

and dot dot um this this common one when

play04:36

will we

play04:37

run this script then it will compile our

play04:39

whole project by

play04:40

typescript okay

play04:43

next next uh right after making the bill

play04:47

uh we need to add some more things that

play04:50

is gonna be like post

play04:52

post install and that will be npm

play04:56

run though good

play05:00

so this post install install will be

play05:02

required as far as hero currently

play05:04

for other stuff if you are um if you are

play05:06

deploying on

play05:07

the docker containers and this is not

play05:10

going to be necessary at all

play05:12

all right so um this section is done now

play05:14

let's come to the dependencies

play05:16

right before adding dependency we will

play05:18

add one more thing that is that will be

play05:20

our engines

play05:26

here and right right before the

play05:28

dependency i'm going to add one more

play05:30

dependency that is kind of a depth

play05:31

dependencies

play05:33

and inside the dev defense a couple of

play05:34

things we will be uh moving from here

play05:48

so certainly we have everything is clear

play05:50

here

play05:51

this body pressure will be not required

play05:52

because this is deprecated this is

play05:54

coming inside the

play05:54

express module right now and this comma

play05:57

we need to remove all right

play05:59

so our uh our package.json pilot so it's

play06:02

totally ready

play06:03

right let's go to the index.ts file here

play06:08

go to app

play06:11

here this body pressure will be not

play06:13

needed

play06:14

so we'll be removing this body pressure

play06:16

here um

play06:17

it will come as express

play06:22

the objection and instead of body

play06:25

pressure i'll just

play06:26

put x-rays

play06:26

[Music]

play06:30

good now the modification of the package

play06:33

digestion file is done

play06:34

so uh what what is going to be happening

play06:36

when we run the dev script then it will

play06:38

run the

play06:39

index.ts file inside the source

play06:41

directory here the directory is missing

play06:43

that's rc once you run the build script

play06:46

then the

play06:47

typescript will be compiled the whole

play06:48

source code and it will store inside the

play06:50

distribution directory so we can start

play06:51

our project uh um the compile source

play06:53

code

play06:54

by pointing to this script like npm

play06:56

start

play06:57

right all right so right after install

play06:59

the dependency then the

play07:00

the this script will be automatically

play07:02

run so what

play07:04

it will do like it will it will build it

play07:06

will run it this build script

play07:08

right so let's let's install the

play07:10

dependency mpm

play07:14

install

play07:16

okay so our installation is done but the

play07:19

compile is

play07:20

is filled because of this uh related to

play07:24

mongodb error

play07:25

right so what we are going to do uh it's

play07:27

a common error so

play07:28

i'm going to remove these things the

play07:30

type declaration file

play07:31

from here i'm going to install ibm

play07:34

install

play07:40

yes now it is all it is successfully

play07:43

installed

play07:44

let's delete this file delete this

play07:46

directory first

play07:47

we will run the this build script and

play07:50

npm run

play07:54

[Music]

play07:56

yeah that's good successfully we have we

play07:58

have successfully now uh

play08:00

built our project let's give a try to

play08:02

run this project

play08:03

npm

play08:06

yeah this is perfectly fine now it is

play08:08

our our js version is

play08:10

running all right so which is we have

play08:12

kept which is we have changed

play08:14

as a targeted version of es6 node

play08:16

support the es6 version

play08:18

that's good so um the

play08:21

basic things are done now what we need

play08:23

to do we need to configure our

play08:25

database file here because we are

play08:27

pointing this database file to our local

play08:28

repository local database

play08:30

so i'm going to just comment these

play08:32

things first here i'll be using cloud

play08:34

mongodb url

play08:35

so let's create an account here

play08:52

is

play09:10

all right so this is our database

play09:12

connection is done here uh go to

play09:14

index.ts file here instead of this port

play09:16

we will be adding something like in the

play09:17

configuration file

play09:19

right here in configuration file

play09:22

will be export launched

play09:27

put will be process dot

play09:31

environment dot port if

play09:34

a port is available on that the

play09:36

environment then it will come over here

play09:38

otherwise we will be listening to the

play09:39

default 8000 port

play09:41

right so this is we need to do

play09:44

next now just to go to the index.ts file

play09:47

here uh

play09:48

instead of this port we will be adding

play09:50

rd port

play09:51

and now um we'll be

play09:54

we'll be adding these things to inside

play09:56

the backtick so at least we can

play09:59

we can determine like what port it is

play10:01

running okay

play10:04

good now this is done um

play10:08

since everything is perfectly fine all

play10:10

database configuration also done

play10:14

good now we will commit all these

play10:16

changes whatever we have made right here

play10:26

and now let's create an app on huroku

play10:28

then this will be

play10:30

morocco first of all let's check it out

play10:32

like if i am logging or not

play10:38

and now let's create an app

play10:41

real cool create create

play10:46

app is creating yeah this is my happy

play10:49

world

play10:49

so what i'm going to do i'm going to

play10:51

push all these changes to heroku

play11:02

yeah that's a good sign our build is

play11:03

success now the application is available

play11:05

on this for

play11:06

this url uh now we have deployed

play11:08

successfully our our source code on the

play11:10

horoko

play11:10

now it is available on this this url

play11:13

also so it is simply saying

play11:15

it cannot get all right that's perfectly

play11:17

fine let's give a try these things from

play11:18

our postman

play11:20

sent here have you seen

play11:23

this is the response from the the server

play11:26

right

play11:26

so we are successfully able to create

play11:28

the uh the vendor so let's

play11:30

try to try to log in as a banner here

play11:37

right so login

play11:41

so as you can see now our application is

play11:43

running on the huroku

play11:44

i hope this is going to be helpful

play11:45

helpful for you so you can get the logs

play11:48

from here for getting log you need to

play11:49

use oracle locks that's the stale

play11:51

right so you can get the whole bunch of

play11:53

the the locks whatever it is happening

play11:55

in the server

play11:56

all right so and now it is perfectly

play11:58

working fine from our heroku server

play12:00

and so if suppose something is going to

play12:02

be changed let's say we are going to

play12:04

change something here

play12:05

uh listening to port on

play12:08

heroku heroku server

play12:11

[Music]

play12:13

if there's something exchanged or again

play12:15

you need to do publish then just

play12:17

simply do one thing get at

play12:28

yeah now it will go through the whole

play12:30

process as we have as we have edit right

play12:32

here

play12:32

and finally once this is done then it

play12:34

will it will start the server

play12:36

this piece of code will be gonna be

play12:37

execute where we can see the

play12:39

up and running server it will be

play12:41

available for us let's go

play12:48

yeah this is done now again check the

play12:50

locks from the hiroko here

play12:52

and then you will see like if this new

play12:54

changes has been done definitely will be

play12:56

it will be look for

play12:57

listening to report uh on heroku server

play13:00

the port number as you can see listening

play13:02

to port on your request server and

play13:04

port number is 55 868.

play13:08

uh that's good that's a good time so

play13:10

let's let's get back to our source code

play13:12

then we are what we are going to do

play13:14

we are going to change our our database

play13:16

url first

play13:17

because we need to work on the work on

play13:20

the order section

play13:25

let's continue with our our progress so

play13:27

we'll be working on the

play13:29

the customer route here we'll be

play13:30

handling our orders first right so let's

play13:32

move our order below payment

play13:34

here we'll be adding a couple of routes

play13:36

for order

play13:42

um in the controller uh customer

play13:44

controller

play13:46

go below here here we'll be creating

play14:02

so add these things here that will be

play14:04

our

play14:05

create order and

play14:09

here get orders get orders

play14:12

and here it will be

play14:16

[Music]

play14:17

get ordered by id right so it's hooked

play14:20

up properly

play14:22

now we'll be adding some code on the

play14:23

create order here in this section

play14:34

to create an order we need to grab the

play14:36

login customer first after that we will

play14:38

create an order id

play14:39

and then we will be uh grab the order

play14:41

items from the request that you

play14:42

requested

play14:43

mostly the request will be something

play14:45

like the id

play14:46

it will become with id and unit right

play14:49

and after that we will be calculating

play14:50

the order amount as per

play14:52

the available uh as party information

play14:54

available on the database

play14:56

then we will be creating an order with

play14:57

the item description and finally

play14:59

we will update the order to the user

play15:01

account and giving the response back

play15:03

all right so these are the things we

play15:04

need to do so let's uh let's dive into

play15:06

to get the get these tapes one by one

play15:28

somehow we need to grab the request body

play15:30

as a card and then

play15:32

but the card is kind of like it will be

play15:34

kind of array

play15:35

it's just similar to something like this

play15:38

okay

play15:38

so that is we need to do so for that

play15:40

thing what we will do here

play15:41

we are we are going to create a dto file

play15:43

inside the dto here

play15:56

so it will be technically it's a kind of

play15:58

like um order inputs

play16:00

right so all the orders we will grab

play16:02

right here

play16:03

now next what you need to do or we will

play16:05

be adding such a kind of

play16:08

array that's gonna be like card item

play16:12

card items and it will be array

play16:15

all right and net amount will be

play16:20

will be zero zero zero point zero zero

play16:24

now we need to calculate the amount here

play16:34

right so it is giving it is giving us a

play16:36

bunch of food so whatever available here

play16:38

whatever request that

play16:40

whatever we have requested on the card

play16:42

array then all foods are available here

play16:44

along with the

play16:45

the information additional information

play16:47

that means uh we are having a price in

play16:49

permission also

play16:50

here okay which is we have not

play16:52

considered from the request

play16:53

the price parameter considering from the

play16:54

request uh this is not a good idea

play16:57

if suppose uh instead of the actual

play16:59

price

play17:00

if someone is sending some different

play17:01

price then the whole calculation will be

play17:04

will be terribly wrong so

play17:07

now what you'll do here we will be

play17:09

comparing the specific food id

play17:11

with the request id if they bought the

play17:13

id is matching then we will be

play17:14

calculating the

play17:16

the total amount depends on the unit of

play17:18

the specific price

play17:19

so let's do these things

play17:44

so to create order we don't have a data

play17:46

model so that is we need to create here

play17:48

we're going to the model and we'll be

play17:50

creating order

play17:52

ts here i'm going to

play17:56

do a little bit quicker from just a copy

play17:58

distance from here

play17:59

then copy all those things paste it here

play18:02

and this is gonna be like our order dogs

play18:27

it

play18:54

okay

play19:08

is

play19:12

so we need to modify our customer model

play19:14

also here

play19:25

right so here in the customer model we

play19:27

will have some additional information

play19:29

that is going to be like you know we

play19:30

will have

play19:31

some orders also here and definitely

play19:34

it it will be kind of array and it will

play19:36

represent the order model

play19:38

good so it's saying your orders

play19:42

redeclare where we're using

play19:47

okay that's not an issue in the customer

play19:50

controller we need to

play19:52

add a couple of things here that is

play19:55

by default we need to provide orders

play19:58

orders initially we will

play19:59

we will just put in an empty array

play20:03

good all right here

play20:06

in the create order um

play20:23

so once we have created order

play20:24

successfully whether our current order

play20:27

has some value or not

play20:28

if it is not a possible then definitely

play20:31

we will be

play20:33

update our user here

play20:38

hello

play20:47

good so let's let's have a try with the

play20:50

creating order

play21:03

send a request yeah that's good so have

play21:06

you seen

play21:07

here we are getting the response right

play21:09

so this is our order id

play21:11

this is our order id and these are the

play21:14

items are available

play21:15

right this is one first item which is we

play21:17

have sand unit tree

play21:19

and this is our second item which is uh

play21:21

unit one and total amount is the

play21:23

560 and order date is this

play21:26

and pedro is the cod and

play21:30

yeah we do have a pretty much good

play21:31

amount of information right

play21:33

when you place the order then these are

play21:35

the information it is not required this

play21:37

is unnecessarily

play21:38

i mean it's it is getting back on server

play21:40

right so what we will do here

play21:42

uh will be right after placing the order

play21:46

um here

play21:48

[Music]

play21:50

this uh this profile response will have

play21:52

some data

play21:53

that is gonna be like orders yeah simply

play21:56

this is this is we will return

play21:59

now again i'm going to create one order

play22:01

and this time

play22:02

let's say one items

play22:05

per okay send yeah

play22:09

but again this is not meaningful all

play22:11

right so this is giving

play22:13

some data but only the ids so what do

play22:15

you will do here

play22:17

instead of returning the profile

play22:18

response order that only you will return

play22:20

this

play22:21

current order only okay this one

play22:24

the current order which is you're

play22:26

creating in here

play22:27

and definitely this is not required at

play22:30

all only we will be calling

play22:31

save if it is saved successfully then it

play22:34

will return the current order

play22:35

now now let's try once once more this

play22:38

time i'm going to order

play22:39

two item two units uh each now sandy

play22:43

permission yeah now it is meaningfully

play22:46

bit right

play22:47

it's only this specific ordering

play22:48

permission is available here

play22:50

that's good so create order is done now

play22:53

now we will be work on the get orders

play22:55

get order is nothing nothing special so

play22:58

what we need to do

play22:59

uh this is the same thing we we will be

play23:01

doing here

play23:03

first uh grab the current current

play23:06

customer

play23:19

let's go to check the getters

play23:20

functionality also here in customer role

play23:23

we are using orders

play23:24

it's a get call

play23:28

yeah that's good all right so we have

play23:30

the three orders available here

play23:32

and next we need to take care of the

play23:35

order by id

play23:36

so this functionality also will be

play23:39

pretty much the same

play23:53

here in in the order in the order model

play23:55

we have

play23:56

we have items specific items array also

play23:58

have a food

play23:59

so we are just populating the food also

play24:01

from here by

play24:02

assigning this way populate items dot

play24:05

food

play24:06

so once you are grabbing that specific

play24:08

order information then we are returning

play24:09

back to the client

play24:10

let's have a try with the get order by

play24:12

id functionality also here

play24:14

all right so we are grabbing we will be

play24:16

we will grab this already copy

play24:21

and view order by id

play24:25

here we will be use this already wow

play24:28

great

play24:29

have you seen here we are getting all

play24:31

the informations available for that

play24:33

specific order

play24:34

so this is our order id and these are

play24:36

the items that

play24:37

exist inside the order now our order

play24:39

section also clear

play24:41

in the upcoming episode we will be

play24:42

working on a microservices architecture

play24:44

where we will be splitting up our

play24:45

modules to microservices

play24:47

so a lot of advanced stuff we need to do

play24:49

right there so

play24:50

see you in the next episode and happy

play24:52

new year

Rate This

5.0 / 5 (0 votes)

関連タグ
Node.jsHeroku DeploymentMicroservicesDevOpsDockerizationCI/CDTypeScriptProject ManagementCloud ServicesSoftware Development
英語で要約が必要ですか?