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 {IItemTask} from '../models/itemTask';
|
||||||
import {HttpClient} from '@angular/common/http';
|
import {HttpClient} from '@angular/common/http';
|
||||||
import {AppConfig} from '../shared/app.config';
|
import {AppConfig} from '../shared/app.config';
|
||||||
import {Observable} from 'rxjs';
|
import {Observable,iif,of} from 'rxjs';
|
||||||
|
import {switchMap} from 'rxjs/operators';
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root',
|
providedIn: 'root',
|
||||||
@ -16,12 +17,13 @@ import {Observable} from 'rxjs';
|
|||||||
export class PackageService {
|
export class PackageService {
|
||||||
private userPackages: { [key: string]: IPackage } = {};
|
private userPackages: { [key: string]: IPackage } = {};
|
||||||
private packages: { [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) {
|
constructor(private store$: Store<appCommonReducer.State>, public httpClient: HttpClient, public appConfig: AppConfig) {
|
||||||
store$.select(appCommonReducer.SelectGetValidUserPackages).subscribe((packages) => {
|
store$.select(appCommonReducer.SelectGetValidUserPackages).subscribe((packages) => {
|
||||||
this.userPackages = packages;
|
this.userPackages = packages;
|
||||||
});
|
});
|
||||||
store$.select(appCommonReducer.SelectGetPackages).subscribe((packages) => {
|
this.packagesObservable.subscribe((packages) => {
|
||||||
this.packages = packages;
|
this.packages = packages;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -41,6 +43,14 @@ export class PackageService {
|
|||||||
postItemPackageTask(item: IItem, task: IItemTask): Observable<IItemTask> {
|
postItemPackageTask(item: IItem, task: IItemTask): Observable<IItemTask> {
|
||||||
return this.httpClient.post<IItemTask>(`${this.ApiEndpoint()}/api/v1/items/${item.code}/packagetasks`, task);
|
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} {
|
export function getValidPackages(packageMap: IPackages): {[key: string]: IPackage} {
|
||||||
|
Loading…
Reference in New Issue
Block a user