Example Filter,sort,map Observable stream

Example 1

sort array of object alphapitaclly . Array of countries

 

 findAllCountry(tokenstring): Observable<ICountry[]> {
    const headerInfo = new HttpHeaders({
      Authorization: token,
    });
    return this.http
      .get<ICountry[]>(
        `${environment.backendUrl}/crm-operations/lookup/country`,
        { headers: headerInfo }
      )
      .pipe(
        tap((data=>
          data.sort((ab=> {
            if (a.couShortNameE < b.couShortNameE) {
              return -1;
            }
            if (a.couShortNameE > b.couShortNameE) {
              return 1;
            }
          })
        )
      );
  }

 

 

Example 2


async findAll(tokenstring): Promise<Observable<ComprehensiveLimit[]>> {
    let customer = await getSessionInfo("customer");
    const headerInfo = new HttpHeaders({
      Authorization: token,
    });
 let compRef = customer.compRef;
    return this.http
      .get<ComprehensiveLimit[]>(
        `${this.url}/crm-operations/application/compRef/${compRef}`,
        
        { headers: headerInfo }
      )
      .pipe(
         map(items => items.filter(item => item.status === 'SAV'))
       , map((responseArray=> {         
          return responseArray.map((record=> {            
            return new ComprehensiveLimit(
              record.clRef,
              record.transType,
              record.riskRef,
              record.hsCode,
              record.status,
              record.customer,
              record.currency,
              record.whoColumns,
              record.comprehensiveLimitsDetailsEntity,
              record.comprehensiveLimitsDetailsEntity.length
            );
          
          });
        })
        ,tap(result => result.sort( (a,b)=>  b.clRef -a.clRef

        )
        )
      );
  }

Comments

Popular posts from this blog

Another user has changed the row with primary key oracle.jbo.Key[12 ].

weblogic windows JPS-01050: Opening of wallet based credential store failed. Reason java.io.IOException: Failed to lock cwallet.sso.lck

Working With File Throgh WebUtill