static/js/records.js (view raw)
1document.addEventListener('DOMContentLoaded', function () {
2 loadRecords();
3
4 document.getElementById('new-record').addEventListener('click', function () {
5 createNewRecord();
6 });
7});
8
9const casino = {
10 type: 'Arbitraggio',
11 description: 'Prova',
12 date: fixDate(new Date()),
13 entries: [
14 {
15 bookmaker_id: 1,
16 account_id: 1,
17 amount: 97500,
18 refund: 0,
19 bonus: 0,
20 commission: 0,
21 sub_entries: [
22 {
23 description: "Punta",
24 odds: 200,
25 won: false,
26 }
27 ]
28 },
29 {
30 bookmaker_id: 2,
31 account_id: 2,
32 amount: 100000,
33 refund: 0,
34 bonus: 0,
35 commission: 0,
36 sub_entries: [
37 {
38 description: "Banca",
39 odds: 195,
40 won: true,
41 }
42 ]
43 },
44 ]
45};
46
47const bank = {
48 type: 'Bancata',
49 description: 'Prova',
50 date: fixDate(new Date()),
51 entries: [
52 {
53 bookmaker_id: 1,
54 account_id: 1,
55 amount: 3000,
56 refund: 0,
57 bonus: 0,
58 commission: 0,
59 sub_entries: [
60 {
61 description: "Punta",
62 odds: 133,
63 won: true,
64 }
65 ]
66 },
67 {
68 bookmaker_id: 3,
69 account_id: 2,
70 amount: 3057,
71 refund: 0,
72 bonus: 0,
73 commission: 450,
74 sub_entries: [
75 {
76 description: "Banca",
77 odds: 135,
78 won: false,
79 }
80 ]
81 },
82 ]
83};
84
85function loadRecords() {
86 getRecords().then(records => {
87 const header = document.getElementById('records-header');
88 const table = document.getElementById('records-table');
89 header.innerHTML = '';
90 table.innerHTML = '';
91
92 const tr = document.createElement('tr');
93 const headers = ["Created", "Done", "Type", "Description", "Date", "Value"];
94
95 for (const header of headers) {
96 const td = document.createElement('td');
97 td.innerText = header;
98 tr.appendChild(td);
99 }
100 header.appendChild(tr);
101
102 for (const record of records) {
103 const tr = document.createElement('tr');
104
105 const fields = [
106 formatDate(record.created_at),
107 record.done,
108 record.type,
109 record.description,
110 formatDate(record.date),
111 formatCash(record.value),
112 ];
113
114 for (const field of fields) {
115 const td = document.createElement('td');
116 td.innerText = field;
117 tr.appendChild(td);
118 }
119 table.appendChild(tr);
120 }
121 });
122}
123
124
125
126function createNewRecord() {
127 const recordStr = JSON.stringify(casino);
128 console.log(recordStr);
129
130 fetch('/api/records', {
131 method: 'POST',
132 headers: {
133 'Content-Type': 'application/json'
134 },
135 body: recordStr
136 }).then(response => response.json())
137 .then(() => loadRecords());
138}