|
1 |
| -const { |
2 |
| - Debit, |
3 |
| - Credit, |
4 |
| - User, |
5 |
| - Sequelize, |
6 |
| -} = require('../../database/models'); |
| 1 | +const { Debit, Credit, User, Sequelize } = require('../../database/models'); |
7 | 2 |
|
8 |
| -const order = [ |
9 |
| - ['date', 'DESC'], |
10 |
| -]; |
| 3 | +const order = [['date', 'DESC']]; |
11 | 4 |
|
12 | 5 | class DebitsService {
|
13 | 6 | async index(startDate, endDate, userId) {
|
| 7 | + console.log('startDate: ', startDate); |
| 8 | + console.log('endDate: ', endDate); |
| 9 | + console.log('userId: ', userId); |
| 10 | + |
14 | 11 | const newEndDate = new Date(endDate);
|
| 12 | + console.log('newEndDate: ', newEndDate); |
15 | 13 | newEndDate.setDate(newEndDate.getDate() + 1);
|
| 14 | + console.log('newEndDate after add: ', newEndDate); |
16 | 15 |
|
17 | 16 | const where = {
|
18 | 17 | user_id: userId,
|
19 | 18 | date: {
|
20 | 19 | [Sequelize.Op.and]: {
|
21 | 20 | [Sequelize.Op.gte]: startDate,
|
22 |
| - [Sequelize.Op.lte]: newEndDate, |
23 |
| - }, |
24 |
| - }, |
| 21 | + [Sequelize.Op.lte]: newEndDate |
| 22 | + } |
| 23 | + } |
25 | 24 | };
|
26 | 25 |
|
| 26 | + console.log('Going to access database!'); |
| 27 | + |
27 | 28 | const debit = await Debit.findAll({ where, order });
|
28 | 29 |
|
29 | 30 | return debit;
|
@@ -85,16 +86,20 @@ class DebitsService {
|
85 | 86 |
|
86 | 87 | async getAllByCurrentMonth(userId) {
|
87 | 88 | const currentDay = new Date();
|
88 |
| - const firstDayCurrentMonth = new Date(currentDay.getFullYear(), currentDay.getMonth(), 1); |
| 89 | + const firstDayCurrentMonth = new Date( |
| 90 | + currentDay.getFullYear(), |
| 91 | + currentDay.getMonth(), |
| 92 | + 1 |
| 93 | + ); |
89 | 94 |
|
90 | 95 | const where = {
|
91 | 96 | user_id: userId,
|
92 | 97 | date: {
|
93 | 98 | [Sequelize.Op.and]: {
|
94 | 99 | [Sequelize.Op.gte]: firstDayCurrentMonth,
|
95 |
| - [Sequelize.Op.lte]: currentDay, |
96 |
| - }, |
97 |
| - }, |
| 100 | + [Sequelize.Op.lte]: currentDay |
| 101 | + } |
| 102 | + } |
98 | 103 | };
|
99 | 104 |
|
100 | 105 | const debits = await Debit.findAll({ where, order });
|
|
0 commit comments