Skip to content

Commit

Permalink
fixed the any and require errors in the fibRoute file
Browse files Browse the repository at this point in the history
  • Loading branch information
jdufitum committed Sep 1, 2024
1 parent f4de0a6 commit 8353dd3
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions src/fibRoute.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import { Request, Response } from "express";
import { fibonacci } from "./fib";

// Endpoint for querying the Fibonacci numbers
export default (req: Request, res: Response) => {
const { num } = req.params as { num: string };


// import fib
// export default function that takes in req, res
// get num from req.params



export default (req, res) => {
const { num }: { num: string } = req.params;

const fibN: number = fibonacci(parseInt(num));
let result: string = "fibonacci(${num}) is ${fibN}";

if (fibN < 0) {
result = `fibonacci(${num}) is undefined`;
const parsedNum = parseInt(num);
if (parsedNum < 0) {
res.send(`fibonacci(${num}) is undefined`);
return;
}

res.send(result);
};
try {
const fibN: number = fibonacci(parsedNum);
const result = `fibonacci(${num}) is ${fibN}`;
res.send(result);
} catch (error) {
const err = error as Error;
res.status(400).send(`Error: ${err.message}`);
}
};

0 comments on commit 8353dd3

Please sign in to comment.