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

      const { organizationId, query, type } = params
      Joi.validate({ organizationId, query }, validationRules.searchTeam, function (err) {
        if (err) {
          return cb(Boom.badRequest(err))
        }

        const sqlQuery = SQL`
          SELECT *
          FROM teams
          WHERE org_id=${organizationId}
          AND (
        `
        if (!type || type === 'default') {
          sqlQuery.append(SQL`
            to_tsvector(name) || to_tsvector(description) @@ to_tsquery(${utils.toTsQuery(query)})
              OR name LIKE(${'%' + query + '%'})
          `)
        } else if (type === 'exact') {
          sqlQuery.append(SQL`
            name = ${query}
          `)
        }

        sqlQuery.append(SQL`)
          ORDER BY id;
        `)

        db.query(sqlQuery, (err, result) => {
          if (err) return cb(Boom.badImplementation(err))
          return cb(null, result.rows.map(mapping.team), result.rows.length)
        })
      })

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

      const { organizationId, query, type } = params
      Joi.validate({ organizationId, query }, validationRules.searchTeam, function (err) {
        if (err) {
          return cb(Boom.badRequest(err))
        }

        const sqlQuery = SQL`
          SELECT *
          FROM teams
          WHERE org_id=${organizationId}
          AND (
        `
        if (!type || type === 'default') {
          sqlQuery.append(SQL`
            to_tsvector(name) || to_tsvector(description) @@ to_tsquery(${utils.toTsQuery(query)})
              OR name LIKE(${'%' + query + '%'})
          `)
        } else if (type === 'exact') {
          sqlQuery.append(SQL`
            name = ${query}
          `)
        }

        sqlQuery.append(SQL`)
          ORDER BY id;
        `)

        db.query(sqlQuery, (err, result) => {
          if (err) return cb(Boom.badImplementation(err))
          return cb(null, result.rows.map(mapping.team), result.rows.length)
        })
      })

      return promise
    }
function search ( params , cb ) { let promise = null if ( typeof cb !== 'function' ) [ promise , cb ] = asyncify ( 'data' , 'total' ) const { organizationId , query , type } = params Joi . validate ( { organizationId , query } , validationRules . searchTeam , function ( err ) { if ( err ) { return cb ( Boom . badRequest ( err ) ) } const sqlQuery = SQL ` ${ organizationId } ` if ( ! type || type === 'default' ) { sqlQuery . append ( SQL ` ${ utils . toTsQuery ( query ) } ${ '%' + query + '%' } ` ) } else if ( type === 'exact' ) { sqlQuery . append ( SQL ` ${ query } ` ) } sqlQuery . append ( SQL ` ` ) db . query ( sqlQuery , ( err , result ) => { if ( err ) return cb ( Boom . badImplementation ( err ) ) return cb ( null , result . rows . map ( mapping . team ) , result . rows . length ) } ) } ) return promise }
Search for team

@param {Object} params { organizationId, query }
@param {Function} cb
Search for team