const {knex} = require('../util/database').connect();


const newComment = (action) =>  knex('comments').insert({
  user_id: action.client.id,
  feed_item_id: action.feedItemId,
  text: action.text,
})
.catch((err) => {
  if (err.constraint === 'comments_feed_item_id_foreign') {
    const error = new Error('No such feed item id');
    error.status = 400;
    throw error;
  }

  throw err;
});

export {
  newComment,
};

const {knex} = require('../util/database').connect();


const newComment = (action) =>  knex('comments').insert({
  user_id: action.client.id,
  feed_item_id: action.feedItemId,
  text: action.text,
})
.catch((err) => {
  if (err.constraint === 'comments_feed_item_id_foreign') {
    const error = new Error('No such feed item id');
    error.status = 404;
    throw error;
  }

  throw err;
});

export {
  newComment,
};

Return 404 instead of 400 when invalid feedItemId is provided
Return 404 instead of 400 when invalid feedItemId is provided

