-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathq2.ts
36 lines (29 loc) · 914 Bytes
/
q2.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// const axios = require("axios");
import axios from "axios";
/* assign interface/type to the function definition properly */
const getTodo = async (todoId: number) => {
try{
const res = await axios.get(`https://jsonplaceholder.typicode.com/todos/${todoId}`);
const todo = res.data;
const userID = todo.userId;
const userres = await axios.get(`https://jsonplaceholder.typicode.com/users/${userID}`);
const userdata = userres.data;
const result = {
owner: userdata.name,
title: todo.title,
completed: todo.completed,
};
return result;
} catch(err){
return 'INVALID TODO ID';
}
};
//test case
const input1 = 15;
const input2 = 60;
const input3 = 250;
//run
getTodo(input1).then((result) => console.log(result));
getTodo(input2).then((result) => console.log(result));
getTodo(input3).then((result) => console.log(result));
export default getTodo;