packages/udaru-core/lib/ops/teamOps.js
function createTeam (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, name, description, metadata, parentId, organizationId, user } = params

          // We should not use boom but return specific errors that will be then handled out side the udaru.js module
          Joi.validate({ id, name, description, metadata, parentId, organizationId, user }, validationRules.createTeam, (err) => {
            if (err) return next(Boom.badRequest(err))
            next()
          })
        },
        (job, next) => {
          job.params = params
          next()
        },
        insertTeam
      ]
      if (!createOnly) {
        tasks.push(
          createDefaultPolicies,
          createDefaultUser,
          makeDefaultUserAdmin,
          assignDefaultUserToTeam
        )
      }

      db.withTransaction(tasks, (err, res) => {
        if (err) return cb(err)
        teamOps.readTeam({ id: res.team.id, organizationId: params.organizationId }, cb)
      })

      return promise
    }
function createTeam (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, name, description, metadata, parentId, organizationId, user } = params

          // We should not use boom but return specific errors that will be then handled out side the udaru.js module
          Joi.validate({ id, name, description, metadata, parentId, organizationId, user }, validationRules.createTeam, (err) => {
            if (err) return next(Boom.badRequest(err))
            next()
          })
        },
        (job, next) => {
          job.params = params
          next()
        },
        insertTeam
      ]
      if (!createOnly) {
        tasks.push(
          createDefaultPolicies,
          createDefaultUser,
          makeDefaultUserAdmin,
          assignDefaultUserToTeam
        )
      }

      db.withTransaction(tasks, (err, res) => {
        if (err) return cb(err)
        teamOps.readTeam({ id: res.team.id, organizationId: params.organizationId }, cb)
      })

      return promise
    }
function createTeam ( 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 , name , description , metadata , parentId , organizationId , user } = params // We should not use boom but return specific errors that will be then handled out side the udaru.js module Joi . validate ( { id , name , description , metadata , parentId , organizationId , user } , validationRules . createTeam , ( err ) => { if ( err ) return next ( Boom . badRequest ( err ) ) next ( ) } ) } , ( job , next ) => { job . params = params next ( ) } , insertTeam ] if ( ! createOnly ) { tasks . push ( createDefaultPolicies , createDefaultUser , makeDefaultUserAdmin , assignDefaultUserToTeam ) } db . withTransaction ( tasks , ( err , res ) => { if ( err ) return cb ( err ) teamOps . readTeam ( { id : res . team . id , organizationId : params . organizationId } , cb ) } ) return promise }
Creates a new team

@param  {Object}   params { id, name, description, metadata, parentId, organizationId, user } "metadata" optoinal
@param  {Object}   opts { createOnly }
@param  {Function} cb
Creates a new team