packages/udaru-core/lib/ops/policyOps.js
function updatePolicy (params, cb) {
      let promise = null
      if (typeof cb !== 'function') [promise, cb] = asyncify()

      const { id, organizationId, version, name, statements } = params

      Joi.validate({ id, organizationId, version, name, statements }, validationRules.updatePolicy, function (err) {
        if (err) return cb(Boom.badRequest(err))

        const sqlQuery = SQL`
          UPDATE policies
          SET
            version = ${version},
            name = ${name},
            statements = ${statements}
          WHERE
            id = ${id}
            AND org_id = ${organizationId}
        `
        db.query(sqlQuery, function (err, result) {
          if (utils.isUniqueViolationError(err)) return cb(Boom.conflict(err.detail))
          if (err) return cb(Boom.badImplementation(err))
          if (result.rowCount === 0) return cb(Boom.notFound())

          policyOps.readPolicy({ id, organizationId }, cb)
        })
      })

      return promise
    }
function updatePolicy (params, cb) {
      let promise = null
      if (typeof cb !== 'function') [promise, cb] = asyncify()

      const { id, organizationId, version, name, statements } = params

      Joi.validate({ id, organizationId, version, name, statements }, validationRules.updatePolicy, function (err) {
        if (err) return cb(Boom.badRequest(err))

        const sqlQuery = SQL`
          UPDATE policies
          SET
            version = ${version},
            name = ${name},
            statements = ${statements}
          WHERE
            id = ${id}
            AND org_id = ${organizationId}
        `
        db.query(sqlQuery, function (err, result) {
          if (utils.isUniqueViolationError(err)) return cb(Boom.conflict(err.detail))
          if (err) return cb(Boom.badImplementation(err))
          if (result.rowCount === 0) return cb(Boom.notFound())

          policyOps.readPolicy({ id, organizationId }, cb)
        })
      })

      return promise
    }
function updatePolicy ( params , cb ) { let promise = null if ( typeof cb !== 'function' ) [ promise , cb ] = asyncify ( ) const { id , organizationId , version , name , statements } = params Joi . validate ( { id , organizationId , version , name , statements } , validationRules . updatePolicy , function ( err ) { if ( err ) return cb ( Boom . badRequest ( err ) ) const sqlQuery = SQL ` ${ version } ${ name } ${ statements } ${ id } ${ organizationId } ` db . query ( sqlQuery , function ( err , result ) { if ( utils . isUniqueViolationError ( err ) ) return cb ( Boom . conflict ( err . detail ) ) if ( err ) return cb ( Boom . badImplementation ( err ) ) if ( result . rowCount === 0 ) return cb ( Boom . notFound ( ) ) policyOps . readPolicy ( { id , organizationId } , cb ) } ) } ) return promise }
Update policy values

@param  {Object}   params { id, organizationId, version, name, statements }
@param  {Function} cb
Update policy values