backend: Hotfix convertRomanToArabic + exports

This commit is contained in:
Divlo
2020-03-24 17:02:30 +01:00
parent 2c61a22787
commit 84712eb251
12 changed files with 69 additions and 54 deletions

View File

@ -28,7 +28,7 @@ function armstrongNumber(number) {
}
/* OUTPUTS */
exports.armstrongNumberOutput = ({ res, next }, argsObject) => {
module.exports = armstrongNumberOutput = ({ res, next }, argsObject) => {
let { number } = argsObject;
// S'il n'y a pas les champs obligatoire

View File

@ -20,7 +20,7 @@ function calculateAge(currentDate, { birthDateDay, birthDateMonth, birthDateYear
}
/* OUTPUTS */
exports.calculateAgeOutput = ({ res, next }, argsObject) => {
module.exports = calculateAgeOutput = ({ res, next }, argsObject) => {
let { birthDate } = argsObject;
// S'il n'y a pas les champs obligatoire

View File

@ -4,7 +4,7 @@ const { requiredFields } = require('../../config/errors');
const formatNumberResult = require('../secondary/formatNumberResult');
/* OUTPUTS */
exports.convertCurrencyOutput = ({ res, next }, argsObject) => {
module.exports = convertCurrencyOutput = ({ res, next }, argsObject) => {
let { number, baseCurrency, finalCurrency } = argsObject;
// S'il n'y a pas les champs obligatoire

View File

@ -28,7 +28,7 @@ function convertDistance(firstValue, unitFirstValue, unitFinalValue) {
}
/* OUTPUTS */
exports.convertDistanceOutput = ({ res, next }, argsObject) => {
module.exports = convertDistanceOutput = ({ res, next }, argsObject) => {
let { number, numberUnit, finalUnit } = argsObject;
// S'il n'y a pas les champs obligatoire

View File

@ -214,12 +214,11 @@ function hexadecimalToText (s) {
/* OUTPUTS */
const convertEncoding = { decimalToBinary, binaryToDecimal, decimalToHexadecimal, hexadecimalToDecimal, binaryToHexadecimal, hexadecimalToBinary, textToNumberUnicode, numberUnicodeToText, textToBinary, binaryToText, textToHexadecimal, hexadecimalToText };
function executeFunction(option, value) {
return convertEncoding[option](value);
}
exports.convertEncodingOutput = ({ res, next }, argsObject) => {
module.exports = convertEncodingOutput = ({ res, next }, argsObject) => {
let { value, functionName } = argsObject;
// S'il n'y a pas les champs obligatoire
@ -227,9 +226,9 @@ exports.convertEncodingOutput = ({ res, next }, argsObject) => {
return errorHandling(next, requiredFields);
}
// Si la fonction de convertEncoding n'existe pas
// Si la fonction n'existe pas
if (!convertEncoding.hasOwnProperty(functionName)) {
return errorHandling(next, { message: "Cette conversion de convertEncoding n'existe pas." });
return errorHandling(next, { message: "Cette conversion n'existe pas.", statusCode: 400 });
}
const result = executeFunction(functionName, value);

View File

@ -1,5 +1,6 @@
const errorHandling = require('../../utils/errorHandling');
const { requiredFields, generalError } = require('../../config/errors');
const formatNumberResult = require('../secondary/formatNumberResult');
/* Variable pour convertRomanArabicNumbers */
const correspondancesRomainArabe = [
@ -20,7 +21,6 @@ const correspondancesRomainArabe = [
/**
* @description Convertis un nombre arabe en nombre romain.
* @requires {@link correspondancesRomainArabe}
* @param {Number} nombre - Le nombre arabe à convertir
* @returns {String}
* @examples convertArabicToRoman(24) → 'XXIV'
@ -45,14 +45,13 @@ function convertArabicToRoman(nombre) {
/**
* @description Convertis un nombre romain en nombre arabe.
* @requires {@link correspondancesRomainArabe}
* @param {String} str - Le nombre romain à convertir
* @returns {Number}
* @examples convertRomanToArabic('XXIV') → 24
*/
function convertRomanToArabic(str) {
let result = 0;
for (let i = 0;i < correspondancesRomainArabe.length; i++) {
for (let i = 0; i < correspondancesRomainArabe.length; i++) {
while (str.indexOf(correspondancesRomainArabe[i][1]) === 0) {
// Ajout de la valeur décimale au résultat
result += correspondancesRomainArabe[i][0];
@ -67,27 +66,25 @@ function convertRomanToArabic(str) {
}
/* OUTPUTS */
exports.convertRomanToArabicOutput = ({ res, next }, argsObject) => {
let { romanNumber } = argsObject;
const convertRomanToArabicOutput = ({ res, next }, number) => {
// S'il n'y a pas les champs obligatoire
if (!(romanNumber)) {
if (!(number)) {
return errorHandling(next, requiredFields);
}
// Formate le paramètre
romanNumber = romanNumber.toUpperCase();
number = number.toUpperCase();
const result = convertRomanToArabic(romanNumber);
const result = convertRomanToArabic(number);
if (result === 0) {
return errorHandling(next, generalError);
}
return res.status(200).json({ result });
return res.status(200).json({ result, resultHTML: `<p><span class="important">${number}</span> s'écrit <span class="important">${result}</span> en chiffres arabes.</p>` });
}
exports.convertArabicToRomanOutput = ({ res, next }, argsObject) => {
let { number } = argsObject;
const convertArabicToRomanOutput = ({ res, next }, number) => {
// S'il n'y a pas les champs obligatoire
if (!(number)) {
@ -100,5 +97,27 @@ exports.convertArabicToRomanOutput = ({ res, next }, argsObject) => {
return errorHandling(next, { message: "Veuillez rentré un nombre valide.", statusCode: 400 });
}
return res.status(200).json({ result: convertArabicToRoman(number) });
const result = convertArabicToRoman(number);
return res.status(200).json({ result, resultHTML: `<p><span class="important">${formatNumberResult(number)}</span> s'écrit <span class="important">${result}</span> en chiffres romains.</p>` });
}
const convertRomanArabicObject = { convertRomanToArabicOutput, convertArabicToRomanOutput };
function executeFunction(option, value, { res, next }) {
return convertRomanArabicObject[option]({ res, next}, value);
}
module.exports = convertRomanArabicNumbersOutput = ({ res, next }, argsObject) => {
let { value, functionName } = argsObject;
// S'il n'y a pas les champs obligatoire
if (!(value && functionName)) {
return errorHandling(next, requiredFields);
}
// Si la fonction n'existe pas
if (!convertRomanArabicObject.hasOwnProperty(functionName)) {
return errorHandling(next, { message: "Cette conversion n'existe pas.", statusCode: 400 });
}
executeFunction(functionName, value, { res, next });
}

View File

@ -27,7 +27,7 @@ function convertTemperature(degree, unit) {
}
/* OUTPUTS */
exports.convertTemperatureOutput = ({ res, next }, argsObject) => {
module.exports = convertTemperatureOutput = ({ res, next }, argsObject) => {
let { degree, unitToConvert } = argsObject;
// S'il n'y a pas les champs obligatoire

View File

@ -28,7 +28,7 @@ function heapAlgorithm(string) {
}
/* OUTPUTS */
exports.heapAlgorithmOutput = ({ res, next }, argsObject) => {
module.exports = heapAlgorithmOutput = ({ res, next }, argsObject) => {
let { string } = argsObject;
// S'il n'y a pas les champs obligatoire

View File

@ -14,7 +14,7 @@ function randomNumber(min, max) {
}
/* OUTPUTS */
exports.randomNumberOutput = ({ res, next }, argsObject) => {
module.exports = randomNumberOutput = ({ res, next }, argsObject) => {
let { min, max } = argsObject;
// S'il n'y a pas les champs obligatoire

View File

@ -3,7 +3,7 @@ const Queue = require('smart-request-balancer');
const errorHandling = require('../../utils/errorHandling');
const { requiredFields } = require('../../config/errors');
const { WEATHER_API_KEY } = require('../../config/config');
const { dateTimeUTC } = require('../secondary/dateTimeManagement');
const dateTimeUTC = require('../secondary/dateTimeManagement');
const capitalize = require('../secondary/capitalize');
const queue = new Queue({
@ -22,7 +22,7 @@ const queue = new Queue({
});
/* OUTPUTS */
exports.weatherRequestOutput = ({ res, next }, argsObject) => {
module.exports = weatherRequestOutput = ({ res, next }, argsObject) => {
let { cityName } = argsObject;
// S'il n'y a pas les champs obligatoire