Use promises api for user-related backend calls

This commit is contained in:
William Brawner 2022-11-09 02:04:43 +00:00
parent 447c1894d9
commit e11ffb741f
4 changed files with 7 additions and 13 deletions

View file

@ -57,7 +57,7 @@ export class AddEditBudgetComponent {
// TODO: Implement a search box with suggestions to add users
searchUsers(username: string) {
this.twigsService.getUsersByUsername(username).subscribe(users => {
this.twigsService.getUsersByUsername(username).then(users => {
this.searchedUsers = users;
});
}

View file

@ -302,10 +302,8 @@ export class TwigsHttpService implements TwigsService {
return this.request(url, HttpMethod.GET)
}
getUsersByUsername(username: string): Observable<User[]> {
return new Observable(subscriber => {
subscriber.error("Not yet implemented")
});
getUsersByUsername(username: string): Promise<User[]> {
return Promise.reject("Not yet implemented")
}
private async request<T>(url: URL, method: HttpMethod, body?: any): Promise<T> {

View file

@ -311,15 +311,11 @@ export class TwigsLocalService implements TwigsService {
// Users
getProfile(id: string): Promise<User> {
return new Promise((resolve, reject) => {
reject("Not yet implemented")
});
return Promise.reject("Not yet implemented");
}
getUsersByUsername(username: string): Observable<User[]> {
return new Observable(subscriber => {
subscriber.next(this.users.filter(user => user.username.indexOf(username) > -1 ));
});
getUsersByUsername(username: string): Promise<User[]> {
return Promise.resolve(this.users.filter(user => user.username.indexOf(username) > -1))
}
private updateValues(old: object, changes: object, keys: string[]) {

View file

@ -55,7 +55,7 @@ export interface TwigsService {
deleteTransaction(id: string): Observable<void>;
getProfile(id: string): Promise<User>;
getUsersByUsername(username: string): Observable<User[]>;
getUsersByUsername(username: string): Promise<User[]>;
}
export let TWIGS_SERVICE = new InjectionToken<TwigsService>('twigs.service');