diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/DevHive.Angular/src/app/services/language.service.ts | 40 | ||||
| -rw-r--r-- | src/DevHive.Angular/src/app/services/technology.service.ts | 41 |
2 files changed, 81 insertions, 0 deletions
diff --git a/src/DevHive.Angular/src/app/services/language.service.ts b/src/DevHive.Angular/src/app/services/language.service.ts index 8613a65..d85f178 100644 --- a/src/DevHive.Angular/src/app/services/language.service.ts +++ b/src/DevHive.Angular/src/app/services/language.service.ts @@ -2,6 +2,7 @@ import {HttpClient, HttpHeaders, HttpParams} from '@angular/common/http'; import {Injectable} from '@angular/core'; import {Guid} from 'guid-typescript'; import {Observable} from 'rxjs'; +import {Language} from 'src/models/identity/user'; import {AppConstants} from '../app-constants.module'; @Injectable({ @@ -16,4 +17,43 @@ export class LanguageService { }; return this.http.get(AppConstants.API_LANGUAGE_URL, options); } + + getAllLanguagesWithSessionStorageRequest(): Observable<object> { + const token = sessionStorage.getItem('UserCred') ?? ''; + return this.getAllLanguagesRequest(token); + } + + getAllLanguagesRequest(authToken: string): Observable<object> { + const options = { + headers: new HttpHeaders().set('Authorization', 'Bearer ' + authToken) + }; + return this.http.get(AppConstants.API_LANGUAGE_URL + '/GetLanguages', options); + } + + getFullLanguagesFromIncomplete(givenLanguages: Language[]): Promise<Language[]> { + if (givenLanguages.length === 0) { + return new Promise(resolve => resolve(givenLanguages)); + } + + // This accepts language array with incomplete languages, meaning + // languages that only have an id, but no name + return new Promise(resolve => { + const lastGuid = givenLanguages[givenLanguages.length - 1].id; + + // For each language, request his name and assign it + for (const lang of givenLanguages) { + this.getLanguageRequest(lang.id).subscribe( + (result: object) => { + // this only assigns the "name" property to the language, + // because only the name is returned from the request + Object.assign(lang, result); + + if (lastGuid === lang.id) { + resolve(givenLanguages); + } + } + ); + } + }); + } } diff --git a/src/DevHive.Angular/src/app/services/technology.service.ts b/src/DevHive.Angular/src/app/services/technology.service.ts index 4df0412..207303f 100644 --- a/src/DevHive.Angular/src/app/services/technology.service.ts +++ b/src/DevHive.Angular/src/app/services/technology.service.ts @@ -2,6 +2,7 @@ import {HttpClient, HttpHeaders, HttpParams} from '@angular/common/http'; import {Injectable} from '@angular/core'; import {Guid} from 'guid-typescript'; import {Observable} from 'rxjs'; +import {Technology} from 'src/models/identity/user'; import {AppConstants} from '../app-constants.module'; @Injectable({ @@ -16,4 +17,44 @@ export class TechnologyService { }; return this.http.get(AppConstants.API_TECHNOLOGY_URL, options); } + + getAllTechnologiesWithSessionStorageRequest(): Observable<object> { + const token = sessionStorage.getItem('UserCred') ?? ''; + return this.getAllTechnologiesRequest(token); + } + + getAllTechnologiesRequest(authToken: string): Observable<object> { + const options = { + headers: new HttpHeaders().set('Authorization', 'Bearer ' + authToken) + }; + return this.http.get(AppConstants.API_TECHNOLOGY_URL + '/GetTechnologies', options); + } + + getFullTechnologiesFromIncomplete(givenTechnologies: Technology[]): Promise<Technology[]> { + if (givenTechnologies.length === 0) { + return new Promise(resolve => resolve(givenTechnologies)); + } + + // This accepts language array with incomplete languages, meaning + // languages that only have an id, but no name + return new Promise(resolve => { + const lastGuid = givenTechnologies[givenTechnologies.length - 1].id; + + // For each language, request his name and assign it + for (const tech of givenTechnologies) { + this.getTechnologyRequest(tech.id).subscribe( + (result: object) => { + // this only assigns the "name" property to the language, + // because only the name is returned from the request + Object.assign(tech, result); + + if (lastGuid === tech.id) { + resolve(givenTechnologies); + } + } + ); + } + }); + } + } |
