backend: Hotfix convertRomanToArabic + exports
This commit is contained in:
parent
2c61a22787
commit
84712eb251
@ -1,26 +1,25 @@
|
||||
const { randomNumberOutput } = require('./main/randomNumber');
|
||||
const { convertArabicToRomanOutput, convertRomanToArabicOutput } = require('./main/convertRomanArabicNumbers');
|
||||
const { convertDistanceOutput } = require('./main/convertDistance');
|
||||
const { convertTemperatureOutput } = require('./main/convertTemperature');
|
||||
const { armstrongNumberOutput } = require('./main/armstrongNumber');
|
||||
const { weatherRequestOutput } = require('./main/weatherRequest');
|
||||
const { convertCurrencyOutput } = require('./main/convertCurrency');
|
||||
const { calculateAgeOutput } = require('./main/calculateAge');
|
||||
const { heapAlgorithmOutput } = require('./main/heapAlgorithm');
|
||||
const { convertEncodingOutput } = require('./main/convertEncoding');
|
||||
const randomNumberOutput = require('./main/randomNumber');
|
||||
const convertRomanArabicNumbersOutput = require('./main/convertRomanArabicNumbers');
|
||||
const convertDistanceOutput = require('./main/convertDistance');
|
||||
const convertTemperatureOutput = require('./main/convertTemperature');
|
||||
const armstrongNumberOutput = require('./main/armstrongNumber');
|
||||
const weatherRequestOutput = require('./main/weatherRequest');
|
||||
const convertCurrencyOutput = require('./main/convertCurrency');
|
||||
const calculateAgeOutput = require('./main/calculateAge');
|
||||
const heapAlgorithmOutput = require('./main/heapAlgorithm');
|
||||
const convertEncodingOutput = require('./main/convertEncoding');
|
||||
|
||||
const functionObject = {
|
||||
randomNumber : randomNumberOutput,
|
||||
convertArabicToRoman: convertArabicToRomanOutput,
|
||||
convertRomanToArabic: convertRomanToArabicOutput,
|
||||
convertDistance : convertDistanceOutput,
|
||||
convertTemperature : convertTemperatureOutput,
|
||||
armstrongNumber : armstrongNumberOutput,
|
||||
weatherRequest : weatherRequestOutput,
|
||||
convertCurrency : convertCurrencyOutput,
|
||||
calculateAge : calculateAgeOutput,
|
||||
heapAlgorithm : heapAlgorithmOutput,
|
||||
convertEncoding : convertEncodingOutput
|
||||
randomNumber : randomNumberOutput,
|
||||
convertRomanArabicNumbers: convertRomanArabicNumbersOutput,
|
||||
convertDistance : convertDistanceOutput,
|
||||
convertTemperature : convertTemperatureOutput,
|
||||
armstrongNumber : armstrongNumberOutput,
|
||||
weatherRequest : weatherRequestOutput,
|
||||
convertCurrency : convertCurrencyOutput,
|
||||
calculateAge : calculateAgeOutput,
|
||||
heapAlgorithm : heapAlgorithmOutput,
|
||||
convertEncoding : convertEncodingOutput
|
||||
};
|
||||
|
||||
// Choisi la fonction à exécuter
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
|
@ -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 });
|
||||
}
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -1,7 +1,3 @@
|
||||
const timeNow = new Date();
|
||||
const utcOffset = timeNow.getTimezoneOffset();
|
||||
timeNow.setMinutes(timeNow.getMinutes() + utcOffset);
|
||||
|
||||
/**
|
||||
* @description Donne la date et l'heure selon l'UTC (Universal Time Coordinated).
|
||||
* @param {String} utc Heure de décalage par rapport à l'UTC
|
||||
@ -9,9 +5,12 @@ timeNow.setMinutes(timeNow.getMinutes() + utcOffset);
|
||||
* @examples dateTimeUTC('0')
|
||||
*/
|
||||
function dateTimeUTC(utc) {
|
||||
const timeNow = new Date();
|
||||
const utcOffset = timeNow.getTimezoneOffset();
|
||||
timeNow.setMinutes(timeNow.getMinutes() + utcOffset);
|
||||
const enteredOffset = parseFloat(utc)*60;
|
||||
timeNow.setMinutes(timeNow.getMinutes() + enteredOffset);
|
||||
return showDateTime(enteredOffset);
|
||||
return showDateTime(timeNow);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -21,7 +20,7 @@ function dateTimeUTC(utc) {
|
||||
* @returns {Object} Retourne un objet contenant l'année, le mois, le jour, l'heure, les minutes, les secondes et la date formaté
|
||||
* @examples dateTimeUTC('0') → dateTimeUTC vous renvoie l'exécution de showDateTime
|
||||
*/
|
||||
function showDateTime(enteredOffset) {
|
||||
function showDateTime(timeNow) {
|
||||
const year = timeNow.getFullYear();
|
||||
const month = ('0'+(timeNow.getMonth()+1)).slice(-2);
|
||||
const day = ('0'+timeNow.getDate()).slice(-2);
|
||||
@ -38,8 +37,7 @@ function showDateTime(enteredOffset) {
|
||||
second: second,
|
||||
showDateTimeValue: showDateTimeValue
|
||||
};
|
||||
timeNow.setMinutes(timeNow.getMinutes() - enteredOffset);
|
||||
return objectDateTime;
|
||||
}
|
||||
|
||||
module.exports = { showDateTime, dateTimeUTC };
|
||||
module.exports = dateTimeUTC;
|
Reference in New Issue
Block a user