Code Monkey home page Code Monkey logo

crud-node's Introduction

Authentication & Authorization

/api/register (POST)

  • Registeration

    • Create Routes

      • Controllers
    • validate Request ( Joi npm package)

      {
          "name":"mayur",
          "email": "[email protected]",
          "password":"878t8gshbyxu28u2",
          "repeat_password":"878t8gshbyxu28u2"
      }
      
  • Autherize Request

  • check if User exist

  • create model User-> ( name*, email*, password* , role(customer) )

  • store in DB

  • generate JWT Token ( jsonwebtoken npm package, {payload, JWT_SECRET, expiry})

  • Send Response (access_token)

/api/login (POST)

/api/me (Get)

  • gives details of user, require access_token

  • Create middleWare for Authentication

    -header
    Autherization: Bearer <access_token>
    
  • Generating Refresh token : On Registration & Login

/api/refresh (POST)

  • Creating End Point to get new access_token by sending refresh_token

    {
      "refresh_token": "<refresh_token>"
    }
    

/api/logout (POST)

  • Create End Point to delete 'refresh_token' of user
  • access_token required in header, and refresh_token in body

CRUD

  • Create /api/products (POST)

    • Create Product Model( name*, price*, size*, image*)
    • using 'multer' for multipart data
    • files will be uploaded to folder named 'uploads'
    • fs (link, unlink) for handdling files
  • Read => get All

    • for large use pagination ( mongoose-pagination)

    • to get in some order, .sort({_id: -1}) sorts on descending order of id

      • Current all images don't have complete paths with server

        -> updating image attribute of ProductSchema of Product Model, and and one more property besides *timestamps\*
              image: { type: String, required: true, get: (image)=>{ return`{APP_URL}/${image}`;
              }}
              .
              .
              .
              {timestamps: true, *toJSON: {getters:true}*}
        
        -> update env
            APP_URL = http://localhost:5000
        
        -> Create upload api (to serve static file)
            app.use('/uploads', express.static('uploads'))
        

    => get Single

    • As id is duplicate in response , update ProductSchema, Add one more property besides timestamps {timestamps: true, toJSON: {getters:true}, *id:false*}
  • Update /api/products/<product_id> (PUT)

    • only authenticated admin can update , creating middleware for same
    • .findOneAndUpdate({}, {}, {})
  • Delete /api/producst/<product*id> (DELETE)

    • only authenticated admin can delete
    • .findOneAndRemove({})
    • const imagePath = document.*_doc_.image;

crud-node's People

Contributors

mayur290 avatar mayur290dj avatar

Watchers

James Cloos avatar  avatar

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.