All files / services/beetranslate information.js

76.47% Statements 13/17
26.66% Branches 4/15
100% Functions 2/2
76.47% Lines 13/17

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45              1x 1x 1x   1x 1x   1x   1x                     1x 1x 1x 1x 1x   1x                      
import axios from 'axios';
import APIError from '../../helpers/error';
import { t } from '../../helpers/i18n';
import SettingsInformation from '../../source/settings/information';
import config from '../../../config/config';
 
async function fetchTranslates(updatedAt = '') {
  try {
    const dbUrl = await SettingsInformation.getSettingCode('beetranslateHost');
    const url = dbUrl || config.beetranslateHost;
 
    const params = new URLSearchParams();
    params.append('updatedAt', updatedAt);
 
    const response = await axios.get(url, { params: { updatedAt } });
 
    return response.data;
  } catch (err) {
    const workplaceErr = err.response && err.response.data && err.response.data;
    throw new APIError(
      '',
      t('BEE2929', { 0: workplaceErr || err } /* Erro na requisição: %{0} */)
    );
  }
}
 
async function getKey(key) {
  try {
    const dbUrl = await SettingsInformation.getSettingCode('beetranslateHost');
    const url = dbUrl || config.beetranslateHost;
    const urlApi = `${url}/${key}`;
    const response = await axios.get(urlApi);
 
    return response.data;
  } catch (err) {
    const workplaceErr = err.response && err.response.data && err.response.data;
    throw new APIError(
      '',
      t('BEE2929', { 0: workplaceErr || err } /* Erro na requisição: %{0} */)
    );
  }
}
 
export default { fetchTranslates, getKey };