-
Notifications
You must be signed in to change notification settings - Fork 0
/
view_investment.js
82 lines (58 loc) · 2.89 KB
/
view_investment.js
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
document.addEventListener("DOMContentLoaded", async()=>{
const investmentList= document.getElementById("investments-list");
try{
const investorId= sessionStorage.getItem("sid");
const URL=`http://localhost:8188/investments/id/${investorId}`;
// console.log(URL);
const response= await fetch(URL);
if(!response.ok){
throw new Error("Failed to fetch data");
}
const data= await response.json();
// console.log(data[0]);
const fundsResponse= await fetch("http://localhost:8188/mutualfunds/");
const fundNames= new Map();
const fundData=await fundsResponse.json();
// console.log(fundData);
fundData.forEach(fund => {
fundNames.set(fund.fundId, fund.fundName);
});
// console.log(fundNames);
data.forEach(investment => {
const row=document.createElement("tr");
const fundIdCell= document.createElement("td");
fundIdCell.textContent= fundNames.get(investment.fundId);
row.appendChild(fundIdCell);
const amountInvestedCell=document.createElement("td");
amountInvestedCell.textContent= `Rs ${investment.amountInvested}`;
row.appendChild(amountInvestedCell);
const transactionTypeCell= document.createElement("td");
transactionTypeCell.textContent=investment.transactionType;
transactionTypeCell.style.color= (transactionTypeCell.textContent=="BUY" ? "green" :"red" );
row.appendChild(transactionTypeCell);
const dateOfInvestmentCell=document.createElement("td");
dateOfInvestmentCell.textContent=investment.dateOfInvestment;
row.appendChild(dateOfInvestmentCell);
let view_btn= document.createElement("a")
view_btn.innerText="View";
view_btn.href=`view_transaction.html?id=${investment.investmentId}`;
view_btn.className="btn-invest";
row.appendChild(view_btn);
// let buy_btn= document.createElement("a")
// buy_btn.innerText="Invest More";
// buy_btn.href=`investnow.html?id=${investment.fundId}`;
// buy_btn.className="btn-invest";
// buy_btn.style.margin="10px";
// // buy_btn.style.padding="10px 20px";
// let redeem_btn= document.createElement("a")
// redeem_btn.innerText="Redeem";
// redeem_btn.href=`redeem_investment.html?id=${investment.investmentId}`;
// redeem_btn.className="btn-invest";
// redeem_btn.style.margin="10px";
// transactionTypeCell.textContent=="BUY" ? row.appendChild(redeem_btn) : row.appendChild(buy_btn) ;
investmentList.appendChild(row);
});
} catch(error){
console.error("Error fetching data: ", error);
}
});