-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathq2.ts
30 lines (26 loc) · 893 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
//660612162 อภิชา เลิศจินตนกิจ
// const axios = require("axios");
import axios from "axios";
/* assign interface/type to the function definition properly */
const getTodo = async (todoId: number) => {
try {
const result = await axios.get("https://jsonplaceholder.typicode.com/todos/${todoId}");
const result2 = await axios.get("https://jsonplaceholder.typicode.com/users/${result.data.userId}");
return {
owner: result2.data.name,
title: result.data.title,
completed: result.data.completed
}
} 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;