Giter Site home page Giter Site logo

food_order_app's Introduction

food_order_app

PART 1


git clone empty repo -> cd foldername -> npm init -> (package.json is made )

tsc --init (to have tsconfig file)

created index.ts in Main folder

dont forget to add scripts to package.json file for index.ts


Created Directories

  • utility
  • services
  • routes
  • models
  • middlewares
  • images
  • images
  • dto
  • controllers
  • config

We created two routes AdminRoute and VandorRoute in routes Folder

Then we moved to contollers Folder to control AdminRoute and inside AdminControll.ts we created three functions that are
CreateVandor : for posting data
GetVandor : for getting all vandors
GetVandorbyID : getting vandor by ID


Then in AdminRoute.ts we created routes

  • router.post('/vandor',CreateVandor)
  • router.post('/vandors',GetVandor )
  • router.post('/vandor/:id',GetVandorbyID)

Now we moved to dto folder (Data Transfer Object)

We created Vandor Interface (you can say class)


For fetching data from url we will use body-parser in main file


Then we completed CreateVandor function in AdminControl.ts file

image

Creating Model

  • Installed mongoose dependencies npm i mongoose @types/mongoose
  • Inside Vandor Scema foods field is an array of object ids , basciaaly its forein key from Food Table

    It's an array of objects, where each object is expected to be of type mongoose.Schema.ObjectId and is referring to the "food" model (specified by ref: "food")


    image

    Creating a vandor in AdminController.ts , checking if it already exists and using salt excrypting the password

    A Password utility is made inside utility folder where generating salt and hashing is done.

    Install below first :

  • npm i bcrypt
  • npm i --save-dev @types/bcrypt
  • Removing password and salt and createdAt and such things while sending as JSON

    image
    JSON MESSAGE
    image
    MONGO DB
    image

    As you can see now we are not able to see the password in JSON format which is good for security purpose , but in database they all are stored , so hacker will not be able to acess password or salt from json response as we have removed it .

    20 dec 23

  • sucessfully created model and applied only one user entry , hased password using bcrypt and salt , and removed password and salt field from JSON message

  • PART 2

    Storing helper classes in utility folder if data is not available or incorrect

    Completed getVandors , getvandorById

    Working on Vandor route

    image image image image

    Use of JWT in utility/Password.ts

    The signature verification process involves the use of a secret key that only the server knows. The key is used to sign the JWT when it is created and to verify the signature when the JWT is presented to the server. The signature is a cryptographic hash generated using this secret key and the content of the JWT (header and payload).


    image
  • Token Generated

  • Verifying signature
  • Made Auth.dto.ts
  • image

    In payload variable we are able to acess id , name , email , foodTypes


    image
  • Middleware CommonAuth
  • image

    Checking if Signature is Validated or Not

  • First Login using Email and Password

  • image
  • Copy the Token generated below

  • image
  • Go to Folders three dot and click Edit

  • image
  • Go to Authorization tab

  • image
  • Select Type as Bearer Token and paste the copied token below it
  • This will help to make that user validated and under this folder every request can access this token to verify
  • Now Click on Save button

  • image
  • In vandor profile set option of Authorization as bearer Token
  • Now go to Vandor Profile Request and clear the body as its a Get request and if the user is authenticated it will show us user details
  • If not validated We will see json message as:{"message":"User not authorized (Authenticate)"}

  • image

    PART 3

    Adding food functionality

  • First Login > copy token > VANDOR folder > edit > choose Bearer Token , add token without " " > Click Save > and now do the below thing

  • image image

    Adding Iamges using Multer Library

    Multer is a node.js middleware for handling multipart/form-data, which is primarily used for uploading files

    image # PART 4

    Adding Images to Database

  • npm i multer -> npm i @types/multer : it handles file upload functionality
  • Recommend Projects

    • React photo React

      A declarative, efficient, and flexible JavaScript library for building user interfaces.

    • Vue.js photo Vue.js

      ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

    • Typescript photo Typescript

      TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

    • TensorFlow photo TensorFlow

      An Open Source Machine Learning Framework for Everyone

    • Django photo Django

      The Web framework for perfectionists with deadlines.

    • D3 photo D3

      Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

    Recommend Topics

    • javascript

      JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

    • web

      Some thing interesting about web. New door for the world.

    • server

      A server is a program made to process requests and deliver data to clients.

    • Machine learning

      Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

    • Game

      Some thing interesting about game, make everyone happy.

    Recommend Org

    • Facebook photo Facebook

      We are working to build community through open source technology. NB: members must have two-factor auth.

    • Microsoft photo Microsoft

      Open source projects and samples from Microsoft.

    • Google photo Google

      Google โค๏ธ Open Source for everyone.

    • D3 photo D3

      Data-Driven Documents codes.