packages/udaru-core/lib/ops/organizationOps.js
function create (params, opts, cb) {
      if (!cb) {
        cb = opts
      }
      if (!opts || typeof opts === 'function') {
        opts = {}
      }

      let promise = null
      if (typeof cb !== 'function') [promise, cb] = asyncify()

      const { createOnly } = opts

      const tasks = [
        (job, next) => {
          const id = params.id || uuid()
          params.id = id
          const { name, description, metadata, user } = params

          Joi.validate({ id, name, description, metadata, user }, validationRules.create, (err) => {
            if (err) return next(Boom.badRequest(err))
            next()
          })
        },
        (job, next) => {
          job.params = params
          job.user = params.user
          next()
        },
        insertOrganization
      ]

      if (!createOnly) {
        tasks.push(
          createDefaultPolicies,
          insertOrgAdminUser
        )
      }

      db.withTransaction(tasks, (err, res) => {
        if (err) return cb(err)

        organizationOps.readById(res.organization.id, (err, organization) => {
          if (err) return cb(Boom.badImplementation(err))

          cb(null, { organization, user: res.user })
        })
      })

      return promise
    }
function create (params, opts, cb) {
      if (!cb) {
        cb = opts
      }
      if (!opts || typeof opts === 'function') {
        opts = {}
      }

      let promise = null
      if (typeof cb !== 'function') [promise, cb] = asyncify()

      const { createOnly } = opts

      const tasks = [
        (job, next) => {
          const id = params.id || uuid()
          params.id = id
          const { name, description, metadata, user } = params

          Joi.validate({ id, name, description, metadata, user }, validationRules.create, (err) => {
            if (err) return next(Boom.badRequest(err))
            next()
          })
        },
        (job, next) => {
          job.params = params
          job.user = params.user
          next()
        },
        insertOrganization
      ]

      if (!createOnly) {
        tasks.push(
          createDefaultPolicies,
          insertOrgAdminUser
        )
      }

      db.withTransaction(tasks, (err, res) => {
        if (err) return cb(err)

        organizationOps.readById(res.organization.id, (err, organization) => {
          if (err) return cb(Boom.badImplementation(err))

          cb(null, { organization, user: res.user })
        })
      })

      return promise
    }
function create ( params , opts , cb ) { if ( ! cb ) { cb = opts } if ( ! opts || typeof opts === 'function' ) { opts = { } } let promise = null if ( typeof cb !== 'function' ) [ promise , cb ] = asyncify ( ) const { createOnly } = opts const tasks = [ ( job , next ) => { const id = params . id || uuid ( ) params . id = id const { name , description , metadata , user } = params Joi . validate ( { id , name , description , metadata , user } , validationRules . create , ( err ) => { if ( err ) return next ( Boom . badRequest ( err ) ) next ( ) } ) } , ( job , next ) => { job . params = params job . user = params . user next ( ) } , insertOrganization ] if ( ! createOnly ) { tasks . push ( createDefaultPolicies , insertOrgAdminUser ) } db . withTransaction ( tasks , ( err , res ) => { if ( err ) return cb ( err ) organizationOps . readById ( res . organization . id , ( err , organization ) => { if ( err ) return cb ( Boom . badImplementation ( err ) ) cb ( null , { organization , user : res . user } ) } ) } ) return promise }
Creates a new organization

@param  {Object}   params {id, name, description, metadata, user} "metadata" optional
@param  {Object}   opts { createOnly }
@param  {Function} cb
Creates a new organization