Skip to content

Commit 51baacb

Browse files
committed
Work on Monthly report page for premium user
1 parent 5e29b8e commit 51baacb

File tree

3 files changed

+12
-32
lines changed

3 files changed

+12
-32
lines changed

controllers/user_controller.js

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ module.exports.getLeaderboardUser = async (req, res) => {
169169
} catch (err) {
170170
console.log(err);
171171
}
172+
//pending task - we have to send the sorted data from here backend only
172173
};
173174

174175
//send sorted data from backend - pending wqtch sir video
@@ -206,7 +207,7 @@ module.exports.dailyReports = async (req, res) => {
206207
try {
207208
const date = req.body.date;
208209
const expenses = await Expense.findAll({
209-
where: { date: date, userId: req.user.id },
210+
where: { date: date, userId: req.user.id }
210211
});
211212
return res.send(expenses);
212213
} catch (error) {
@@ -218,15 +219,8 @@ module.exports.monthlyReports = async (req, res) => {
218219
try {
219220
const month = req.body.month;
220221
const expenses = await Expense.findAll({
221-
where: {
222-
date: {
223-
[sequelize.like]: `%-${month}-%`,
224-
},
225-
userId: req.user.id,
226-
},
227-
raw: true,
222+
where: { date: { [sequelize.Op.like]: `%-${month}-%`, }, userId: req.user.id, } //, raw: true,
228223
});
229-
230224
return res.send(expenses);
231225
} catch (error) {
232226
console.log(error);

public/js/reports.js

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,13 @@ async function getDailyReport(e) {
1717
e.preventDefault();
1818
const date = new Date(dateInput.value);
1919
const formattedDate = `${date.getDate().toString().padStart(2, "0")}-${(
20-
date.getMonth() + 1
21-
)
22-
.toString()
23-
.padStart(2, "0")}-${date.getFullYear()}`;
20+
date.getMonth() + 1).toString().padStart(2, "0")}-${date.getFullYear()}`;
2421

2522
let totalAmount = 0;
26-
const res = await axios.post(
27-
"http://localhost:9000/user/dailyReports",
28-
{
29-
date: formattedDate,
30-
}
31-
// ,{ headers: { Authorization: token } }
23+
const res = await axios.post("http://localhost:9000/user/dailyReports", { date: formattedDate }
3224
);
3325

26+
// for empty the previous data
3427
tbodyDaily.innerHTML = "";
3528
tfootDaily.innerHTML = "";
3629

@@ -64,8 +57,8 @@ async function getDailyReport(e) {
6457
tr.setAttribute("class", "trStyle");
6558
tfootDaily.appendChild(tr);
6659

67-
const td1 = document.createElement("td");
68-
const td2 = document.createElement("td");
60+
const td1 = document.createElement("td"); // no use but make for balancing colums
61+
const td2 = document.createElement("td"); // no use but make for balancing colums
6962
const td3 = document.createElement("td");
7063
const td4 = document.createElement("td");
7164

@@ -88,18 +81,11 @@ monthShowBtn.addEventListener("click", getMonthlyReport);
8881
async function getMonthlyReport(e) {
8982
try {
9083
e.preventDefault();
91-
// const token = localStorage.getItem("token");
9284
const month = new Date(monthInput.value);
93-
const formattedMonth = `${(month.getMonth() + 1)
94-
.toString()
95-
.padStart(2, "0")}`;
85+
const formattedMonth = `${(month.getMonth() + 1).toString().padStart(2, "0")}`;
9686

9787
let totalAmount = 0;
98-
const res = await axios.post(
99-
"http://localhost:9000/user/monthlyReports",
100-
{
101-
month: formattedMonth,
102-
}
88+
const res = await axios.post("http://localhost:9000/user/monthlyReports", { month: formattedMonth }
10389
// ,{ headers: { Authorization: token } }
10490
);
10591

public/views/reports.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ <h3>DAILY REPORTS</h3>
6969
<form>
7070
<div class="mb-3">
7171
<label for="date" class="form-label"> Select Date</label>
72-
<input type="date" class="form-control" id="date" />
72+
<input type="date" class="form-control" id="date" required />
7373
</div>
7474
<button id="dateShowBtn" type="submit" class="btn btn-primary showBtn">Show</button>
7575
</form>
@@ -117,7 +117,7 @@ <h3>MONTHLY REPORTS</h3>
117117
<form>
118118
<div class="mb-3">
119119
<label for="month" class="form-label">Select Month</label>
120-
<input type="month" class="form-control" id="month" />
120+
<input type="month" class="form-control" id="month" required />
121121
</div>
122122
<button id="monthShowBtn" type="submit" class="btn btn-primary showBtn">Show</button>
123123
</form>

0 commit comments

Comments
 (0)