Query for transactions from first of month

Signed-off-by: William Brawner <me@wbrawner.com>
This commit is contained in:
William Brawner 2020-07-03 15:13:52 +00:00
parent f880c108dc
commit ed6fa0d8a0
4 changed files with 47 additions and 19 deletions

View file

@ -89,7 +89,12 @@ export class BudgetDetailsComponent implements OnInit {
}
getTransactions(): void {
this.twigsService.getTransactions(this.budget.id, null, 5)
let date = new Date();
date.setHours(0);
date.setMinutes(0);
date.setSeconds(0);
date.setDate(1);
this.twigsService.getTransactions(this.budget.id, null, 5, date)
.subscribe(transactions => this.transactions = <Transaction[]>transactions);
}
@ -134,7 +139,12 @@ export class BudgetDetailsComponent implements OnInit {
getCategoryBalance(category: number): Observable<number> {
return Observable.create(subscriber => {
this.twigsService.getTransactions(this.budget.id, category).subscribe(transactions => {
let date = new Date();
date.setHours(0);
date.setMinutes(0);
date.setSeconds(0);
date.setDate(1);
this.twigsService.getTransactions(this.budget.id, category, null, date).subscribe(transactions => {
let balance = 0;
for (const transaction of transactions) {
if (transaction.expense) {

View file

@ -34,7 +34,7 @@ export class TwigsHttpService implements TwigsService {
// };
// return this.http.post<User>(this.apiUrl + '/users/login', params, this.options);
const credentials = btoa(`${email}:${password}`)
this.cookieService.set( 'Authorization', credentials, 14);
this.cookieService.set('Authorization', credentials, 14);
return this.getProfile();
}
@ -70,7 +70,7 @@ export class TwigsHttpService implements TwigsService {
'description': description,
'users': users.map(user => {
return {
user: user.user,
user: user.user,
permission: Permission[user.permission]
};
})
@ -105,7 +105,7 @@ export class TwigsHttpService implements TwigsService {
'amount': amount,
'expense': isExpense,
'budgetId': budgetId
};
};
return this.http.post<Category>(this.apiUrl + '/categories/new', params, this.options);
}
@ -118,30 +118,38 @@ export class TwigsHttpService implements TwigsService {
}
// Transactions
getTransactions(budgetId?: number, categoryId?: number, count?: number): Observable<Transaction[]> {
getTransactions(
budgetId?: number,
categoryId?: number,
count?: number,
from?: Date
): Observable<Transaction[]> {
let httpParams = new HttpParams();
if (budgetId) {
httpParams = httpParams.set('budgetId', `${budgetId}`);
httpParams = httpParams.set('budgetIds', `${budgetId}`);
}
if (categoryId) {
httpParams = httpParams.set('categoryId', `${categoryId}`);
}
if (from) {
httpParams = httpParams.set('from', from.toISOString());
}
const params = { params: httpParams };
return this.http.get<Transaction[]>(`${this.apiUrl}/transactions`, Object.assign(params, this.options))
.pipe(map(transactions => {
transactions.forEach(transaction => {
transaction.date = new Date(transaction.date);
});
return transactions;
}));
.pipe(map(transactions => {
transactions.forEach(transaction => {
transaction.date = new Date(transaction.date);
});
return transactions;
}));
}
getTransaction(id: number): Observable<Transaction> {
return this.http.get<Transaction>(`${this.apiUrl}/transactions/${id}`, this.options)
.pipe(map(transaction => {
transaction.date = new Date(transaction.date);
return transaction;
}));
.pipe(map(transaction => {
transaction.date = new Date(transaction.date);
return transaction;
}));
}
createTransaction(

View file

@ -30,7 +30,12 @@ export interface TwigsService {
deleteCategory(budgetId: number, id: number): Observable<void>;
// Transactions
getTransactions(budgetId?: number, categoryId?: number, count?: number): Observable<Transaction[]>;
getTransactions(
budgetId?: number,
categoryId?: number,
count?: number,
from?: Date
): Observable<Transaction[]>;
getTransaction(id: number): Observable<Transaction>;
createTransaction(
budgetId: number,

View file

@ -32,7 +32,12 @@ export class TransactionsComponent implements OnInit {
}
getTransactions(): void {
this.twigsService.getTransactions(this.budgetId).subscribe(transactions => {
let date = new Date();
date.setHours(0);
date.setMinutes(0);
date.setSeconds(0);
date.setDate(1);
this.twigsService.getTransactions(this.budgetId, null, null, date).subscribe(transactions => {
this.transactions = transactions;
});
}