add ifPackageListExists to packageservice
This commit is contained in:
parent
713af307cd
commit
57e0a37c78
@ -7,7 +7,8 @@ import {IItem} from '../models/item';
|
||||
import {IItemTask} from '../models/itemTask';
|
||||
import {HttpClient} from '@angular/common/http';
|
||||
import {AppConfig} from '../shared/app.config';
|
||||
import {Observable} from 'rxjs';
|
||||
import {Observable,iif,of} from 'rxjs';
|
||||
import {switchMap} from 'rxjs/operators';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
@ -16,12 +17,13 @@ import {Observable} from 'rxjs';
|
||||
export class PackageService {
|
||||
private userPackages: { [key: string]: IPackage } = {};
|
||||
private packages: { [key: string]: IPackage } = {};
|
||||
private packagesObservable = this.store$.select(appCommonReducer.SelectGetPackages);
|
||||
|
||||
constructor(private store$: Store<appCommonReducer.State>, public httpClient: HttpClient, public appConfig: AppConfig) {
|
||||
store$.select(appCommonReducer.SelectGetValidUserPackages).subscribe((packages) => {
|
||||
this.userPackages = packages;
|
||||
});
|
||||
store$.select(appCommonReducer.SelectGetPackages).subscribe((packages) => {
|
||||
this.packagesObservable.subscribe((packages) => {
|
||||
this.packages = packages;
|
||||
});
|
||||
}
|
||||
@ -41,6 +43,14 @@ export class PackageService {
|
||||
postItemPackageTask(item: IItem, task: IItemTask): Observable<IItemTask> {
|
||||
return this.httpClient.post<IItemTask>(`${this.ApiEndpoint()}/api/v1/items/${item.code}/packagetasks`, task);
|
||||
}
|
||||
|
||||
ifPackageListExists<Type>(packageList: Array<string>, ifTrue:Observable<Type>,ifFalse:Observable<Type>):Observable<Type> {
|
||||
return this.packagesObservable.pipe(switchMap(packages =>
|
||||
iif(( )=> Object.keys(packages).some(id => packageList.includes(id)),
|
||||
ifTrue,
|
||||
ifFalse)
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
export function getValidPackages(packageMap: IPackages): {[key: string]: IPackage} {
|
||||
|
Loading…
Reference in New Issue
Block a user