Fixes for new Ktor API
This commit is contained in:
parent
3e70e402ea
commit
9a274591ac
10 changed files with 27 additions and 20 deletions
|
@ -41,12 +41,13 @@ export class AppComponent implements OnInit {
|
|||
'/register'
|
||||
]
|
||||
let auth = this.storage.getItem('Authorization');
|
||||
let userId = this.storage.getItem('userId');
|
||||
let savedUser = JSON.parse(this.storage.getItem('user')) as User;
|
||||
if (auth && auth.length == 255) {
|
||||
if (auth && auth.length == 255 && userId) {
|
||||
if (savedUser) {
|
||||
this.user.next(savedUser);
|
||||
}
|
||||
this.twigsService.getProfile().subscribe(fetchedUser => {
|
||||
this.twigsService.getProfile(userId).subscribe(fetchedUser => {
|
||||
this.storage.setItem('user', JSON.stringify(fetchedUser));
|
||||
this.user.next(fetchedUser);
|
||||
if (unauthenticatedRoutes.indexOf(this.location.path()) != -1) {
|
||||
|
|
|
@ -23,7 +23,7 @@ export class AddEditBudgetComponent {
|
|||
) {
|
||||
this.app.setTitle(this.title)
|
||||
this.app.setBackEnabled(true);
|
||||
this.users = [new UserPermission(this.app.user.value, Permission.OWNER)];
|
||||
this.users = [new UserPermission(this.app.user.value.id, Permission.OWNER)];
|
||||
}
|
||||
|
||||
save(): void {
|
||||
|
|
|
@ -27,9 +27,9 @@
|
|||
</mat-card>
|
||||
<mat-card class="dashboard-categories" [hidden]="!budget">
|
||||
<h3 class="categories">Expenses</h3>
|
||||
<a mat-button routerLink="/categories/new" [queryParams]="{budgetIds: budget.id, expense: true}" class="view-all" *ngIf="budget">Add Category</a>
|
||||
<a mat-button routerLink="/categories/new" [queryParams]="{budgetId: budget.id, expense: true}" class="view-all" *ngIf="budget">Add Category</a>
|
||||
<div class="no-categories" *ngIf="!expenses || expenses.length === 0">
|
||||
<a mat-button routerLink="/categories/new" [queryParams]="{budgetIds: budget.id, expense: true}" *ngIf="budget">
|
||||
<a mat-button routerLink="/categories/new" [queryParams]="{budgetId: budget.id, expense: true}" *ngIf="budget">
|
||||
<mat-icon>add</mat-icon>
|
||||
<p>Add categories to gain more insights into your expenses.</p>
|
||||
</a>
|
||||
|
|
|
@ -17,7 +17,8 @@ export class NewCategoryComponent implements OnInit {
|
|||
) { }
|
||||
|
||||
ngOnInit() {
|
||||
this.budgetId = this.route.snapshot.paramMap.get('budgetId');
|
||||
this.budgetId = this.route.snapshot.queryParamMap.get('budgetId');
|
||||
console.log(`Creating category for budget ${this.budgetId}`)
|
||||
this.category = new Category();
|
||||
// TODO: Set random color for category, improve color picker
|
||||
// this.category.color =
|
||||
|
|
|
@ -36,7 +36,8 @@ export class TwigsHttpService implements TwigsService {
|
|||
auth => {
|
||||
// TODO: Use token expiration to determine cookie expiration
|
||||
this.storage.setItem('Authorization', auth.token);
|
||||
this.getProfile().subscribe(user => emitter.next(user), error => emitter.error(error));
|
||||
this.storage.setItem('userId', auth.userId);
|
||||
this.getProfile(auth.userId).subscribe(user => emitter.next(user), error => emitter.error(error));
|
||||
},
|
||||
error => emitter.error(error)
|
||||
);
|
||||
|
@ -49,12 +50,13 @@ export class TwigsHttpService implements TwigsService {
|
|||
'email': email,
|
||||
'password': password
|
||||
};
|
||||
return this.http.post<User>(this.apiUrl + '/users', params, this.options);
|
||||
return this.http.post<User>(this.apiUrl + '/users/register', params, this.options);
|
||||
}
|
||||
|
||||
logout(): Observable<void> {
|
||||
return new Observable(emitter => {
|
||||
this.storage.removeItem('Authorization');
|
||||
this.storage.removeItem('userId');
|
||||
emitter.next();
|
||||
emitter.complete();
|
||||
})
|
||||
|
@ -72,7 +74,7 @@ export class TwigsHttpService implements TwigsService {
|
|||
}
|
||||
|
||||
getBudgetBalance(id: string): Observable<number> {
|
||||
return this.http.get<any>(`${this.apiUrl}/budgets/${id}/balance`, this.options)
|
||||
return this.http.get<any>(`${this.apiUrl}/transactions/sum?budgetId=${id}`, this.options)
|
||||
.pipe(map(obj => obj.balance));
|
||||
}
|
||||
|
||||
|
@ -116,7 +118,7 @@ export class TwigsHttpService implements TwigsService {
|
|||
'description': description,
|
||||
'users': users.map(userPermission => {
|
||||
return {
|
||||
user: userPermission.user.id,
|
||||
user: userPermission.user,
|
||||
permission: Permission[userPermission.permission]
|
||||
};
|
||||
})
|
||||
|
@ -138,7 +140,7 @@ export class TwigsHttpService implements TwigsService {
|
|||
'description': budget.description,
|
||||
'users': budget.users.map(userPermission => {
|
||||
return {
|
||||
user: userPermission.user.id,
|
||||
user: userPermission.user,
|
||||
permission: Permission[userPermission.permission]
|
||||
};
|
||||
})
|
||||
|
@ -176,6 +178,7 @@ export class TwigsHttpService implements TwigsService {
|
|||
const params = {
|
||||
params: new HttpParams()
|
||||
.set('budgetIds', `${budgetId}`)
|
||||
.set('archived', false)
|
||||
};
|
||||
return this.http.get<Category[]>(`${this.apiUrl}/categories`, Object.assign(params, this.options));
|
||||
}
|
||||
|
@ -185,7 +188,7 @@ export class TwigsHttpService implements TwigsService {
|
|||
}
|
||||
|
||||
getCategoryBalance(id: string): Observable<number> {
|
||||
return this.http.get<any>(`${this.apiUrl}/categories/${id}/balance`, this.options)
|
||||
return this.http.get<any>(`${this.apiUrl}/transactions/sum?categoryId=${id}`, this.options)
|
||||
.pipe(map(obj => obj.balance));
|
||||
}
|
||||
|
||||
|
@ -280,8 +283,8 @@ export class TwigsHttpService implements TwigsService {
|
|||
}
|
||||
|
||||
// Users
|
||||
getProfile(): Observable<User> {
|
||||
return this.http.get<User>(`${this.apiUrl}/users/me`, this.options);
|
||||
getProfile(id: string): Observable<User> {
|
||||
return this.http.get<User>(`${this.apiUrl}/users/${id}`, this.options);
|
||||
}
|
||||
|
||||
getUsersByUsername(username: string): Observable<User[]> {
|
||||
|
|
|
@ -313,7 +313,7 @@ export class TwigsLocalService implements TwigsService {
|
|||
}
|
||||
|
||||
// Users
|
||||
getProfile(): Observable<User> {
|
||||
getProfile(id: string): Observable<User> {
|
||||
return new Observable(subscriber => {
|
||||
subscriber.error("Not yet implemented")
|
||||
});
|
||||
|
|
|
@ -54,7 +54,7 @@ export interface TwigsService {
|
|||
updateTransaction(id: string, changes: object): Observable<Transaction>;
|
||||
deleteTransaction(id: string): Observable<void>;
|
||||
|
||||
getProfile(): Observable<User>;
|
||||
getProfile(id: string): Observable<User>;
|
||||
getUsersByUsername(username: string): Observable<User[]>;
|
||||
}
|
||||
|
||||
|
|
|
@ -13,15 +13,16 @@ export class User {
|
|||
}
|
||||
|
||||
export class AuthToken {
|
||||
userId: string;
|
||||
token: string;
|
||||
expiration: Date;
|
||||
}
|
||||
|
||||
export class UserPermission {
|
||||
user: User;
|
||||
user: string;
|
||||
permission: Permission;
|
||||
|
||||
constructor(user: User, permission: Permission) {
|
||||
constructor(user: string, permission: Permission) {
|
||||
this.user = user;
|
||||
this.permission = permission;
|
||||
}
|
||||
|
@ -30,5 +31,6 @@ export class UserPermission {
|
|||
export enum Permission {
|
||||
READ,
|
||||
WRITE,
|
||||
MANAGE,
|
||||
OWNER
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
export const environment = {
|
||||
production: true,
|
||||
apiUrl: 'https://api.twigs.brawner.dev'
|
||||
apiUrl: '/api'
|
||||
};
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
export const environment = {
|
||||
production: false,
|
||||
apiUrl: 'http://localhost:8080'
|
||||
apiUrl: 'http://localhost:8080/api'
|
||||
};
|
||||
|
||||
/*
|
||||
|
|
Loading…
Reference in a new issue