-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestB.ts
More file actions
41 lines (35 loc) · 973 Bytes
/
testB.ts
File metadata and controls
41 lines (35 loc) · 973 Bytes
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
37
38
39
40
41
// Implementation B
import APICaller from "./src/api/APICaller";
import APIPayload from "./src/api/types/APIPayload";
import UserInfo from "./src/api/UserInfo/types/UserInfo";
import UserStatus from "./src/api/UserInfo/types/UserStatus";
import UserType from "./src/api/UserInfo/types/UserType";
// API Adapter file
const API = new APICaller();
interface UserInfoPayload extends APIPayload {
body: UserInfo;
}
const userAPI = {
info: <APIPayload> {
url: "/api/user/info",
method: "GET",
},
activate: <UserInfoPayload> {
url: "/api/user/activate",
method: "POST",
body: <UserInfo> {},
}
}
Object.freeze(userAPI);
// Store/usage
const userInfo = await API.fetch<UserInfo>(userAPI.info);
console.log(userInfo.data.user_id);
const activateUser = await API.fetch<UserInfo>({
...userAPI.activate,
body: {
user_id: 1,
user_status: UserStatus.Active,
user_type: UserType.Solo
},
});
console.log(activateUser.data.user_status);