2023-04-23 12:11:26 +02:00
|
|
|
"use strict";
|
2017-02-18 20:14:10 +01:00
|
|
|
|
2023-04-23 12:11:26 +02:00
|
|
|
const expect = require("chai").expect;
|
|
|
|
const ConvertHandler = require("../controllers/convertHandler.js");
|
2017-02-18 20:14:10 +01:00
|
|
|
|
|
|
|
module.exports = function (app) {
|
Fix (Boilerplate): Add Event Parameter to test, Remove Infosec Requriements, Add Lowercase Requirement (#12)
* Fix missing event, correct example conversion
* Fix unit case
* Remove Infosec items, add lowercase requirement
* Convert to ES6, Update Packages, Fix display
* Applying @nhcarrigan's changes from site tests
* Removed unneeded mongodb ref
* Remove User Stories, Reformat README
* Apply suggestions from code review - Remove "Quality Assurance Project" Prefix
Co-authored-by: Shaun Hamilton <51722130+Sky020@users.noreply.github.com>
* Re-add the example text, clean up formatting
* Update Favicon
* Fix repo link, remove zombie.js
* Remove unused files, add sample.env
Co-authored-by: Shaun Hamilton <51722130+Sky020@users.noreply.github.com>
Co-authored-by: Rex Schrader <rex.schader@gmail.com>
2020-11-25 16:09:04 +01:00
|
|
|
let convertHandler = new ConvertHandler();
|
2023-04-23 12:11:26 +02:00
|
|
|
app.route("/api/convert").get((req, res) => {
|
|
|
|
const input = req.query.input;
|
|
|
|
if (
|
|
|
|
input &&
|
|
|
|
convertHandler.getUnit(input) &&
|
|
|
|
convertHandler.getNum(input)
|
|
|
|
) {
|
|
|
|
const initNum = convertHandler.getNum(input);
|
|
|
|
const initUnit = convertHandler.getUnit(input);
|
|
|
|
const returnNum = Number(
|
|
|
|
convertHandler.convert(initNum, initUnit)?.toFixed(5)
|
|
|
|
);
|
|
|
|
const returnUnit = convertHandler.getReturnUnit(initUnit);
|
|
|
|
const string = convertHandler.getString(
|
|
|
|
initNum,
|
|
|
|
initUnit,
|
|
|
|
returnNum,
|
|
|
|
returnUnit
|
|
|
|
);
|
|
|
|
res.json({
|
|
|
|
initNum: initNum,
|
|
|
|
initUnit: initUnit,
|
|
|
|
returnNum: returnNum,
|
|
|
|
returnUnit: returnUnit,
|
|
|
|
string: string,
|
|
|
|
});
|
|
|
|
} else if (
|
|
|
|
!convertHandler.getUnit(input) &&
|
|
|
|
!convertHandler.getNum(input)
|
|
|
|
) {
|
|
|
|
console.log(`1: ${input}`);
|
|
|
|
res.send("invalid number and unit");
|
|
|
|
} else if (!convertHandler.getUnit(input)) {
|
|
|
|
console.log(`2: ${input}`);
|
|
|
|
res.send("invalid unit");
|
|
|
|
} else if (!convertHandler.getNum(input)) {
|
|
|
|
console.log(`3: ${input}`);
|
|
|
|
res.send("invalid number");
|
|
|
|
}
|
|
|
|
});
|
2017-02-18 20:14:10 +01:00
|
|
|
};
|