Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 16 additions & 11 deletions src/fibRoute.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
// Endpoint for querying the fibonacci numbers
// Endpoint for querying the fibonacci numbers.
import { Request, Response } from 'express';
import { fibonacci } from './fib';

const fibonacci = require("./fib");
export default function fibonacciHandler(req: Request, res: Response): void {
const numStr: string = req.params.num;
const num: number = parseInt(numStr, 10);

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

const fibN = fibonacci(parseInt(num));
let result = `fibonacci(${num}) is ${fibN}`;

if (fibN < 0) {
result = `fibonacci(${num}) is undefined`;
// Check if the parsed number is valid
if (isNaN(num)) {
res.status(400).send('Invalid number provided');
return;
}

const fibN: number = fibonacci(num);
const result: string = fibN < 0
? fibonacci(${num}) is undefined

Check failure on line 17 in src/fibRoute.ts

View workflow job for this annotation

GitHub Actions / test

',' expected.

Check failure on line 17 in src/fibRoute.ts

View workflow job for this annotation

GitHub Actions / test

':' expected.

Check failure on line 17 in src/fibRoute.ts

View workflow job for this annotation

GitHub Actions / test

',' expected.
: fibonacci(${num}) is ${fibN};

Check failure on line 18 in src/fibRoute.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected keyword or identifier.

Check failure on line 18 in src/fibRoute.ts

View workflow job for this annotation

GitHub Actions / test

A type predicate is only allowed in return type position for functions and methods.

Check failure on line 18 in src/fibRoute.ts

View workflow job for this annotation

GitHub Actions / test

Declaration or statement expected.

Check failure on line 18 in src/fibRoute.ts

View workflow job for this annotation

GitHub Actions / test

')' expected.

Check failure on line 18 in src/fibRoute.ts

View workflow job for this annotation

GitHub Actions / test

',' expected.

res.send(result);
};
}
Loading