Fix transaction loading/saving and use env vars for api url

Signed-off-by: William Brawner <me@wbrawner.com>
This commit is contained in:
William Brawner 2020-02-19 19:54:10 -07:00
parent d22fc6f7cc
commit 1551b865d6
5 changed files with 23 additions and 11 deletions

View file

@ -6,6 +6,8 @@ import { TwigsService } from './twigs.service';
import { Budget } from '../budgets/budget';
import { Category } from '../categories/category';
import { Transaction } from '../transactions/transaction';
import { environment } from '../../environments/environment';
import { map } from 'rxjs/operators';
@Injectable({
providedIn: 'root'
@ -20,10 +22,7 @@ export class TwigsHttpService implements TwigsService {
withCredentials: true
};
// TODO: Set this up in environment variables
private apiUrl = 'https://budget-api.intra.wbrawner.com';
// private apiUrl = 'https://code.brawner.home/spring';
// private apiUrl = 'http://localhost:8080';
private apiUrl = environment.apiUrl;
// Auth
login(email: string, password: string): Observable<User> {
@ -118,11 +117,21 @@ export class TwigsHttpService implements TwigsService {
httpParams = httpParams.set('categoryId', `${categoryId}`);
}
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> {
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(

View file

@ -24,9 +24,9 @@
</mat-option>
</mat-select>
</mat-form-field>
<mat-radio-group [(ngModel)]="currentTransaction.type">
<mat-radio-button [value]="transactionType.EXPENSE">Expense</mat-radio-button>
<mat-radio-button [value]="transactionType.INCOME">Income</mat-radio-button>
<mat-radio-group [(ngModel)]="currentTransaction.expense">
<mat-radio-button [value]="true">Expense</mat-radio-button>
<mat-radio-button [value]="false">Income</mat-radio-button>
</mat-radio-group>
<button class="button-delete" mat-button color="warn" *ngIf="currentTransaction.id" (click)="delete()">Delete</button>
</div>

View file

@ -28,6 +28,7 @@ export class TransactionDetailsComponent implements OnInit {
.subscribe(transaction => {
transaction.amount /= 100;
this.transaction = transaction;
this.budgetId = transaction.budgetId;
});
}
}

View file

@ -1,3 +1,4 @@
export const environment = {
production: true
production: true,
apiUrl: 'https://budget-api.intra.wbrawner.com'
};

View file

@ -3,7 +3,8 @@
// The list of file replacements can be found in `angular.json`.
export const environment = {
production: false
production: false,
apiUrl: 'http://localhost:8080'
};
/*