-
Notifications
You must be signed in to change notification settings - Fork 1
/
call-all-apis.ts
62 lines (60 loc) · 1.97 KB
/
call-all-apis.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import { Api } from './src';
const { username, password } = process.env;
if (username === undefined) {
throw new Error(`Missing en var "username".`);
}
if (password === undefined) {
throw new Error(`Missing en var "password".`);
}
(async () => {
const api = new Api();
const { access_token: token } = await api.login({ username, password });
const user = await api.getMe({ token });
const userId = user.id;
const investProfileCategories = await api.getInvestProfileCategories({ token });
const investProfiles = await api.getInvestProfiles({ token });
const userCoupons = await api.getUserCoupons({ token, userId });
const coupons = await api.getCoupons({ token, userId });
const userKycs = await api.getUserKycs({ token, userId });
const availableProducts = await Promise.all(
userKycs['hydra:member'].map(({ id }) =>
api.getAvailableProducts({ token, userKycsId: parseInt(id, 10) })
)
);
const advices = await Promise.all(
userKycs['hydra:member'].map(({ advice }) =>
api.getAdvice({ token, adviceId: parseInt(advice.id, 10) })
)
);
const userFinancialCapitals = await Promise.all(
user.investmentAccounts.map(({ id }) =>
api.getUserFinancialCapital({ token, userInvestmentAccountId: parseInt(id, 10) })
)
);
const userInvestmentValuesInput = await Promise.all(
user.investmentAccounts.map(({ id }) =>
api.getUserInvestmentValuesInput({ token, userInvestmentAccountId: parseInt(id, 10) })
)
);
const userInvestmentAccountProducts = await Promise.all(
user.investmentAccounts.map(({ id }) =>
api.getUserInvestmentAccountProducts({ token, userInvestmentAccountId: parseInt(id, 10) })
)
);
console.log({
investProfileCategories,
investProfiles,
user,
userCoupons,
coupons,
userKycs,
availableProducts,
advices,
userFinancialCapitals,
userInvestmentValuesInput,
userInvestmentAccountProducts,
});
})().catch((e) => {
console.error(e);
process.exit(-1);
});