Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

boilerpress-route-sequelize

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

boilerpress-route-sequelize

Express auto routes for sequelize

  • 2.0.1
  • unpublished
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

boilerpress-route-sequelize

Boilerpress route resources for sequelize

npm install --save boilerpress-route-sequelize

Restful API Design

Creates restful routes based on your sequelize models.

Data Structure:

{
  prefix: '/api/v1',
  models, // The object of all sequelize models
  use(req, res, next) {

    // Put any middleware requirements you need here
    if (
      req.headers['x-service-token'] &&
      req.headers['x-service-token'] === 'abc123'
    ) {
      return next();
    }

    // Lock down any records that belong to the logged in user
    if (req.bp.childModelName) {
      req.bp.childSequelizeOptions.where = {
        ...get(req, 'bp.childSequelizeOptions.where', {}),
        [req.bp.childModelName === 'accounts' ? 'id' : 'accountId']: req.user.account.id,
      };
    } else {
      req.bp.sequelizeOptions.where = {
        ...get(req, 'bp.sequelizeOptions.where', {}),
        [req.bp.modelName === 'accounts' ? 'id' : 'accountId']: req.user.account.id,
      };
    }
    return next();
  },
}

Example url

http://localhost:3000/api/v1/users?attributes=id,accountId&where={"id":3}&include=[{"model":"accounts", "attributes": ["id","name"], "where":{"id":1}}]&order=[["id", "desc"]]

FAQs

Package last updated on 16 Mar 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc