async function post(req, res) {
  const {
    ruleModel = new models.Rule(),
    dbClient = await getKnexClient(),
    rulePgModel = new RulePgModel(),
  } = req.testContext || {};

  let record;
  const apiRule = req.body || {};
  const name = apiRule.name;

  if (await ruleModel.exists(name)) {
    return res.boom.conflict(`A record already exists for ${name}`);
  }

  try {
    apiRule.createdAt = Date.now();
    apiRule.updatedAt = Date.now();

    // Create rule trigger
    const ruleWithTrigger = await ruleModel.createRuleTrigger(apiRule);
    const postgresRule = await translateApiRuleToPostgresRule(ruleWithTrigger, dbClient);

    await dbClient.transaction(async (trx) => {
      await rulePgModel.create(trx, postgresRule);
      record = await ruleModel.create(ruleWithTrigger);
    });
    if (inTestMode()) await addToLocalES(record, indexRule);
    return res.send({ message: 'Record saved', record });
  } catch (error) {
    if (isBadRequestError(error)) {
      return res.boom.badRequest(error.message);
    }
    log.error('Error occurred while trying to create rule:', error);
    return res.boom.badImplementation(error.message);
  }
}
/**
 * Creates a new rule
 *
 * @param {Object} req - express request object
 * @param {Object} res - express response object
 * @returns {Promise<Object>} the promise of express response object
 */
Creates a new rule
@param {Object} req - express request object
@param {Object} res - express response object
@returns {Promise} the promise of express response object
Creates a new rule @param { Object } req - express request object @param { Object } res - express response object @returns { Promise } the promise of express response object
async function post(req, res) {
  const {
    ruleModel = new models.Rule(),
    dbClient = await getKnexClient(),
    rulePgModel = new RulePgModel(),
  } = req.testContext || {};
  let record;
  const apiRule = req.body || {};
  const name = apiRule.name;
  if (await ruleModel.exists(name)) {
    return res.boom.conflict(`A record already exists for ${name}`);
  }
  try {
    apiRule.createdAt = Date.now();
    apiRule.updatedAt = Date.now();
    const ruleWithTrigger = await ruleModel.createRuleTrigger(apiRule);
    const postgresRule = await translateApiRuleToPostgresRule(ruleWithTrigger, dbClient);
    await dbClient.transaction(async (trx) => {
      await rulePgModel.create(trx, postgresRule);
      record = await ruleModel.create(ruleWithTrigger);
    });
    if (inTestMode()) await addToLocalES(record, indexRule);
    return res.send({ message: 'Record saved', record });
  } catch (error) {
    if (isBadRequestError(error)) {
      return res.boom.badRequest(error.message);
    }
    log.error('Error occurred while trying to create rule:', error);
    return res.boom.badImplementation(error.message);
  }
}
async function post ( req , res ) { const { ruleModel = new models . Rule ( ) , dbClient = await getKnexClient ( ) , rulePgModel = new RulePgModel ( ) , } = req . testContext || { } ; let record ; const apiRule = req . body || { } ; const name = apiRule . name ; if ( await ruleModel . exists ( name ) ) { return res . boom . conflict ( ` ${ name } ` ) ; } try { apiRule . createdAt = Date . now ( ) ; apiRule . updatedAt = Date . now ( ) ; const ruleWithTrigger = await ruleModel . createRuleTrigger ( apiRule ) ; const postgresRule = await translateApiRuleToPostgresRule ( ruleWithTrigger , dbClient ) ; await dbClient . transaction ( async ( trx ) => { await rulePgModel . create ( trx , postgresRule ) ; record = await ruleModel . create ( ruleWithTrigger ) ; } ) ; if ( inTestMode ( ) ) await addToLocalES ( record , indexRule ) ; return res . send ( { message : 'Record saved' , record } ) ; } catch ( error ) { if ( isBadRequestError ( error ) ) { return res . boom . badRequest ( error . message ) ; } log . error ( 'Error occurred while trying to create rule:' , error ) ; return res . boom . badImplementation ( error . message ) ; } }
Creates a new rule
 @param {Object} req - express request object
 @param {Object} res - express response object
 @returns {Promise<Object>} the promise of express response object
Creates a new rule @param { Object } req - express request object @param { Object } res - express response object @returns { Promise<Object > } the promise of express response object
// Create rule trigger