Add recurring transaction methods to api service
This commit is contained in:
parent
484e0c8c75
commit
d6fbe06cab
3 changed files with 144 additions and 0 deletions
|
@ -5,6 +5,7 @@ import { Budget } from '../budgets/budget';
|
||||||
import { Category } from '../categories/category';
|
import { Category } from '../categories/category';
|
||||||
import { Transaction } from '../transactions/transaction';
|
import { Transaction } from '../transactions/transaction';
|
||||||
import { environment } from '../../environments/environment';
|
import { environment } from '../../environments/environment';
|
||||||
|
import { Frequency, RecurringTransaction } from '../recurringtransactions/recurringtransaction';
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root'
|
providedIn: 'root'
|
||||||
|
@ -245,6 +246,85 @@ export class TwigsHttpService implements TwigsService {
|
||||||
return this.request(url, HttpMethod.DELETE)
|
return this.request(url, HttpMethod.DELETE)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Recurring Transactions
|
||||||
|
async getRecurringTransactions(
|
||||||
|
budgetId?: string,
|
||||||
|
categoryId?: string,
|
||||||
|
count?: number,
|
||||||
|
from?: Date,
|
||||||
|
to?: Date
|
||||||
|
): Promise<RecurringTransaction[]> {
|
||||||
|
const url = new URL(`/api/recurringtransactions`, this.apiUrl)
|
||||||
|
if (budgetId) {
|
||||||
|
url.searchParams.set('budgetIds', budgetId);
|
||||||
|
}
|
||||||
|
if (categoryId) {
|
||||||
|
url.searchParams.set('categoryIds', categoryId);
|
||||||
|
}
|
||||||
|
if (from) {
|
||||||
|
url.searchParams.set('from', from.toISOString());
|
||||||
|
}
|
||||||
|
if (to) {
|
||||||
|
url.searchParams.set('to', to.toISOString());
|
||||||
|
}
|
||||||
|
const transactions: RecurringTransaction[] = await this.request(url, HttpMethod.GET)
|
||||||
|
transactions.forEach(transaction => {
|
||||||
|
transaction.frequency = Frequency.parse(transaction.frequency as any)
|
||||||
|
})
|
||||||
|
return transactions
|
||||||
|
}
|
||||||
|
|
||||||
|
async getRecurringTransaction(id: string): Promise<RecurringTransaction> {
|
||||||
|
const url = new URL(`/api/recurringtransactions/${id}`, this.apiUrl)
|
||||||
|
const transaction: RecurringTransaction = await this.request(url, HttpMethod.GET)
|
||||||
|
transaction.frequency = Frequency.parse(transaction.frequency as any)
|
||||||
|
return transaction
|
||||||
|
}
|
||||||
|
|
||||||
|
async createRecurringTransaction(
|
||||||
|
id: string,
|
||||||
|
budgetId: string,
|
||||||
|
name: string,
|
||||||
|
description: string,
|
||||||
|
amount: number,
|
||||||
|
frequency: Frequency,
|
||||||
|
start: Date,
|
||||||
|
expense: boolean,
|
||||||
|
category: string,
|
||||||
|
end?: Date,
|
||||||
|
): Promise<RecurringTransaction> {
|
||||||
|
const url = new URL(`/api/transactions`, this.apiUrl)
|
||||||
|
const body = {
|
||||||
|
'id': id,
|
||||||
|
'title': name,
|
||||||
|
'description': description,
|
||||||
|
'frequency': frequency.toString(),
|
||||||
|
'start': start.toISOString(),
|
||||||
|
'finish': end?.toISOString(),
|
||||||
|
'amount': amount,
|
||||||
|
'expense': expense,
|
||||||
|
'categoryId': category,
|
||||||
|
'budgetId': budgetId
|
||||||
|
};
|
||||||
|
const transaction: RecurringTransaction = await this.request(url, HttpMethod.POST, body)
|
||||||
|
transaction.frequency = Frequency.parse(transaction.frequency as any)
|
||||||
|
return transaction
|
||||||
|
}
|
||||||
|
|
||||||
|
async updateRecurringTransaction(id: string, transaction: RecurringTransaction): Promise<RecurringTransaction> {
|
||||||
|
const body: any = transaction;
|
||||||
|
body.frequency = transaction.frequency.toString()
|
||||||
|
const url = new URL(`/api/transactions/${id}`, this.apiUrl)
|
||||||
|
const updatedTransaction: RecurringTransaction = await this.request(url, HttpMethod.PUT, body)
|
||||||
|
updatedTransaction.frequency = Frequency.parse(updatedTransaction.frequency as any)
|
||||||
|
return updatedTransaction
|
||||||
|
}
|
||||||
|
|
||||||
|
deleteRecurringTransaction(id: string): Promise<void> {
|
||||||
|
const url = new URL(`/api/recurringtransactions/${id}`, this.apiUrl)
|
||||||
|
return this.request(url, HttpMethod.DELETE)
|
||||||
|
}
|
||||||
|
|
||||||
// Users
|
// Users
|
||||||
getProfile(id: string): Promise<User> {
|
getProfile(id: string): Promise<User> {
|
||||||
const url = new URL(`/api/users/${id}`, this.apiUrl)
|
const url = new URL(`/api/users/${id}`, this.apiUrl)
|
||||||
|
|
|
@ -5,6 +5,7 @@ import { Budget } from '../budgets/budget';
|
||||||
import { Category } from '../categories/category';
|
import { Category } from '../categories/category';
|
||||||
import { Transaction } from '../transactions/transaction';
|
import { Transaction } from '../transactions/transaction';
|
||||||
import { randomId } from '../shared/utils';
|
import { randomId } from '../shared/utils';
|
||||||
|
import { Frequency, RecurringTransaction } from '../recurringtransactions/recurringtransaction';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is intended to be a very simple implementation of the TwigsService used for testing out the UI and quickly iterating on it.
|
* This is intended to be a very simple implementation of the TwigsService used for testing out the UI and quickly iterating on it.
|
||||||
|
@ -284,6 +285,44 @@ export class TwigsLocalService implements TwigsService {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Recurring Transactions
|
||||||
|
getRecurringTransactions(
|
||||||
|
budgetId?: string,
|
||||||
|
categoryId?: string,
|
||||||
|
count?: number,
|
||||||
|
from?: Date,
|
||||||
|
to?: Date
|
||||||
|
): Promise<RecurringTransaction[]> {
|
||||||
|
return Promise.reject("Not yet implemented")
|
||||||
|
}
|
||||||
|
|
||||||
|
getRecurringTransaction(id: string): Promise<RecurringTransaction> {
|
||||||
|
return Promise.reject("Not yet implemented")
|
||||||
|
}
|
||||||
|
|
||||||
|
createRecurringTransaction(
|
||||||
|
id: string,
|
||||||
|
budgetId: string,
|
||||||
|
name: string,
|
||||||
|
description: string,
|
||||||
|
amount: number,
|
||||||
|
frequency: Frequency,
|
||||||
|
start: Date,
|
||||||
|
expense: boolean,
|
||||||
|
category: string,
|
||||||
|
end?: Date,
|
||||||
|
): Promise<RecurringTransaction> {
|
||||||
|
return Promise.reject("Not yet implemented")
|
||||||
|
}
|
||||||
|
|
||||||
|
updateRecurringTransaction(id: string, transaction: RecurringTransaction): Promise<RecurringTransaction> {
|
||||||
|
return Promise.reject("Not yet implemented")
|
||||||
|
}
|
||||||
|
|
||||||
|
deleteRecurringTransaction(id: string): Promise<void> {
|
||||||
|
return Promise.reject("Not yet implemented")
|
||||||
|
}
|
||||||
|
|
||||||
// Users
|
// Users
|
||||||
getProfile(id: string): Promise<User> {
|
getProfile(id: string): Promise<User> {
|
||||||
return Promise.reject("Not yet implemented");
|
return Promise.reject("Not yet implemented");
|
||||||
|
|
|
@ -2,6 +2,7 @@ import { InjectionToken } from '@angular/core';
|
||||||
import { User, UserPermission } from '../users/user';
|
import { User, UserPermission } from '../users/user';
|
||||||
import { Budget } from '../budgets/budget';
|
import { Budget } from '../budgets/budget';
|
||||||
import { Category } from '../categories/category';
|
import { Category } from '../categories/category';
|
||||||
|
import { RecurringTransaction, Frequency } from '../recurringtransactions/recurringtransaction';
|
||||||
import { Transaction } from '../transactions/transaction';
|
import { Transaction } from '../transactions/transaction';
|
||||||
|
|
||||||
export interface TwigsService {
|
export interface TwigsService {
|
||||||
|
@ -53,6 +54,30 @@ export interface TwigsService {
|
||||||
updateTransaction(id: string, transaction: Transaction): Promise<Transaction>;
|
updateTransaction(id: string, transaction: Transaction): Promise<Transaction>;
|
||||||
deleteTransaction(id: string): Promise<void>;
|
deleteTransaction(id: string): Promise<void>;
|
||||||
|
|
||||||
|
// Recurring Transactions
|
||||||
|
getRecurringTransactions(
|
||||||
|
budgetId?: string,
|
||||||
|
categoryId?: string,
|
||||||
|
count?: number,
|
||||||
|
from?: Date,
|
||||||
|
to?: Date
|
||||||
|
): Promise<RecurringTransaction[]>;
|
||||||
|
getRecurringTransaction(id: string): Promise<RecurringTransaction>;
|
||||||
|
createRecurringTransaction(
|
||||||
|
id: string,
|
||||||
|
budgetId: string,
|
||||||
|
name: string,
|
||||||
|
description: string,
|
||||||
|
amount: number,
|
||||||
|
frequency: Frequency,
|
||||||
|
start: Date,
|
||||||
|
expense: boolean,
|
||||||
|
category: string,
|
||||||
|
end?: Date,
|
||||||
|
): Promise<RecurringTransaction>;
|
||||||
|
updateRecurringTransaction(id: string, transaction: RecurringTransaction): Promise<RecurringTransaction>;
|
||||||
|
deleteRecurringTransaction(id: string): Promise<void>;
|
||||||
|
|
||||||
getProfile(id: string): Promise<User>;
|
getProfile(id: string): Promise<User>;
|
||||||
getUsersByUsername(username: string): Promise<User[]>;
|
getUsersByUsername(username: string): Promise<User[]>;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue