Fix transaction loading/saving and use env vars for api url
Signed-off-by: William Brawner <me@wbrawner.com>
This commit is contained in:
parent
d22fc6f7cc
commit
1551b865d6
5 changed files with 23 additions and 11 deletions
|
@ -6,6 +6,8 @@ import { TwigsService } from './twigs.service';
|
||||||
import { Budget } from '../budgets/budget';
|
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 { map } from 'rxjs/operators';
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root'
|
providedIn: 'root'
|
||||||
|
@ -20,10 +22,7 @@ export class TwigsHttpService implements TwigsService {
|
||||||
withCredentials: true
|
withCredentials: true
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO: Set this up in environment variables
|
private apiUrl = environment.apiUrl;
|
||||||
private apiUrl = 'https://budget-api.intra.wbrawner.com';
|
|
||||||
// private apiUrl = 'https://code.brawner.home/spring';
|
|
||||||
// private apiUrl = 'http://localhost:8080';
|
|
||||||
|
|
||||||
// Auth
|
// Auth
|
||||||
login(email: string, password: string): Observable<User> {
|
login(email: string, password: string): Observable<User> {
|
||||||
|
@ -118,11 +117,21 @@ export class TwigsHttpService implements TwigsService {
|
||||||
httpParams = httpParams.set('categoryId', `${categoryId}`);
|
httpParams = httpParams.set('categoryId', `${categoryId}`);
|
||||||
}
|
}
|
||||||
const params = { params: httpParams };
|
const params = { params: httpParams };
|
||||||
return this.http.get<Transaction[]>(`${this.apiUrl}/transactions`, Object.assign(params, this.options));
|
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;
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
getTransaction(id: number): Observable<Transaction> {
|
getTransaction(id: number): Observable<Transaction> {
|
||||||
return this.http.get<Transaction>(`${this.apiUrl}/transactions/${id}`, this.options);
|
return this.http.get<Transaction>(`${this.apiUrl}/transactions/${id}`, this.options)
|
||||||
|
.pipe(map(transaction => {
|
||||||
|
transaction.date = new Date(transaction.date);
|
||||||
|
return transaction;
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
createTransaction(
|
createTransaction(
|
||||||
|
|
|
@ -24,9 +24,9 @@
|
||||||
</mat-option>
|
</mat-option>
|
||||||
</mat-select>
|
</mat-select>
|
||||||
</mat-form-field>
|
</mat-form-field>
|
||||||
<mat-radio-group [(ngModel)]="currentTransaction.type">
|
<mat-radio-group [(ngModel)]="currentTransaction.expense">
|
||||||
<mat-radio-button [value]="transactionType.EXPENSE">Expense</mat-radio-button>
|
<mat-radio-button [value]="true">Expense</mat-radio-button>
|
||||||
<mat-radio-button [value]="transactionType.INCOME">Income</mat-radio-button>
|
<mat-radio-button [value]="false">Income</mat-radio-button>
|
||||||
</mat-radio-group>
|
</mat-radio-group>
|
||||||
<button class="button-delete" mat-button color="warn" *ngIf="currentTransaction.id" (click)="delete()">Delete</button>
|
<button class="button-delete" mat-button color="warn" *ngIf="currentTransaction.id" (click)="delete()">Delete</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -28,6 +28,7 @@ export class TransactionDetailsComponent implements OnInit {
|
||||||
.subscribe(transaction => {
|
.subscribe(transaction => {
|
||||||
transaction.amount /= 100;
|
transaction.amount /= 100;
|
||||||
this.transaction = transaction;
|
this.transaction = transaction;
|
||||||
|
this.budgetId = transaction.budgetId;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
export const environment = {
|
export const environment = {
|
||||||
production: true
|
production: true,
|
||||||
|
apiUrl: 'https://budget-api.intra.wbrawner.com'
|
||||||
};
|
};
|
||||||
|
|
|
@ -3,7 +3,8 @@
|
||||||
// The list of file replacements can be found in `angular.json`.
|
// The list of file replacements can be found in `angular.json`.
|
||||||
|
|
||||||
export const environment = {
|
export const environment = {
|
||||||
production: false
|
production: false,
|
||||||
|
apiUrl: 'http://localhost:8080'
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Reference in a new issue