let models = require('../../models');
let Boom = require('boom');
let {
  async,
  await
} = require('asyncawait');

const all = (request, reply) => {
  let key = request.params.key;
  const getVisits = async (() => {
    let campaign = await (models.Campaign.find({
      where: {
        key
      }
    }));
    if (campaign)
      return await (models.Visit.findAll({
        where: {
          CampaignId: campaign.id
        }
      }));
    else
      return [];
  });
  getVisits()
    .then((visits) => {
      reply(visits).code(200);
    });
};

const post = (request, reply) => {
  let {
    visit
  } = request.payload;
  let key = request.params.key;
  const newVisit = async (() => {
    let campaign = await (models.Campaign.find({
      where: {
        key
      }
    }));
    if (campaign) {
      visit.CampaignId = campaign.id;
      return await (models.Visit.create(visit));
    } else {
      return null;
    }
  });
  if (campaign) {
    visit.CampaignId = campaign.id;
    return await (models.Visit.create(visit));
  } else {
    return null;
  }
  newVisit()
    .then((visit) => {
      reply(visit).code(200);
    })
    .catch((error) => {
      reply(Boom.badImplementation());
    });
};

module.exports = {
  all,
  post
};
@@ -940,141 +940,8 @@
 %7D);%0A
-  if (campaign) %7B%0A    visit.CampaignId = campaign.id;%0A    return await (models.Visit.create(visit));%0A  %7D else %7B%0A    return null;%0A  %7D%0A
   ne

fix visits post