Socket
Book a DemoInstallSign in
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
Package was removed
Sorry, it seems this package was removed from the registry

boilerpress-route-sequelize

Express auto routes for sequelize

unpublished
latest
Source
npmnpm
Version
2.0.2
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}&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