<commit_before>import axios from 'axios';

/**
 * API request: create a reference
 * @param {object} reference - reference to save
 * @returns Promise<Reference> - saved reference
 */
export async function create(reference) {
  const { data: responseReference } = await axios.post(
    '/api/experiences',
    reference,
  );
  return responseReference;
}

/**
 * API request: read references, filter them by userTo,
 * and sort by 'created' field starting from the most recent date
 *
 * @param {string} userTo - id of user who received the reference
 * @returns {array} - array of the found references
 */
export async function read({ userTo }) {
  const { data: references } = await axios.get('/api/experiences', {
    params: { userTo },
  });
  return references;
}

/**
 * API request: read references written by loggedIn user, filter them by userTo,
 * and sort by 'created' field starting from the most recent date
 *
 * @param {string} userTo - id of user who received the reference
 * @returns {object} - A reference
 */
export async function readMine({ userTo }) {
  const params = { userTo };
  try {
    const { data: reference } = await axios.get('/api/my-experience', {
      params,
    });
    return reference;
  } catch (err) {
    if (err.response?.status === 404) {
      return null;
    } else {
      throw err;
    }
  }
}

/**
 * API request: report a member
 * @TODO this request belongs to a different module
 * @param {object} user - member to report
 * @param {string} message - message to administrators
 * @returns Promise<void>
 */
export async function report(user, message) {
  await axios.post('/api/support', { message, reportMember: user.username });
}

/**
 * API request: get count of references
 *
 * @param {string} userTo - id of user who received the reference
 * @returns {object} - Number of experiences as `{count: Int, hasPending: Bool}`
 */
export async function getCount(userTo) {
  try {
    const { data } = await axios.get('/api/experiences/count', {
      params: { userTo },
    });
    return data;
  } catch {
    return { count: 0 };
  }
}<commit_msg>references -> experiences: rename api client code and jsdocs (#1996)<commit_after>import axios from 'axios';

/**
 * API request: create an experience
 * @param {object} experience - experience to save
 * @returns {object} - saved experience object, which includes the "response" to it if exists
 */
export async function create(experience) {
  const { data: responseExperience } = await axios.post(
    '/api/experiences',
    experience,
  );
  return responseExperience;
}

/**
 * API request: read experiences shared with `userTo`;
 * sorted by `created` field starting from the most recent date
 *
 * @param {string} userTo - id of the user with whom the experiences were shared
 * @returns {array} - array of experience objects, which include the "responses" to them where exist
 */
export async function read({ userTo }) {
  const { data: experiences } = await axios.get('/api/experiences', {
    params: { userTo },
  });
  return experiences;
}

/**
 * API request: read the experience shared by the logged-in user with `userTo`
 *
 * @param {string} userTo - id of the user with whom the experience was shared
 * @returns {object} - experience object, which includes the "response" to it if exists
 */
export async function readMine({ userTo }) {
  const params = { userTo };
  try {
    const { data: experience } = await axios.get('/api/my-experience', {
      params,
    });
    return experience;
  } catch (err) {
    if (err.response?.status === 404) {
      return null;
    } else {
      throw err;
    }
  }
}

/**
 * API request: report a member
 * @TODO this request belongs to a different module
 * @param {object} user - member to report
 * @param {string} message - message to administrators
 * @returns Promise<void>
 */
export async function report(user, message) {
  await axios.post('/api/support', { message, reportMember: user.username });
}

/**
 * API request: get count of experiences
 *
 * @param {string} userTo - id of the user with whom the experiences were shared
 * @returns {object} - Number of experiences as `{count: Int, hasPending: Bool}`
 */
export async function getCount(userTo) {
  try {
    const { data } = await axios.get('/api/experiences/count', {
      params: { userTo },
    });
    return data;
  } catch {
    return { count: 0 };
  }
}
{'fraction_non_alphanumeric': 0.12167990919409762, 'fraction_numerical': 0.002724177071509648, 'mean_word_length': 3.294346978557505, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2759414', 'n_tokens_mistral': 1272, 'n_tokens_neox': 1255, 'n_words': 480}