How to use the baucis.Controller function in baucis

To help you get started, we’ve selected a few baucis examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github wprl / baucis-swagger / index.js View on Github external
// __Dependencies__
var baucis = require('baucis');
var deco = require('deco');
var decorators = deco.require(__dirname, [ 'Controller', 'Api' ]).hash;

baucis.Controller.decorators(decorators.Controller);
baucis.Api.decorators(decorators.Api);
github capaj / Moonridge / utils / baucis.js View on Github external
'use strict'
const debug = require('debug')('moonridge:baucis')
const baucis = require('baucis')
require('baucis-swagger')

const mapVerbToOperation = {
  POST: 'create',
  GET: 'read',
  PUT: 'update',
  DELETE: 'remove'
}

baucis.Controller.decorators(function (options, protect) {
  var controller = this
  const model = controller.model()
  const mrOpts = model.moonridgeOpts
  controller.request(function (request, response, next) {
    // expects request.moonridge to be something like {user: {privilege_level: 30}}
    debug(request.method)
    const operation = mapVerbToOperation[request.method]
    let errWhileCheckingPermissions
    try {
      mrOpts.checkPermission(request, operation)
    } catch (err) {
      errWhileCheckingPermissions = err
    }
    debug('errWhileCheckingPermissions ', errWhileCheckingPermissions)
    if (errWhileCheckingPermissions) {
      return response.status(403).send(baucis.Error.Forbidden(`You lack a privilege to ${request.method} ${model.modelName} collection`))

baucis

Build scalable REST APIs using the open source tools and standards you already know.

MIT
Latest version published 1 year ago

Package Health Score

46 / 100
Full package analysis