// eslint-disable-next-line import/prefer-default-export
export const addVote = async (feetBack, pageId) => {
  const votedUser = feetBack ? 1 : 0;
  try {
    const response = await fetch(`${process.env.GATSBY_API_URL}/sites/v0.1/page-votes`, {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
      },
      body: JSON.stringify({
        page_id: pageId,
        vote: votedUser,
      }),
    });
    const data = await response.json();
    return data;
  } catch (err) {
    console.error(err);
  }
};
