rxjs#range TypeScript Examples

The following examples show how to use rxjs#range. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: corporate-credit-card-expense.service.ts    From fyle-mobile-app with MIT License 6 votes vote down vote up
getAllv2CardTransactions(config: Partial<{ order: string; queryParams: any }>): Observable<CorporateCardExpense[]> {
    return this.getv2CardTransactionsCount(config.queryParams).pipe(
      switchMap((count) => {
        count = count > 50 ? count / 50 : 1;
        return range(0, count);
      }),
      concatMap((page) =>
        this.getv2CardTransactions({
          offset: 50 * page,
          limit: 50,
          queryParams: config.queryParams,
          order: config.order,
        })
      ),
      map((res) => res.data),
      reduce((acc, curr) => acc.concat(curr))
    );
  }
Example #2
Source File: org-user.service.ts    From fyle-mobile-app with MIT License 6 votes vote down vote up
getEmployees(params): Observable<Employee[]> {
    return this.getEmployeesByParams({ ...params, limit: 1 }).pipe(
      switchMap((res) => {
        const count = res.count > 200 ? res.count / 200 : 1;
        return range(0, count);
      }),
      concatMap((page) => this.getEmployeesByParams({ ...params, offset: 200 * page, limit: 200 })),
      reduce((acc, curr) => acc.concat(curr.data), [] as Employee[])
    );
  }
Example #3
Source File: report.service.ts    From fyle-mobile-app with MIT License 6 votes vote down vote up
getAllExtendedReports(config: Partial<{ order: string; queryParams: any }>) {
    return this.getMyReportsCount(config.queryParams).pipe(
      switchMap((count) => {
        count = count > 50 ? count / 50 : 1;
        return range(0, count);
      }),
      concatMap((page) =>
        this.getMyReports({ offset: 50 * page, limit: 50, queryParams: config.queryParams, order: config.order })
      ),
      map((res) => res.data),
      reduce((acc, curr) => acc.concat(curr), [] as ExtendedReport[])
    );
  }
Example #4
Source File: report.service.ts    From fyle-mobile-app with MIT License 6 votes vote down vote up
getAllTeamExtendedReports(
    config: Partial<{ order: string; queryParams: any }> = {
      order: '',
      queryParams: {},
    }
  ) {
    return this.getTeamReportsCount().pipe(
      switchMap((count) => {
        count = count > 50 ? count / 50 : 1;
        return range(0, count);
      }),
      concatMap((page) =>
        this.getTeamReports({ offset: 50 * page, limit: 50, ...config.queryParams, order: config.order })
      ),
      map((res) => res.data),
      reduce((acc, curr) => acc.concat(curr), [] as ExtendedReport[])
    );
  }
Example #5
Source File: report.service.ts    From fyle-mobile-app with MIT License 6 votes vote down vote up
getApproversInBulk(rptIds) {
    if (!rptIds || rptIds.length === 0) {
      return of([]);
    }
    const count = rptIds.length > 50 ? rptIds.length / 50 : 1;
    return range(0, count).pipe(
      map((page) => rptIds.slice(page * 50, (page + 1) * 50)),
      concatMap((rptIds) => this.apiService.get('/reports/approvers', { params: { report_ids: rptIds } })),
      reduce((acc, curr) => acc.concat(curr), [])
    );
  }
Example #6
Source File: transaction.service.ts    From fyle-mobile-app with MIT License 6 votes vote down vote up
@Cacheable({
    cacheBusterObserver: transactionsCacheBuster$,
  })
  getAllETxnc(params) {
    return this.getETxnCount(params).pipe(
      switchMap((res) => {
        const count = res.count > 50 ? res.count / 50 : 1;
        return range(0, count);
      }),
      concatMap((page) => this.getETxnc({ offset: 50 * page, limit: 50, params })),
      reduce((acc, curr) => acc.concat(curr))
    );
  }
Example #7
Source File: transaction.service.ts    From fyle-mobile-app with MIT License 6 votes vote down vote up
@Cacheable({
    cacheBusterObserver: transactionsCacheBuster$,
  })
  getAllExpenses(config: Partial<{ order: string; queryParams: any }>) {
    return this.getMyExpensesCount(config.queryParams).pipe(
      switchMap((count) => {
        count = count > 50 ? count / 50 : 1;
        return range(0, count);
      }),
      concatMap((page) =>
        this.getMyExpenses({ offset: 50 * page, limit: 50, queryParams: config.queryParams, order: config.order })
      ),
      map((res) => res.data),
      reduce((acc, curr) => acc.concat(curr), [] as any[])
    );
  }
Example #8
Source File: transaction.service.ts    From fyle-mobile-app with MIT License 6 votes vote down vote up
@CacheBuster({
    cacheBusterNotifier: transactionsCacheBuster$,
  })
  deleteBulk(txnIds: string[]) {
    const chunkSize = 10;
    const count = txnIds.length > chunkSize ? txnIds.length / chunkSize : 1;
    return range(0, count).pipe(
      concatMap((page) => {
        const filteredtxnIds = txnIds.slice(chunkSize * page, chunkSize * page + chunkSize);
        return this.apiService.post('/transactions/delete/bulk', {
          txn_ids: filteredtxnIds,
        });
      }),
      reduce((acc, curr) => acc.concat(curr), [] as any[])
    );
  }
Example #9
Source File: transaction.service.ts    From fyle-mobile-app with MIT License 6 votes vote down vote up
@CacheBuster({
    cacheBusterNotifier: transactionsCacheBuster$,
  })
  removeTxnsFromRptInBulk(txnIds, comment?) {
    const count = txnIds.length > 50 ? txnIds.length / 50 : 1;
    return range(0, count).pipe(
      concatMap((page) => {
        const data: any = {
          ids: txnIds.slice(page * 50, (page + 1) * 50),
        };

        if (comment) {
          data.comment = comment;
        }

        return this.apiService.post('/transactions/remove_report/bulk', data);
      }),
      reduce((acc, curr) => acc.concat(curr), [] as any[])
    );
  }
Example #10
Source File: CollateralAuctionsTask.ts    From guardian with Apache License 2.0 5 votes vote down vote up
async start(guardian: AcalaGuardian) {
    const { apiRx } = await guardian.isReady();

    const { account, currencyId } = this.arguments;

    let currencies: CurrencyId[] = [];
    const whitelist = apiRx.consts.cdpEngine.collateralCurrencyIds;

    // make sure provided currency id is whitelisted
    if (currencyId !== 'all') {
      currencies = castArray(currencyId).map((x) => apiRx.createType('CurrencyId', x));
      currencies.forEach((id) => {
        if (!whitelist.find((x) => x.eq(id))) throw Error('Collateral currency id not allowed!');
      });
    } else {
      currencies = whitelist;
    }

    const includesAccount = includesArgument<string>(account);
    const includesCurrency = includesArgument<CurrencyId>(currencies);

    const upcomingAuctions$ = apiRx.query.auction.auctionsIndex().pipe(
      pairwise(),
      filter(([, next]) => !next.isZero()),
      switchMap(([prev, next]) => range(prev.toNumber(), next.toNumber())),
      distinctUntilChanged(),
      mergeMap((auctionId) => {
        return combineLatest([
          of(auctionId),
          apiRx.query.auctionManager.collateralAuctions(auctionId),
          apiRx.query.auction.auctions(auctionId)
        ]);
      })
    );

    return apiRx.query.auctionManager.collateralAuctions.entries().pipe(
      mergeMap((entry) => entry),
      mergeMap((entry) => {
        const [storageKey, maybecollateralAuction] = entry;
        const [auctionId] = storageKey.args;
        return combineLatest([of(auctionId), of(maybecollateralAuction), apiRx.query.auction.auctions(auctionId)]);
      }),
      concatWith(upcomingAuctions$),
      filter(([, maybecollateralAuction, maybeAuction]) => {
        if (maybecollateralAuction.isNone) return false;
        if (maybeAuction.isNone) return false;

        const { refundRecipient, currencyId } = maybecollateralAuction.unwrap();

        if (!includesAccount(refundRecipient.toString())) return false;
        if (!includesCurrency(currencyId)) return false;

        return true;
      }),
      map(([auctionId, maybecollateralAuction, maybeAuction]) => {
        const collateralAuction = maybecollateralAuction.unwrap();
        const auction = maybeAuction.unwrap();

        const [lastBidder, lastBid] = auction.bid.isSome ? auction.bid.unwrap() : [];

        return {
          account: collateralAuction.refundRecipient.toString(),
          currencyId: collateralAuction.currencyId.asToken.toString(),
          auctionId: Number(auctionId.toString()),
          initialAmount: collateralAuction.initialAmount.toString(),
          amount: collateralAuction.amount.toString(),
          target: collateralAuction.target.toString(),
          startTime: Number(collateralAuction.startTime.toString()),
          endTime: auction.end.isSome ? Number(auction.end.toString()) : undefined,
          lastBidder: lastBidder && lastBidder.toString(),
          lastBid: lastBid && lastBid.toString()
        };
      }),
      drr()
    );
  }
Example #11
Source File: LiquidityPoolTask.ts    From guardian with Apache License 2.0 5 votes vote down vote up
getSyntheticPools = (apiRx: ApiRx) => (poolId: number | number[] | 'all') => {
  const upcomingPools$ = apiRx.query.baseLiquidityPoolsForSynthetic.nextPoolId().pipe(
    pairwise(),
    filter(([, next]) => !next.isZero()),
    switchMap(([prev, next]) => range(prev.toNumber(), next.toNumber())),
    distinctUntilChanged(),
    mergeMap((poolId) =>
      combineLatest([
        of(poolId.toString()),
        apiRx.query.baseLiquidityPoolsForSynthetic.pools(poolId).pipe(
          filter((x) => x.isSome),
          map((x) => x.unwrap())
        )
      ])
    )
  );

  if (poolId === 'all') {
    return apiRx.query.baseLiquidityPoolsForSynthetic.pools.entries().pipe(
      mergeMap((x) => x),
      filter(([, value]) => value.isSome),
      mergeMap(
        ([
          {
            args: [poolId]
          },
          pool
        ]) => combineLatest([of(poolId.toString()), of(pool.unwrap())])
      ),
      concatWith(upcomingPools$)
    );
  } else {
    return of(castArray(poolId)).pipe(
      mergeMap((x) => x),
      switchMap((poolId) =>
        combineLatest([of(poolId.toString()), apiRx.query.baseLiquidityPoolsForSynthetic.pools(poolId)])
      ),
      filter(([, pool]) => pool.isSome),
      mergeMap(([poolId, value]) => combineLatest([of(poolId), of(value.unwrap())]))
    );
  }
}
Example #12
Source File: my-advances.page.ts    From fyle-mobile-app with MIT License 4 votes vote down vote up
ionViewWillEnter() {
    this.setupNetworkWatcher();

    this.tasksService.getAdvancesTaskCount().subscribe((advancesTaskCount) => {
      this.advancesTaskCount = advancesTaskCount;
    });

    this.navigateBack = !!this.activatedRoute.snapshot.params.navigateBack;
    this.tasksService.getTotalTaskCount().subscribe((totalTaskCount) => (this.totalTaskCount = totalTaskCount));

    const oldFilters = this.activatedRoute.snapshot.queryParams.filters;
    if (oldFilters) {
      this.filterParams$.next(JSON.parse(oldFilters));
      this.filterPills = this.filtersHelperService.generateFilterPills(this.filterParams$.value);
    }

    this.isLoading = true;

    this.myAdvancerequests$ = this.advanceRequestService
      .getMyAdvanceRequestsCount({
        areq_advance_id: 'is.null',
      })
      .pipe(
        concatMap((count) => {
          count = count > 10 ? count / 10 : 1;
          return range(0, count);
        }),
        concatMap((count) =>
          this.advanceRequestService.getMyadvanceRequests({
            offset: 10 * count,
            limit: 10,
            queryParams: {
              areq_advance_id: 'is.null',
              order: 'areq_created_at.desc,areq_id.desc',
            },
          })
        ),
        map((res) => res.data),
        reduce((acc, curr) => acc.concat(curr))
      );

    this.myAdvances$ = this.advanceService.getMyAdvancesCount().pipe(
      concatMap((count) => {
        count = count > 10 ? count / 10 : 1;
        return range(0, count);
      }),
      concatMap((count) =>
        this.advanceService.getMyadvances({
          offset: 10 * count,
          limit: 10,
          queryParams: { order: 'adv_created_at.desc,adv_id.desc' },
        })
      ),
      map((res) => res.data),
      reduce((acc, curr) => acc.concat(curr))
    );

    const sortResults = map((res: any[]) => res.sort((a, b) => (a.created_at < b.created_at ? 1 : -1)));
    this.advances$ = this.refreshAdvances$.pipe(
      startWith(0),
      concatMap(() => this.offlineService.getOrgSettings()),
      switchMap((orgSettings) =>
        combineLatest([
          iif(() => orgSettings.advance_requests.enabled, this.myAdvancerequests$, of(null)),
          iif(() => orgSettings.advances.enabled, this.myAdvances$, of(null)),
        ]).pipe(
          map((res) => {
            const [myAdvancerequestsRes, myAdvancesRes] = res;
            let myAdvancerequests = myAdvancerequestsRes || [];
            let myAdvances = myAdvancesRes || [];
            myAdvancerequests = this.updateMyAdvanceRequests(myAdvancerequests);
            myAdvances = this.updateMyAdvances(myAdvances);
            return myAdvances.concat(myAdvancerequests);
          }),
          sortResults
        )
      ),
      switchMap((advArray) =>
        //piping through filterParams so that filtering and sorting happens whenever we call next() on filterParams
        this.filterParams$.pipe(
          map((filters) => {
            let newArr = cloneDeep(advArray);

            if (filters && filters.state && filters.state.length > 0) {
              newArr = advArray.filter((adv) => {
                const sentBackAdvance =
                  filters.state.includes(AdvancesStates.sentBack) &&
                  adv.areq_state === 'DRAFT' &&
                  adv.areq_is_sent_back;

                const plainDraft =
                  filters.state.includes(AdvancesStates.draft) &&
                  adv.areq_state === 'DRAFT' &&
                  !adv.areq_is_sent_back &&
                  !adv.areq_is_pulled_back;

                return sentBackAdvance || plainDraft;
              });
            }
            newArr = this.utilityService.sortAllAdvances(filters.sortDir, filters.sortParam, newArr);
            return newArr;
          })
        )
      ),
      tap((res) => {
        if (res && res.length >= 0) {
          this.isLoading = false;
        }
      })
    );

    this.getAndUpdateProjectName();
  }